niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | e713fd0 | 2012-04-10 07:13:46 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 11 | #include "webrtc/system_wrappers/source/trace_win.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 13 | #include <assert.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | #include <stdarg.h> |
| 15 | |
| 16 | #include "Mmsystem.h" |
| 17 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | namespace webrtc { |
| 19 | TraceWindows::TraceWindows() |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 20 | : prev_api_tick_count_(0), |
| 21 | prev_tick_count_(0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | } |
| 23 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 24 | TraceWindows::~TraceWindows() { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | } |
| 26 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 27 | int32_t TraceWindows::AddTime(char* trace_message, |
| 28 | const TraceLevel level) const { |
| 29 | uint32_t dw_current_time = timeGetTime(); |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 30 | SYSTEMTIME system_time; |
| 31 | GetSystemTime(&system_time); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 33 | if (level == kTraceApiCall) { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 34 | uint32_t dw_delta_time = dw_current_time - prev_tick_count_; |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 35 | prev_tick_count_ = dw_current_time; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 37 | if (prev_tick_count_ == 0) { |
| 38 | dw_delta_time = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | } |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 40 | if (dw_delta_time > 0x0fffffff) { |
| 41 | // Either wrap-around or data race. |
| 42 | dw_delta_time = 0; |
| 43 | } |
| 44 | if (dw_delta_time > 99999) { |
| 45 | dw_delta_time = 99999; |
| 46 | } |
| 47 | |
thakis@chromium.org | 905f9ef | 2014-08-21 02:23:30 +0000 | [diff] [blame] | 48 | sprintf(trace_message, "(%2u:%2u:%2u:%3u |%5u) ", system_time.wHour, |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 49 | system_time.wMinute, system_time.wSecond, |
| 50 | system_time.wMilliseconds, dw_delta_time); |
| 51 | } else { |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 52 | uint32_t dw_delta_time = dw_current_time - prev_api_tick_count_; |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 53 | prev_api_tick_count_ = dw_current_time; |
| 54 | |
| 55 | if (prev_api_tick_count_ == 0) { |
| 56 | dw_delta_time = 0; |
| 57 | } |
| 58 | if (dw_delta_time > 0x0fffffff) { |
| 59 | // Either wraparound or data race. |
| 60 | dw_delta_time = 0; |
| 61 | } |
| 62 | if (dw_delta_time > 99999) { |
| 63 | dw_delta_time = 99999; |
| 64 | } |
thakis@chromium.org | 905f9ef | 2014-08-21 02:23:30 +0000 | [diff] [blame] | 65 | sprintf(trace_message, "(%2u:%2u:%2u:%3u |%5u) ", system_time.wHour, |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 66 | system_time.wMinute, system_time.wSecond, |
| 67 | system_time.wMilliseconds, dw_delta_time); |
| 68 | } |
| 69 | return 22; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | } |
| 71 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 72 | int32_t TraceWindows::AddDateTimeInfo(char* trace_message) const { |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 73 | prev_api_tick_count_ = timeGetTime(); |
| 74 | prev_tick_count_ = prev_api_tick_count_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 76 | SYSTEMTIME sys_time; |
| 77 | GetLocalTime(&sys_time); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 79 | TCHAR sz_date_str[20]; |
| 80 | TCHAR sz_time_str[20]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 82 | // Create date string (e.g. Apr 04 2002) |
| 83 | GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &sys_time, TEXT("MMM dd yyyy"), |
| 84 | sz_date_str, 20); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 86 | // Create time string (e.g. 15:32:08) |
| 87 | GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &sys_time, TEXT("HH':'mm':'ss"), |
| 88 | sz_time_str, 20); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
thakis@chromium.org | 905f9ef | 2014-08-21 02:23:30 +0000 | [diff] [blame] | 90 | sprintf(trace_message, "Local Date: %ls Local Time: %ls", sz_date_str, |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 91 | sz_time_str); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 92 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 93 | // Include NULL termination (hence + 1). |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 94 | return static_cast<int32_t>(strlen(trace_message) + 1); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | } |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 96 | |
| 97 | } // namespace webrtc |