2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #include "webrtc/system_wrappers/source/trace_win.h"
27 #define BUILDTIME __TIME__
28 #define BUILDDATE __DATE__
29 // Example: "Oct 10 2002 12:05:30 r"
30 #define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE
33 TraceWindows::TraceWindows()
34 : prev_api_tick_count_(0),
38 TraceWindows::~TraceWindows() {
42 int32_t TraceWindows::AddTime(char* trace_message,
43 const TraceLevel level) const {
44 uint32_t dw_current_time = timeGetTime();
45 SYSTEMTIME system_time;
46 GetSystemTime(&system_time);
48 if (level == kTraceApiCall) {
49 uint32_t dw_delta_time = dw_current_time - prev_tick_count_;
50 prev_tick_count_ = dw_current_time;
52 if (prev_tick_count_ == 0) {
55 if (dw_delta_time > 0x0fffffff) {
56 // Either wrap-around or data race.
59 if (dw_delta_time > 99999) {
60 dw_delta_time = 99999;
63 sprintf(trace_message, "(%2u:%2u:%2u:%3u |%5u) ", system_time.wHour,
64 system_time.wMinute, system_time.wSecond,
65 system_time.wMilliseconds, dw_delta_time);
67 uint32_t dw_delta_time = dw_current_time - prev_api_tick_count_;
68 prev_api_tick_count_ = dw_current_time;
70 if (prev_api_tick_count_ == 0) {
73 if (dw_delta_time > 0x0fffffff) {
74 // Either wraparound or data race.
77 if (dw_delta_time > 99999) {
78 dw_delta_time = 99999;
80 sprintf(trace_message, "(%2u:%2u:%2u:%3u |%5u) ", system_time.wHour,
81 system_time.wMinute, system_time.wSecond,
82 system_time.wMilliseconds, dw_delta_time);
87 int32_t TraceWindows::AddBuildInfo(char* trace_message) const {
88 // write data and time to text file
89 sprintf(trace_message, "Build info: %s", BUILDINFO);
90 // Include NULL termination (hence + 1).
91 return static_cast<int32_t>(strlen(trace_message) + 1);
94 int32_t TraceWindows::AddDateTimeInfo(char* trace_message) const {
95 prev_api_tick_count_ = timeGetTime();
96 prev_tick_count_ = prev_api_tick_count_;
99 GetLocalTime(&sys_time);
101 TCHAR sz_date_str[20];
102 TCHAR sz_time_str[20];
104 // Create date string (e.g. Apr 04 2002)
105 GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &sys_time, TEXT("MMM dd yyyy"),
108 // Create time string (e.g. 15:32:08)
109 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &sys_time, TEXT("HH':'mm':'ss"),
112 sprintf(trace_message, "Local Date: %ls Local Time: %ls", sz_date_str,
115 // Include NULL termination (hence + 1).
116 return static_cast<int32_t>(strlen(trace_message) + 1);
119 } // namespace webrtc