blob: 4caedfce773286f40d837ccba141ee13e05299a6 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.orge713fd02012-04-10 07:13:46 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.orgdaabfd22013-01-03 09:37:03 +000011#include "webrtc/system_wrappers/source/trace_win.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000013#include <assert.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000014#include <stdarg.h>
15
16#include "Mmsystem.h"
17
niklase@google.com470e71d2011-07-07 08:21:25 +000018namespace webrtc {
19TraceWindows::TraceWindows()
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000020 : prev_api_tick_count_(0),
21 prev_tick_count_(0) {
niklase@google.com470e71d2011-07-07 08:21:25 +000022}
23
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000024TraceWindows::~TraceWindows() {
niklase@google.com470e71d2011-07-07 08:21:25 +000025}
26
pbos@webrtc.org046deb92013-04-09 09:06:11 +000027int32_t TraceWindows::AddTime(char* trace_message,
28 const TraceLevel level) const {
29 uint32_t dw_current_time = timeGetTime();
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000030 SYSTEMTIME system_time;
31 GetSystemTime(&system_time);
niklase@google.com470e71d2011-07-07 08:21:25 +000032
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000033 if (level == kTraceApiCall) {
pbos@webrtc.org046deb92013-04-09 09:06:11 +000034 uint32_t dw_delta_time = dw_current_time - prev_tick_count_;
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000035 prev_tick_count_ = dw_current_time;
niklase@google.com470e71d2011-07-07 08:21:25 +000036
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000037 if (prev_tick_count_ == 0) {
38 dw_delta_time = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000039 }
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000040 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.org905f9ef2014-08-21 02:23:30 +000048 sprintf(trace_message, "(%2u:%2u:%2u:%3u |%5u) ", system_time.wHour,
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000049 system_time.wMinute, system_time.wSecond,
50 system_time.wMilliseconds, dw_delta_time);
51 } else {
pbos@webrtc.org046deb92013-04-09 09:06:11 +000052 uint32_t dw_delta_time = dw_current_time - prev_api_tick_count_;
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000053 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.org905f9ef2014-08-21 02:23:30 +000065 sprintf(trace_message, "(%2u:%2u:%2u:%3u |%5u) ", system_time.wHour,
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000066 system_time.wMinute, system_time.wSecond,
67 system_time.wMilliseconds, dw_delta_time);
68 }
69 return 22;
niklase@google.com470e71d2011-07-07 08:21:25 +000070}
71
pbos@webrtc.org046deb92013-04-09 09:06:11 +000072int32_t TraceWindows::AddDateTimeInfo(char* trace_message) const {
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000073 prev_api_tick_count_ = timeGetTime();
74 prev_tick_count_ = prev_api_tick_count_;
niklase@google.com470e71d2011-07-07 08:21:25 +000075
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000076 SYSTEMTIME sys_time;
77 GetLocalTime(&sys_time);
niklase@google.com470e71d2011-07-07 08:21:25 +000078
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000079 TCHAR sz_date_str[20];
80 TCHAR sz_time_str[20];
niklase@google.com470e71d2011-07-07 08:21:25 +000081
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000082 // 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.com470e71d2011-07-07 08:21:25 +000085
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000086 // 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.com470e71d2011-07-07 08:21:25 +000089
thakis@chromium.org905f9ef2014-08-21 02:23:30 +000090 sprintf(trace_message, "Local Date: %ls Local Time: %ls", sz_date_str,
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000091 sz_time_str);
niklase@google.com470e71d2011-07-07 08:21:25 +000092
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000093 // Include NULL termination (hence + 1).
pbos@webrtc.org046deb92013-04-09 09:06:11 +000094 return static_cast<int32_t>(strlen(trace_message) + 1);
niklase@google.com470e71d2011-07-07 08:21:25 +000095}
phoglund@webrtc.orgdaabfd22013-01-03 09:37:03 +000096
97} // namespace webrtc