Reformatted trace* files.

BUG=
TEST=Trybots.

Review URL: https://webrtc-codereview.appspot.com/1015004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3329 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
phoglund@webrtc.org
2013-01-03 09:37:03 +00:00
parent 201d4b61d1
commit daabfd25a6
9 changed files with 946 additions and 1060 deletions

View File

@@ -6,54 +6,54 @@
* tree. An additional intellectual property rights grant can be found * tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may * in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*
* System independent wrapper for logging runtime information to file.
* Note: All log messages will be written to the same trace file.
* Note: If too many messages are written to file there will be a build up of
* messages. Apply filtering to avoid that.
*/ */
// System independent wrapper for logging runtime information to file.
// Note: All log messages will be written to the same trace file.
// Note: If too many messages are written to file there will be a build up of
// messages. Apply filtering to avoid that.
#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ #ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_
#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ #define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_
#include "common_types.h" #include "webrtc/common_types.h"
#include "typedefs.h" #include "webrtc/typedefs.h"
#define WEBRTC_TRACE Trace::Add #define WEBRTC_TRACE Trace::Add
namespace webrtc { namespace webrtc {
class Trace
{
public:
class Trace {
public:
// Increments the reference count to the trace. // Increments the reference count to the trace.
static void CreateTrace(); static void CreateTrace();
// Decrements the reference count to the trace. // Decrements the reference count to the trace.
static void ReturnTrace(); static void ReturnTrace();
// Note: any instance that writes to the trace file should increment and // Note: any instance that writes to the trace file should increment and
// decrement the reference count on construction and destruction // decrement the reference count on construction and destruction,
// respectively // respectively.
// Specifies what type of messages should be written to the trace file. The // Specifies what type of messages should be written to the trace file. The
// filter parameter is a bitmask where each message type is enumerated by // filter parameter is a bitmask where each message type is enumerated by the
// the TraceLevel enumerator. TODO(hellner): why is the // TraceLevel enumerator. TODO(hellner): why is the TraceLevel enumerator not
// TraceLevel enumerator not defined in this file? // defined in this file?
static WebRtc_Word32 SetLevelFilter(const WebRtc_UWord32 filter); static WebRtc_Word32 SetLevelFilter(const WebRtc_UWord32 filter);
// Returns what type of messages are written to the trace file. // Returns what type of messages are written to the trace file.
static WebRtc_Word32 LevelFilter(WebRtc_UWord32& filter); static WebRtc_Word32 LevelFilter(WebRtc_UWord32& filter);
// Sets the file name. If addFileCounter is false the same file will be // Sets the file name. If add_file_counter is false the same file will be
// reused when it fills up. If it's true a new file with incremented name // reused when it fills up. If it's true a new file with incremented name
// will be used. // will be used.
static WebRtc_Word32 SetTraceFile(const char* fileName, static WebRtc_Word32 SetTraceFile(const char* file_name,
const bool addFileCounter = false); const bool add_file_counter = false);
// Returns the name of the file that the trace is currently writing to. // Returns the name of the file that the trace is currently writing to.
static WebRtc_Word32 TraceFile(char fileName[1024]); static WebRtc_Word32 TraceFile(char file_name[1024]);
// Registers callback to receive trace messages. TODO (hellner) // Registers callback to receive trace messages.
// why not use OutStream instead? Why is TraceCallback not defined in this // TODO(hellner): Why not use OutStream instead? Why is TraceCallback not
// file // defined in this file?
static WebRtc_Word32 SetTraceCallback(TraceCallback* callback); static WebRtc_Word32 SetTraceCallback(TraceCallback* callback);
// Adds a trace message for writing to file. The message is put in a queue // Adds a trace message for writing to file. The message is put in a queue
@@ -65,7 +65,7 @@ public:
// id is an identifier that should be unique for that set of classes that // id is an identifier that should be unique for that set of classes that
// are associated (e.g. all instances owned by an engine). // are associated (e.g. all instances owned by an engine).
// msg and the ellipsis are the same as e.g. sprintf. // msg and the ellipsis are the same as e.g. sprintf.
// TODO (hellner) Why is TraceModule not defined in this file? // TODO(hellner) Why is TraceModule not defined in this file?
static void Add(const TraceLevel level, static void Add(const TraceLevel level,
const TraceModule module, const TraceModule module,
const WebRtc_Word32 id, const WebRtc_Word32 id,
@@ -73,4 +73,5 @@ public:
}; };
} // namespace webrtc } // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ #endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_

File diff suppressed because it is too large Load Diff

View File

@@ -11,48 +11,47 @@
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_ #ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_ #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_
#include "system_wrappers/interface/critical_section_wrapper.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "system_wrappers/interface/event_wrapper.h" #include "webrtc/system_wrappers/interface/event_wrapper.h"
#include "system_wrappers/interface/file_wrapper.h" #include "webrtc/system_wrappers/interface/file_wrapper.h"
#include "system_wrappers/interface/static_instance.h" #include "webrtc/system_wrappers/interface/static_instance.h"
#include "system_wrappers/interface/trace.h" #include "webrtc/system_wrappers/interface/thread_wrapper.h"
#include "system_wrappers/interface/thread_wrapper.h" #include "webrtc/system_wrappers/interface/trace.h"
namespace webrtc { namespace webrtc {
// TODO (pwestin) WEBRTC_TRACE_MAX_QUEUE needs to be tweaked // TODO(pwestin) WEBRTC_TRACE_MAX_QUEUE needs to be tweaked
// TODO (hellner) the buffer should be close to how much the system can write to // TODO(hellner) the buffer should be close to how much the system can write to
// file. Increasing the buffer will not solve anything. Sooner or // file. Increasing the buffer will not solve anything. Sooner or
// later the buffer is going to fill up anyways. // later the buffer is going to fill up anyways.
#if defined(WEBRTC_IOS) #if defined(WEBRTC_IOS)
#define WEBRTC_TRACE_MAX_QUEUE 2000 #define WEBRTC_TRACE_MAX_QUEUE 2000
#else #else
#define WEBRTC_TRACE_MAX_QUEUE 8000 #define WEBRTC_TRACE_MAX_QUEUE 8000
#endif #endif
#define WEBRTC_TRACE_NUM_ARRAY 2 #define WEBRTC_TRACE_NUM_ARRAY 2
#define WEBRTC_TRACE_MAX_MESSAGE_SIZE 256 #define WEBRTC_TRACE_MAX_MESSAGE_SIZE 256
// Total buffer size is WEBRTC_TRACE_NUM_ARRAY (number of buffer partitions) * // Total buffer size is WEBRTC_TRACE_NUM_ARRAY (number of buffer partitions) *
// WEBRTC_TRACE_MAX_QUEUE (number of lines per buffer partition) * // WEBRTC_TRACE_MAX_QUEUE (number of lines per buffer partition) *
// WEBRTC_TRACE_MAX_MESSAGE_SIZE (number of 1 byte charachters per line) = // WEBRTC_TRACE_MAX_MESSAGE_SIZE (number of 1 byte charachters per line) =
// 1 or 4 Mbyte // 1 or 4 Mbyte.
#define WEBRTC_TRACE_MAX_FILE_SIZE 100*1000 #define WEBRTC_TRACE_MAX_FILE_SIZE 100*1000
// Number of rows that may be written to file. On average 110 bytes per row (max // Number of rows that may be written to file. On average 110 bytes per row (max
// 256 bytes per row). So on average 110*100*1000 = 11 Mbyte, max 256*100*1000 = // 256 bytes per row). So on average 110*100*1000 = 11 Mbyte, max 256*100*1000 =
// 25.6 Mbyte // 25.6 Mbyte
class TraceImpl : public Trace class TraceImpl : public Trace {
{ public:
public:
virtual ~TraceImpl(); virtual ~TraceImpl();
static TraceImpl* CreateInstance(); static TraceImpl* CreateInstance();
static TraceImpl* GetTrace(const TraceLevel level = kTraceAll); static TraceImpl* GetTrace(const TraceLevel level = kTraceAll);
WebRtc_Word32 SetTraceFileImpl(const char* fileName, WebRtc_Word32 SetTraceFileImpl(const char* file_name,
const bool addFileCounter); const bool add_file_counter);
WebRtc_Word32 TraceFileImpl( WebRtc_Word32 TraceFileImpl(
char fileName[FileWrapper::kMaxFileNameSize]); char file_name[FileWrapper::kMaxFileNameSize]);
WebRtc_Word32 SetTraceCallbackImpl(TraceCallback* callback); WebRtc_Word32 SetTraceCallbackImpl(TraceCallback* callback);
@@ -63,70 +62,71 @@ public:
bool TraceCheck(const TraceLevel level) const; bool TraceCheck(const TraceLevel level) const;
protected: protected:
TraceImpl(); TraceImpl();
static TraceImpl* StaticInstance(CountOperation count_operation, static TraceImpl* StaticInstance(CountOperation count_operation,
const TraceLevel level = kTraceAll); const TraceLevel level = kTraceAll);
WebRtc_Word32 AddThreadId(char* traceMessage) const; WebRtc_Word32 AddThreadId(char* trace_message) const;
// OS specific implementations // OS specific implementations.
virtual WebRtc_Word32 AddTime(char* traceMessage, virtual WebRtc_Word32 AddTime(char* trace_message,
const TraceLevel level) const = 0; const TraceLevel level) const = 0;
virtual WebRtc_Word32 AddBuildInfo(char* traceMessage) const = 0; virtual WebRtc_Word32 AddBuildInfo(char* trace_message) const = 0;
virtual WebRtc_Word32 AddDateTimeInfo(char* traceMessage) const = 0; virtual WebRtc_Word32 AddDateTimeInfo(char* trace_message) const = 0;
static bool Run(void* obj); static bool Run(void* obj);
bool Process(); bool Process();
private: private:
friend class Trace; friend class Trace;
WebRtc_Word32 AddLevel(char* szMessage, const TraceLevel level) const; WebRtc_Word32 AddLevel(char* sz_message, const TraceLevel level) const;
WebRtc_Word32 AddModuleAndId(char* traceMessage, const TraceModule module, WebRtc_Word32 AddModuleAndId(char* trace_message, const TraceModule module,
const WebRtc_Word32 id) const; const WebRtc_Word32 id) const;
WebRtc_Word32 AddMessage(char* traceMessage, WebRtc_Word32 AddMessage(char* trace_message,
const char msg[WEBRTC_TRACE_MAX_MESSAGE_SIZE], const char msg[WEBRTC_TRACE_MAX_MESSAGE_SIZE],
const WebRtc_UWord16 writtenSoFar) const; const WebRtc_UWord16 written_so_far) const;
void AddMessageToList( void AddMessageToList(
const char traceMessage[WEBRTC_TRACE_MAX_MESSAGE_SIZE], const char trace_message[WEBRTC_TRACE_MAX_MESSAGE_SIZE],
const WebRtc_UWord16 length, const WebRtc_UWord16 length,
const TraceLevel level); const TraceLevel level);
bool UpdateFileName( bool UpdateFileName(
const char fileNameUTF8[FileWrapper::kMaxFileNameSize], const char file_name_utf8[FileWrapper::kMaxFileNameSize],
char fileNameWithCounterUTF8[FileWrapper::kMaxFileNameSize], char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize],
const WebRtc_UWord32 newCount) const; const WebRtc_UWord32 new_count) const;
bool CreateFileName( bool CreateFileName(
const char fileNameUTF8[FileWrapper::kMaxFileNameSize], const char file_name_utf8[FileWrapper::kMaxFileNameSize],
char fileNameWithCounterUTF8[FileWrapper::kMaxFileNameSize], char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize],
const WebRtc_UWord32 newCount) const; const WebRtc_UWord32 new_count) const;
void WriteToFile(); void WriteToFile();
CriticalSectionWrapper* _critsectInterface; CriticalSectionWrapper* critsect_interface_;
TraceCallback* _callback; TraceCallback* callback_;
WebRtc_UWord32 _rowCountText; WebRtc_UWord32 row_count_text_;
WebRtc_UWord32 _fileCountText; WebRtc_UWord32 file_count_text_;
FileWrapper& _traceFile; FileWrapper& trace_file_;
ThreadWrapper& _thread; ThreadWrapper& thread_;
EventWrapper& _event; EventWrapper& event_;
// _critsectArray protects _activeQueue // critsect_array_ protects active_queue_.
CriticalSectionWrapper* _critsectArray; CriticalSectionWrapper* critsect_array_;
WebRtc_UWord16 _nextFreeIdx[WEBRTC_TRACE_NUM_ARRAY]; WebRtc_UWord16 next_free_idx_[WEBRTC_TRACE_NUM_ARRAY];
TraceLevel _level[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE]; TraceLevel level_[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE];
WebRtc_UWord16 _length[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE]; WebRtc_UWord16 length_[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE];
char* _messageQueue[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE]; char* message_queue_[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE];
WebRtc_UWord8 _activeQueue; WebRtc_UWord8 active_queue_;
}; };
} // namespace webrtc } // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_ #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_

View File

@@ -8,49 +8,39 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "trace.h" #include "webrtc/system_wrappers/interface/trace.h"
namespace webrtc { namespace webrtc {
void Trace::CreateTrace() void Trace::CreateTrace() {
{
} }
void Trace::ReturnTrace() void Trace::ReturnTrace() {
{
} }
WebRtc_Word32 Trace::SetLevelFilter(WebRtc_UWord32 /*filter*/) WebRtc_Word32 Trace::SetLevelFilter(WebRtc_UWord32 filter) {
{
return 0; return 0;
} }
WebRtc_Word32 Trace::LevelFilter(WebRtc_UWord32& /*filter*/) WebRtc_Word32 Trace::LevelFilter(WebRtc_UWord32& filter) {
{
return 0; return 0;
} }
WebRtc_Word32 Trace::TraceFile( WebRtc_Word32 Trace::TraceFile(char file_name[1024]) {
char/*fileName*/[1024])
{
return -1; return -1;
} }
WebRtc_Word32 Trace::SetTraceFile(const char* /*fileName*/, WebRtc_Word32 Trace::SetTraceFile(const char* file_name,
const bool /*addFileCounter*/) const bool add_file_counter) {
{
return -1; return -1;
} }
WebRtc_Word32 Trace::SetTraceCallback(TraceCallback* /*callback*/) WebRtc_Word32 Trace::SetTraceCallback(TraceCallback* callback) {
{
return -1; return -1;
} }
void Trace::Add(const TraceLevel /*level*/, const TraceModule /*module*/, void Trace::Add(const TraceLevel level, const TraceModule module,
const WebRtc_Word32 /*id*/, const char* /*msg*/, ...) const WebRtc_Word32 id, const char* msg, ...) {
{
} }
} // namespace webrtc } // namespace webrtc

View File

@@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "trace_posix.h" #include "webrtc/system_wrappers/source/trace_posix.h"
#include <cassert> #include <cassert>
#include <stdarg.h> #include <stdarg.h>
@@ -17,19 +17,19 @@
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#ifdef WEBRTC_ANDROID #ifdef WEBRTC_ANDROID
#include <pthread.h> #include <pthread.h>
#else #else
#include <iostream> #include <iostream>
#endif #endif
#if defined(_DEBUG) #if defined(_DEBUG)
#define BUILDMODE "d" #define BUILDMODE "d"
#elif defined(DEBUG) #elif defined(DEBUG)
#define BUILDMODE "d" #define BUILDMODE "d"
#elif defined(NDEBUG) #elif defined(NDEBUG)
#define BUILDMODE "r" #define BUILDMODE "r"
#else #else
#define BUILDMODE "?" #define BUILDMODE "?"
#endif #endif
#define BUILDTIME __TIME__ #define BUILDTIME __TIME__
#define BUILDDATE __DATE__ #define BUILDDATE __DATE__
@@ -37,84 +37,75 @@
#define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE #define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE
namespace webrtc { namespace webrtc {
TracePosix::TracePosix()
{ TracePosix::TracePosix() {
struct timeval systemTimeHighRes; struct timeval system_time_high_res;
gettimeofday(&systemTimeHighRes, 0); gettimeofday(&system_time_high_res, 0);
_prevAPITickCount = _prevTickCount = systemTimeHighRes.tv_sec; prev_api_tick_count_ = prev_tick_count_ = system_time_high_res.tv_sec;
} }
TracePosix::~TracePosix() TracePosix::~TracePosix() {
{
StopThread(); StopThread();
} }
WebRtc_Word32 TracePosix::AddTime(char* traceMessage, WebRtc_Word32 TracePosix::AddTime(char* trace_message,
const TraceLevel level) const const TraceLevel level) const {
{ struct timeval system_time_high_res;
struct timeval systemTimeHighRes; if (gettimeofday(&system_time_high_res, 0) == -1) {
if (gettimeofday(&systemTimeHighRes, 0) == -1)
{
return -1; return -1;
} }
struct tm buffer; struct tm buffer;
const struct tm* systemTime = const struct tm* system_time =
localtime_r(&systemTimeHighRes.tv_sec, &buffer); localtime_r(&system_time_high_res.tv_sec, &buffer);
const WebRtc_UWord32 ms_time = systemTimeHighRes.tv_usec / 1000; const WebRtc_UWord32 ms_time = system_time_high_res.tv_usec / 1000;
WebRtc_UWord32 prevTickCount = 0; WebRtc_UWord32 prev_tickCount = 0;
if (level == kTraceApiCall) if (level == kTraceApiCall) {
{ prev_tickCount = prev_tick_count_;
prevTickCount = _prevTickCount; prev_tick_count_ = ms_time;
_prevTickCount = ms_time;
} else { } else {
prevTickCount = _prevAPITickCount; prev_tickCount = prev_api_tick_count_;
_prevAPITickCount = ms_time; prev_api_tick_count_ = ms_time;
} }
WebRtc_UWord32 dwDeltaTime = ms_time - prevTickCount; WebRtc_UWord32 dw_delta_time = ms_time - prev_tickCount;
if (prevTickCount == 0) if (prev_tickCount == 0) {
{ dw_delta_time = 0;
dwDeltaTime = 0;
} }
if (dwDeltaTime > 0x0fffffff) if (dw_delta_time > 0x0fffffff) {
{
// Either wraparound or data race. // Either wraparound or data race.
dwDeltaTime = 0; dw_delta_time = 0;
} }
if(dwDeltaTime > 99999) if (dw_delta_time > 99999) {
{ dw_delta_time = 99999;
dwDeltaTime = 99999;
} }
sprintf(traceMessage, "(%2u:%2u:%2u:%3u |%5lu) ", systemTime->tm_hour, sprintf(trace_message, "(%2u:%2u:%2u:%3u |%5lu) ", system_time->tm_hour,
systemTime->tm_min, systemTime->tm_sec, ms_time, system_time->tm_min, system_time->tm_sec, ms_time,
static_cast<unsigned long>(dwDeltaTime)); static_cast<unsigned long>(dw_delta_time));
// Messages are 22 characters. // Messages are 22 characters.
return 22; return 22;
} }
WebRtc_Word32 TracePosix::AddBuildInfo(char* traceMessage) const WebRtc_Word32 TracePosix::AddBuildInfo(char* trace_message) const {
{ sprintf(trace_message, "Build info: %s", BUILDINFO);
sprintf(traceMessage, "Build info: %s", BUILDINFO);
// Include NULL termination (hence + 1). // Include NULL termination (hence + 1).
return strlen(traceMessage) + 1; return strlen(trace_message) + 1;
} }
WebRtc_Word32 TracePosix::AddDateTimeInfo(char* traceMessage) const WebRtc_Word32 TracePosix::AddDateTimeInfo(char* trace_message) const {
{
time_t t; time_t t;
time(&t); time(&t);
char buffer[26]; // man ctime says buffer should have room for >=26 bytes. char buffer[26]; // man ctime says buffer should have room for >=26 bytes.
sprintf(traceMessage, "Local Date: %s", ctime_r(&t, buffer)); sprintf(trace_message, "Local Date: %s", ctime_r(&t, buffer));
WebRtc_Word32 len = static_cast<WebRtc_Word32>(strlen(traceMessage)); WebRtc_Word32 len = static_cast<WebRtc_Word32>(strlen(trace_message));
if ('\n' == traceMessage[len - 1]) if ('\n' == trace_message[len - 1]) {
{ trace_message[len - 1] = '\0';
traceMessage[len - 1] = '\0';
--len; --len;
} }
// Messages is 12 characters. // Messages is 12 characters.
return len + 1; return len + 1;
} }
} // namespace webrtc } // namespace webrtc

View File

@@ -11,26 +11,27 @@
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_POSIX_H_ #ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_POSIX_H_
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_POSIX_H_ #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_POSIX_H_
#include "critical_section_wrapper.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "trace_impl.h" #include "webrtc/system_wrappers/source/trace_impl.h"
namespace webrtc { namespace webrtc {
class TracePosix : public TraceImpl
{ class TracePosix : public TraceImpl {
public: public:
TracePosix(); TracePosix();
virtual ~TracePosix(); virtual ~TracePosix();
virtual WebRtc_Word32 AddTime(char* traceMessage, virtual WebRtc_Word32 AddTime(char* trace_message,
const TraceLevel level) const; const TraceLevel level) const;
virtual WebRtc_Word32 AddBuildInfo(char* traceMessage) const; virtual WebRtc_Word32 AddBuildInfo(char* trace_message) const;
virtual WebRtc_Word32 AddDateTimeInfo(char* traceMessage) const; virtual WebRtc_Word32 AddDateTimeInfo(char* trace_message) const;
private: private:
volatile mutable WebRtc_UWord32 _prevAPITickCount; volatile mutable WebRtc_UWord32 prev_api_tick_count_;
volatile mutable WebRtc_UWord32 _prevTickCount; volatile mutable WebRtc_UWord32 prev_tick_count_;
}; };
} // namespace webrtc } // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_POSIX_H_ #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_POSIX_H_

View File

@@ -8,11 +8,10 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "system_wrappers/interface/trace.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "system_wrappers/source/cpu_measurement_harness.h" #include "webrtc/system_wrappers/interface/trace.h"
#include "testsupport/fileutils.h" #include "webrtc/system_wrappers/source/cpu_measurement_harness.h"
#include "webrtc/test/testsupport/fileutils.h"
using webrtc::CpuMeasurementHarness; using webrtc::CpuMeasurementHarness;
using webrtc::Trace; using webrtc::Trace;
@@ -23,8 +22,7 @@ class Logger : public webrtc::CpuTarget {
public: public:
Logger() { Logger() {
Trace::CreateTrace(); Trace::CreateTrace();
std::string trace_file = webrtc::test::OutputPath() + std::string trace_file = webrtc::test::OutputPath() + "trace_unittest.txt";
"trace_unittest.txt";
Trace::SetTraceFile(trace_file.c_str()); Trace::SetTraceFile(trace_file.c_str());
Trace::SetLevelFilter(webrtc::kTraceAll); Trace::SetLevelFilter(webrtc::kTraceAll);
} }

View File

@@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "trace_win.h" #include "webrtc/system_wrappers/source/trace_win.h"
#include <cassert> #include <cassert>
#include <stdarg.h> #include <stdarg.h>
@@ -16,13 +16,13 @@
#include "Mmsystem.h" #include "Mmsystem.h"
#if defined(_DEBUG) #if defined(_DEBUG)
#define BUILDMODE "d" #define BUILDMODE "d"
#elif defined(DEBUG) #elif defined(DEBUG)
#define BUILDMODE "d" #define BUILDMODE "d"
#elif defined(NDEBUG) #elif defined(NDEBUG)
#define BUILDMODE "r" #define BUILDMODE "r"
#else #else
#define BUILDMODE "?" #define BUILDMODE "?"
#endif #endif
#define BUILDTIME __TIME__ #define BUILDTIME __TIME__
#define BUILDDATE __DATE__ #define BUILDDATE __DATE__
@@ -31,101 +31,89 @@
namespace webrtc { namespace webrtc {
TraceWindows::TraceWindows() TraceWindows::TraceWindows()
: _prevAPITickCount(0), : prev_api_tick_count_(0),
_prevTickCount(0) prev_tick_count_(0) {
{
} }
TraceWindows::~TraceWindows() TraceWindows::~TraceWindows() {
{
StopThread(); StopThread();
} }
WebRtc_Word32 TraceWindows::AddTime(char* traceMessage, WebRtc_Word32 TraceWindows::AddTime(char* trace_message,
const TraceLevel level) const const TraceLevel level) const {
{ WebRtc_UWord32 dw_current_time = timeGetTime();
WebRtc_UWord32 dwCurrentTime = timeGetTime(); SYSTEMTIME system_time;
SYSTEMTIME systemTime; GetSystemTime(&system_time);
GetSystemTime(&systemTime);
if(level == kTraceApiCall) if (level == kTraceApiCall) {
{ WebRtc_UWord32 dw_delta_time = dw_current_time - prev_tick_count_;
WebRtc_UWord32 dwDeltaTime = dwCurrentTime- _prevTickCount; prev_tick_count_ = dw_current_time;
_prevTickCount = dwCurrentTime;
if(_prevTickCount == 0) if (prev_tick_count_ == 0) {
{ dw_delta_time = 0;
dwDeltaTime = 0;
} }
if(dwDeltaTime > 0x0fffffff) if (dw_delta_time > 0x0fffffff) {
{ // Either wrap-around or data race.
// Either wraparound or data race. dw_delta_time = 0;
dwDeltaTime = 0;
} }
if(dwDeltaTime > 99999) if (dw_delta_time > 99999) {
{ dw_delta_time = 99999;
dwDeltaTime = 99999;
} }
sprintf (traceMessage, "(%2u:%2u:%2u:%3u |%5lu) ", systemTime.wHour, sprintf(trace_message, "(%2u:%2u:%2u:%3u |%5lu) ", system_time.wHour,
systemTime.wMinute, systemTime.wSecond, system_time.wMinute, system_time.wSecond,
systemTime.wMilliseconds, dwDeltaTime); system_time.wMilliseconds, dw_delta_time);
} else { } else {
WebRtc_UWord32 dwDeltaTime = dwCurrentTime - _prevAPITickCount; WebRtc_UWord32 dw_delta_time = dw_current_time - prev_api_tick_count_;
_prevAPITickCount = dwCurrentTime; prev_api_tick_count_ = dw_current_time;
if(_prevAPITickCount == 0) if (prev_api_tick_count_ == 0) {
{ dw_delta_time = 0;
dwDeltaTime = 0;
} }
if(dwDeltaTime > 0x0fffffff) if (dw_delta_time > 0x0fffffff) {
{
// Either wraparound or data race. // Either wraparound or data race.
dwDeltaTime = 0; dw_delta_time = 0;
} }
if(dwDeltaTime > 99999) if (dw_delta_time > 99999) {
{ dw_delta_time = 99999;
dwDeltaTime = 99999;
} }
sprintf (traceMessage, "(%2u:%2u:%2u:%3u |%5lu) ", systemTime.wHour, sprintf(trace_message, "(%2u:%2u:%2u:%3u |%5lu) ", system_time.wHour,
systemTime.wMinute, systemTime.wSecond, system_time.wMinute, system_time.wSecond,
systemTime.wMilliseconds, dwDeltaTime); system_time.wMilliseconds, dw_delta_time);
} }
// Messages is 12 characters.
return 22; return 22;
} }
WebRtc_Word32 TraceWindows::AddBuildInfo(char* traceMessage) const WebRtc_Word32 TraceWindows::AddBuildInfo(char* trace_message) const {
{
// write data and time to text file // write data and time to text file
sprintf(traceMessage, "Build info: %s", BUILDINFO); sprintf(trace_message, "Build info: %s", BUILDINFO);
// Include NULL termination (hence + 1). // Include NULL termination (hence + 1).
return static_cast<WebRtc_Word32>(strlen(traceMessage)+1); return static_cast<WebRtc_Word32>(strlen(trace_message) + 1);
} }
WebRtc_Word32 TraceWindows::AddDateTimeInfo(char* traceMessage) const WebRtc_Word32 TraceWindows::AddDateTimeInfo(char* trace_message) const {
{ prev_api_tick_count_ = timeGetTime();
_prevAPITickCount = timeGetTime(); prev_tick_count_ = prev_api_tick_count_;
_prevTickCount = _prevAPITickCount;
SYSTEMTIME sysTime; SYSTEMTIME sys_time;
GetLocalTime (&sysTime); GetLocalTime(&sys_time);
TCHAR szDateStr[20]; TCHAR sz_date_str[20];
TCHAR szTimeStr[20]; TCHAR sz_time_str[20];
// Create date string (e.g. Apr 04 2002) // Create date string (e.g. Apr 04 2002)
GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &sysTime, TEXT("MMM dd yyyy"), GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &sys_time, TEXT("MMM dd yyyy"),
szDateStr, 20); sz_date_str, 20);
// Create time string (e.g. 15:32:08) // Create time string (e.g. 15:32:08)
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &sysTime, TEXT("HH':'mm':'ss"), GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &sys_time, TEXT("HH':'mm':'ss"),
szTimeStr, 20); sz_time_str, 20);
sprintf(traceMessage, "Local Date: %s Local Time: %s", szDateStr, sprintf(trace_message, "Local Date: %s Local Time: %s", sz_date_str,
szTimeStr); sz_time_str);
// Include NULL termination (hence + 1). // Include NULL termination (hence + 1).
return static_cast<WebRtc_Word32>(strlen(traceMessage)+ 1); return static_cast<WebRtc_Word32>(strlen(trace_message) + 1);
} }
} // namespace webrtc } // namespace webrtc

View File

@@ -8,29 +8,31 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_WINDOWS_H_ #ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_WIN_H_
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_WINDOWS_H_ #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_WIN_H_
#include "trace_impl.h"
#include <stdio.h> #include <stdio.h>
#include <windows.h> #include <windows.h>
#include "webrtc/system_wrappers/source/trace_impl.h"
namespace webrtc { namespace webrtc {
class TraceWindows : public TraceImpl
{ class TraceWindows : public TraceImpl {
public: public:
TraceWindows(); TraceWindows();
virtual ~TraceWindows(); virtual ~TraceWindows();
virtual WebRtc_Word32 AddTime(char* traceMessage, virtual WebRtc_Word32 AddTime(char* trace_message,
const TraceLevel level) const; const TraceLevel level) const;
virtual WebRtc_Word32 AddBuildInfo(char* traceMessage) const; virtual WebRtc_Word32 AddBuildInfo(char* trace_message) const;
virtual WebRtc_Word32 AddDateTimeInfo(char* traceMessage) const; virtual WebRtc_Word32 AddDateTimeInfo(char* trace_message) const;
private: private:
volatile mutable WebRtc_UWord32 _prevAPITickCount; volatile mutable WebRtc_UWord32 prev_api_tick_count_;
volatile mutable WebRtc_UWord32 _prevTickCount; volatile mutable WebRtc_UWord32 prev_tick_count_;
}; };
} // namespace webrtc } // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_WINDOWS_H_ #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_WIN_H_