OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/system_wrappers/source/trace_posix.h" | 11 #include "webrtc/system_wrappers/source/trace_posix.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <stdarg.h> | 14 #include <stdarg.h> |
15 #include <stdio.h> | 15 #include <stdio.h> |
16 #include <string.h> | 16 #include <string.h> |
17 #include <sys/time.h> | 17 #include <sys/time.h> |
18 #include <time.h> | 18 #include <time.h> |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 | 21 |
22 TracePosix::TracePosix() | 22 TracePosix::TracePosix() { |
23 : crit_sect_(*CriticalSectionWrapper::CreateCriticalSection()) { | |
24 struct timeval system_time_high_res; | 23 struct timeval system_time_high_res; |
25 gettimeofday(&system_time_high_res, 0); | 24 gettimeofday(&system_time_high_res, 0); |
26 prev_api_tick_count_ = prev_tick_count_ = system_time_high_res.tv_sec; | 25 prev_api_tick_count_ = prev_tick_count_ = system_time_high_res.tv_sec; |
27 } | 26 } |
28 | 27 |
29 TracePosix::~TracePosix() { | |
30 delete &crit_sect_; | |
31 } | |
32 | |
33 int32_t TracePosix::AddTime(char* trace_message, const TraceLevel level) const { | 28 int32_t TracePosix::AddTime(char* trace_message, const TraceLevel level) const { |
34 struct timeval system_time_high_res; | 29 struct timeval system_time_high_res; |
35 if (gettimeofday(&system_time_high_res, 0) == -1) { | 30 if (gettimeofday(&system_time_high_res, 0) == -1) { |
36 return -1; | 31 return -1; |
37 } | 32 } |
38 struct tm buffer; | 33 struct tm buffer; |
39 const struct tm* system_time = | 34 const struct tm* system_time = |
40 localtime_r(&system_time_high_res.tv_sec, &buffer); | 35 localtime_r(&system_time_high_res.tv_sec, &buffer); |
41 | 36 |
42 const uint32_t ms_time = system_time_high_res.tv_usec / 1000; | 37 const uint32_t ms_time = system_time_high_res.tv_usec / 1000; |
43 uint32_t prev_tickCount = 0; | 38 uint32_t prev_tickCount = 0; |
44 { | 39 { |
45 CriticalSectionScoped lock(&crit_sect_); | 40 rtc::CritScope lock(&crit_sect_); |
46 if (level == kTraceApiCall) { | 41 if (level == kTraceApiCall) { |
47 prev_tickCount = prev_tick_count_; | 42 prev_tickCount = prev_tick_count_; |
48 prev_tick_count_ = ms_time; | 43 prev_tick_count_ = ms_time; |
49 } else { | 44 } else { |
50 prev_tickCount = prev_api_tick_count_; | 45 prev_tickCount = prev_api_tick_count_; |
51 prev_api_tick_count_ = ms_time; | 46 prev_api_tick_count_ = ms_time; |
52 } | 47 } |
53 } | 48 } |
54 | 49 |
55 uint32_t dw_delta_time = ms_time - prev_tickCount; | 50 uint32_t dw_delta_time = ms_time - prev_tickCount; |
(...skipping 25 matching lines...) Expand all Loading... |
81 if ('\n' == trace_message[len - 1]) { | 76 if ('\n' == trace_message[len - 1]) { |
82 trace_message[len - 1] = '\0'; | 77 trace_message[len - 1] = '\0'; |
83 --len; | 78 --len; |
84 } | 79 } |
85 | 80 |
86 // Messages is 12 characters. | 81 // Messages is 12 characters. |
87 return len + 1; | 82 return len + 1; |
88 } | 83 } |
89 | 84 |
90 } // namespace webrtc | 85 } // namespace webrtc |
OLD | NEW |