Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/base/cpu_time.h" | |
| 12 #include "webrtc/base/logging.h" | |
| 13 | |
| 14 #if defined(WEBRTC_LINUX) | |
| 15 #include <time.h> | |
| 16 #elif defined(WEBRTC_MAC) | |
| 17 #include <unistd.h> | |
| 18 #include <sys/resource.h> | |
| 19 #include <sys/times.h> | |
| 20 #elif defined(WEBRTC_WIN) | |
| 21 #include <windows.h> | |
| 22 #endif | |
| 23 | |
| 24 namespace rtc { | |
| 25 | |
| 26 // static | |
| 27 double CpuTime::GetCpuTime() { | |
| 28 #if defined(WEBRTC_LINUX) | |
| 29 struct timespec ts; | |
| 30 if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) != -1) { | |
| 31 return static_cast<double>(ts.tv_sec) + | |
| 32 static_cast<double>(ts.tv_nsec) / 1000000000.0; | |
|
nisse-webrtc
2017/02/15 12:18:16
I'd prefer "* 1e-9", so I don't have to count the
ilnik
2017/02/15 12:53:21
Done.
| |
| 33 } else { | |
| 34 LOG(LS_ERROR) << "clock_gettime() failed."; | |
| 35 } | |
| 36 #elif defined(WEBRTC_MAC) | |
| 37 struct rusage rusage; | |
| 38 if (getrusage(RUSAGE_SELF, &rusage) != -1) { | |
| 39 return static_cast<double>(rusage.ru_utime.tv_sec) + | |
| 40 static_cast<double>(rusage.ru_utime.tv_usec) / 1000000.0; | |
| 41 } | |
| 42 #elif defined(WEBRTC_WIN) | |
| 43 FILETIME createTime; | |
| 44 FILETIME exitTime; | |
| 45 FILETIME kernelTime; | |
| 46 FILETIME userTime; | |
| 47 if (GetProcessTimes(GetCurrentProcess(), &createTime, &exitTime, &kernelTime, | |
| 48 &userTime) != -1) { | |
| 49 SYSTEMTIME userSystemTime; | |
|
nisse-webrtc
2017/02/15 12:18:16
After a quick look at the windows docs, I'd recomm
ilnik
2017/02/15 12:53:21
Done.
| |
| 50 if (FileTimeToSystemTime(&userTime, &userSystemTime) != -1) | |
| 51 return static_cast<double>(userSystemTime.wHour) * 3600.0 + | |
| 52 static_cast<double>(userSystemTime.wMinute) * 60.0 + | |
| 53 static_cast<double>(userSystemTime.wSecond) + | |
| 54 static_cast<double>(userSystemTime.wMilliseconds) / 1000.0; | |
| 55 } else { | |
| 56 LOG(LS_ERROR) << "GetProcessTimes() failed."; | |
| 57 } | |
| 58 #else | |
| 59 LOG(LS_ERROR) << "No function to get CPU time"; | |
| 60 #endif | |
| 61 return -1.0; | |
| 62 } | |
| 63 | |
| 64 } // namespace rtc | |
| OLD | NEW |