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 #include "webrtc/base/timeutils.h" | |
14 | |
15 #if defined(WEBRTC_LINUX) | |
16 #include <time.h> | |
17 #elif defined(WEBRTC_MAC) | |
18 #include <unistd.h> | |
19 #include <sys/resource.h> | |
20 #include <sys/times.h> | |
21 #elif defined(WEBRTC_WIN) | |
22 #include <windows.h> | |
23 #endif | |
24 | |
25 namespace rtc { | |
26 | |
27 int64_t GetCpuTime() { | |
28 #if defined(WEBRTC_LINUX) | |
29 struct timespec ts; | |
30 if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) != -1) { | |
31 return ts.tv_sec * kNumNanosecsPerSec + ts.tv_nsec; | |
nisse-webrtc
2017/02/15 13:07:31
I think you need a cast to int64_t on one of the f
ilnik
2017/02/15 13:23:11
kNumNanosecsPerSec and other constants are already
nisse-webrtc
2017/02/15 14:27:35
You're right, that's sufficient.
| |
32 } else { | |
33 LOG(LS_ERROR) << "clock_gettime() failed."; | |
nisse-webrtc
2017/02/15 13:07:31
I think you should use LOG_ERR when errno (or the
ilnik
2017/02/15 13:23:11
Done.
| |
34 } | |
35 #elif defined(WEBRTC_MAC) | |
36 struct rusage rusage; | |
37 if (getrusage(RUSAGE_SELF, &rusage) != -1) { | |
38 return rusage.ru_utime.tv_sec * kNumNanosecsPerSec + | |
39 rusage.ru_utime.tv_usec * kNumNanosecsPerMicrosec; | |
40 } | |
41 #elif defined(WEBRTC_WIN) | |
42 // FILETIME resolution is 100 nanosecs. | |
43 static const int64_t kNanosecsPerFiletime = 100; | |
44 FILETIME createTime; | |
45 FILETIME exitTime; | |
46 FILETIME kernelTime; | |
47 FILETIME userTime; | |
48 if (GetProcessTimes(GetCurrentProcess(), &createTime, &exitTime, &kernelTime, | |
49 &userTime) != -1) { | |
nisse-webrtc
2017/02/15 13:07:31
The docs doesn't specify which non-zero value is r
ilnik
2017/02/15 13:23:11
This was actually a mistake, because it returns no
nisse-webrtc
2017/02/15 14:27:35
Ooops. Good you found it.
| |
50 return (static_cast<uint64_t>(userTime.dwHighDateTime) << 32) | |
51 + userTime.dwLowDateTime) * kNanosecsPerFiletime; | |
52 } else { | |
53 LOG(LS_ERROR) << "GetProcessTimes() failed."; | |
54 } | |
55 #else | |
56 LOG(LS_ERROR) << "No function to get CPU time"; | |
57 #endif | |
58 return -1; | |
59 } | |
60 | |
61 } // namespace rtc | |
OLD | NEW |