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,71 +6,72 @@
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* 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_
#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_
#include "common_types.h"
#include "typedefs.h"
#include "webrtc/common_types.h"
#include "webrtc/typedefs.h"
#define WEBRTC_TRACE Trace::Add
namespace webrtc {
class Trace
{
public:
// Increments the reference count to the trace.
static void CreateTrace();
// Decrements the reference count to the trace.
static void ReturnTrace();
// Note: any instance that writes to the trace file should increment and
// decrement the reference count on construction and destruction
// respectively
class Trace {
public:
// Increments the reference count to the trace.
static void CreateTrace();
// Decrements the reference count to the trace.
static void ReturnTrace();
// Note: any instance that writes to the trace file should increment and
// decrement the reference count on construction and destruction,
// respectively.
// 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
// the TraceLevel enumerator. TODO(hellner): why is the
// TraceLevel enumerator not defined in this file?
static WebRtc_Word32 SetLevelFilter(const WebRtc_UWord32 filter);
// 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 the
// TraceLevel enumerator. TODO(hellner): why is the TraceLevel enumerator not
// defined in this file?
static WebRtc_Word32 SetLevelFilter(const WebRtc_UWord32 filter);
// Returns what type of messages are written to the trace file.
static WebRtc_Word32 LevelFilter(WebRtc_UWord32& filter);
// Returns what type of messages are written to the trace file.
static WebRtc_Word32 LevelFilter(WebRtc_UWord32& filter);
// Sets the file name. If addFileCounter is false the same file will be
// reused when it fills up. If it's true a new file with incremented name
// will be used.
static WebRtc_Word32 SetTraceFile(const char* fileName,
const bool addFileCounter = false);
// 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
// will be used.
static WebRtc_Word32 SetTraceFile(const char* file_name,
const bool add_file_counter = false);
// Returns the name of the file that the trace is currently writing to.
static WebRtc_Word32 TraceFile(char fileName[1024]);
// Returns the name of the file that the trace is currently writing to.
static WebRtc_Word32 TraceFile(char file_name[1024]);
// Registers callback to receive trace messages. TODO (hellner)
// why not use OutStream instead? Why is TraceCallback not defined in this
// file
static WebRtc_Word32 SetTraceCallback(TraceCallback* callback);
// Registers callback to receive trace messages.
// TODO(hellner): Why not use OutStream instead? Why is TraceCallback not
// defined in this file?
static WebRtc_Word32 SetTraceCallback(TraceCallback* callback);
// Adds a trace message for writing to file. The message is put in a queue
// for writing to file whenever possible for performance reasons. I.e. there
// is a crash it is possible that the last, vital logs are not logged yet.
// level is the type of message to log. If that type of messages is
// filtered it will not be written to file. module is an identifier for what
// part of the code the message is coming.
// id is an identifier that should be unique for that set of classes that
// are associated (e.g. all instances owned by an engine).
// msg and the ellipsis are the same as e.g. sprintf.
// TODO (hellner) Why is TraceModule not defined in this file?
static void Add(const TraceLevel level,
const TraceModule module,
const WebRtc_Word32 id,
const char* msg, ...);
// Adds a trace message for writing to file. The message is put in a queue
// for writing to file whenever possible for performance reasons. I.e. there
// is a crash it is possible that the last, vital logs are not logged yet.
// level is the type of message to log. If that type of messages is
// filtered it will not be written to file. module is an identifier for what
// part of the code the message is coming.
// id is an identifier that should be unique for that set of classes that
// are associated (e.g. all instances owned by an engine).
// msg and the ellipsis are the same as e.g. sprintf.
// TODO(hellner) Why is TraceModule not defined in this file?
static void Add(const TraceLevel level,
const TraceModule module,
const WebRtc_Word32 id,
const char* msg, ...);
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_

File diff suppressed because it is too large Load Diff

View File

@@ -11,122 +11,122 @@
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_
#include "system_wrappers/interface/critical_section_wrapper.h"
#include "system_wrappers/interface/event_wrapper.h"
#include "system_wrappers/interface/file_wrapper.h"
#include "system_wrappers/interface/static_instance.h"
#include "system_wrappers/interface/trace.h"
#include "system_wrappers/interface/thread_wrapper.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/event_wrapper.h"
#include "webrtc/system_wrappers/interface/file_wrapper.h"
#include "webrtc/system_wrappers/interface/static_instance.h"
#include "webrtc/system_wrappers/interface/thread_wrapper.h"
#include "webrtc/system_wrappers/interface/trace.h"
namespace webrtc {
// 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
// file. Increasing the buffer will not solve anything. Sooner or
// later the buffer is going to fill up anyways.
// 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
// file. Increasing the buffer will not solve anything. Sooner or
// later the buffer is going to fill up anyways.
#if defined(WEBRTC_IOS)
#define WEBRTC_TRACE_MAX_QUEUE 2000
#define WEBRTC_TRACE_MAX_QUEUE 2000
#else
#define WEBRTC_TRACE_MAX_QUEUE 8000
#define WEBRTC_TRACE_MAX_QUEUE 8000
#endif
#define WEBRTC_TRACE_NUM_ARRAY 2
#define WEBRTC_TRACE_MAX_MESSAGE_SIZE 256
// 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_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
// 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 =
// 25.6 Mbyte
class TraceImpl : public Trace
{
public:
virtual ~TraceImpl();
class TraceImpl : public Trace {
public:
virtual ~TraceImpl();
static TraceImpl* CreateInstance();
static TraceImpl* GetTrace(const TraceLevel level = kTraceAll);
static TraceImpl* CreateInstance();
static TraceImpl* GetTrace(const TraceLevel level = kTraceAll);
WebRtc_Word32 SetTraceFileImpl(const char* fileName,
const bool addFileCounter);
WebRtc_Word32 TraceFileImpl(
char fileName[FileWrapper::kMaxFileNameSize]);
WebRtc_Word32 SetTraceFileImpl(const char* file_name,
const bool add_file_counter);
WebRtc_Word32 TraceFileImpl(
char file_name[FileWrapper::kMaxFileNameSize]);
WebRtc_Word32 SetTraceCallbackImpl(TraceCallback* callback);
WebRtc_Word32 SetTraceCallbackImpl(TraceCallback* callback);
void AddImpl(const TraceLevel level, const TraceModule module,
const WebRtc_Word32 id, const char* msg);
void AddImpl(const TraceLevel level, const TraceModule module,
const WebRtc_Word32 id, const char* msg);
bool StopThread();
bool StopThread();
bool TraceCheck(const TraceLevel level) const;
bool TraceCheck(const TraceLevel level) const;
protected:
TraceImpl();
protected:
TraceImpl();
static TraceImpl* StaticInstance(CountOperation count_operation,
const TraceLevel level = kTraceAll);
static TraceImpl* StaticInstance(CountOperation count_operation,
const TraceLevel level = kTraceAll);
WebRtc_Word32 AddThreadId(char* traceMessage) const;
WebRtc_Word32 AddThreadId(char* trace_message) const;
// OS specific implementations
virtual WebRtc_Word32 AddTime(char* traceMessage,
const TraceLevel level) const = 0;
// OS specific implementations.
virtual WebRtc_Word32 AddTime(char* trace_message,
const TraceLevel level) const = 0;
virtual WebRtc_Word32 AddBuildInfo(char* traceMessage) const = 0;
virtual WebRtc_Word32 AddDateTimeInfo(char* traceMessage) const = 0;
virtual WebRtc_Word32 AddBuildInfo(char* trace_message) const = 0;
virtual WebRtc_Word32 AddDateTimeInfo(char* trace_message) const = 0;
static bool Run(void* obj);
bool Process();
static bool Run(void* obj);
bool Process();
private:
friend class Trace;
private:
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,
const WebRtc_Word32 id) const;
WebRtc_Word32 AddModuleAndId(char* trace_message, const TraceModule module,
const WebRtc_Word32 id) const;
WebRtc_Word32 AddMessage(char* traceMessage,
const char msg[WEBRTC_TRACE_MAX_MESSAGE_SIZE],
const WebRtc_UWord16 writtenSoFar) const;
WebRtc_Word32 AddMessage(char* trace_message,
const char msg[WEBRTC_TRACE_MAX_MESSAGE_SIZE],
const WebRtc_UWord16 written_so_far) const;
void AddMessageToList(
const char traceMessage[WEBRTC_TRACE_MAX_MESSAGE_SIZE],
const WebRtc_UWord16 length,
const TraceLevel level);
void AddMessageToList(
const char trace_message[WEBRTC_TRACE_MAX_MESSAGE_SIZE],
const WebRtc_UWord16 length,
const TraceLevel level);
bool UpdateFileName(
const char fileNameUTF8[FileWrapper::kMaxFileNameSize],
char fileNameWithCounterUTF8[FileWrapper::kMaxFileNameSize],
const WebRtc_UWord32 newCount) const;
bool UpdateFileName(
const char file_name_utf8[FileWrapper::kMaxFileNameSize],
char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize],
const WebRtc_UWord32 new_count) const;
bool CreateFileName(
const char fileNameUTF8[FileWrapper::kMaxFileNameSize],
char fileNameWithCounterUTF8[FileWrapper::kMaxFileNameSize],
const WebRtc_UWord32 newCount) const;
bool CreateFileName(
const char file_name_utf8[FileWrapper::kMaxFileNameSize],
char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize],
const WebRtc_UWord32 new_count) const;
void WriteToFile();
void WriteToFile();
CriticalSectionWrapper* _critsectInterface;
TraceCallback* _callback;
WebRtc_UWord32 _rowCountText;
WebRtc_UWord32 _fileCountText;
CriticalSectionWrapper* critsect_interface_;
TraceCallback* callback_;
WebRtc_UWord32 row_count_text_;
WebRtc_UWord32 file_count_text_;
FileWrapper& _traceFile;
ThreadWrapper& _thread;
EventWrapper& _event;
FileWrapper& trace_file_;
ThreadWrapper& thread_;
EventWrapper& event_;
// _critsectArray protects _activeQueue
CriticalSectionWrapper* _critsectArray;
WebRtc_UWord16 _nextFreeIdx[WEBRTC_TRACE_NUM_ARRAY];
TraceLevel _level[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];
WebRtc_UWord8 _activeQueue;
// critsect_array_ protects active_queue_.
CriticalSectionWrapper* critsect_array_;
WebRtc_UWord16 next_free_idx_[WEBRTC_TRACE_NUM_ARRAY];
TraceLevel level_[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE];
WebRtc_UWord16 length_[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE];
char* message_queue_[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE];
WebRtc_UWord8 active_queue_;
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_
} // namespace webrtc
#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.
*/
#include "trace.h"
#include "webrtc/system_wrappers/interface/trace.h"
namespace webrtc {
void Trace::CreateTrace()
{
void Trace::CreateTrace() {
}
void Trace::ReturnTrace()
{
void Trace::ReturnTrace() {
}
WebRtc_Word32 Trace::SetLevelFilter(WebRtc_UWord32 /*filter*/)
{
return 0;
WebRtc_Word32 Trace::SetLevelFilter(WebRtc_UWord32 filter) {
return 0;
}
WebRtc_Word32 Trace::LevelFilter(WebRtc_UWord32& /*filter*/)
{
return 0;
WebRtc_Word32 Trace::LevelFilter(WebRtc_UWord32& filter) {
return 0;
}
WebRtc_Word32 Trace::TraceFile(
char/*fileName*/[1024])
{
return -1;
WebRtc_Word32 Trace::TraceFile(char file_name[1024]) {
return -1;
}
WebRtc_Word32 Trace::SetTraceFile(const char* /*fileName*/,
const bool /*addFileCounter*/)
{
return -1;
WebRtc_Word32 Trace::SetTraceFile(const char* file_name,
const bool add_file_counter) {
return -1;
}
WebRtc_Word32 Trace::SetTraceCallback(TraceCallback* /*callback*/)
{
return -1;
WebRtc_Word32 Trace::SetTraceCallback(TraceCallback* callback) {
return -1;
}
void Trace::Add(const TraceLevel /*level*/, const TraceModule /*module*/,
const WebRtc_Word32 /*id*/, const char* /*msg*/, ...)
{
void Trace::Add(const TraceLevel level, const TraceModule module,
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.
*/
#include "trace_posix.h"
#include "webrtc/system_wrappers/source/trace_posix.h"
#include <cassert>
#include <stdarg.h>
@@ -17,19 +17,19 @@
#include <sys/time.h>
#include <time.h>
#ifdef WEBRTC_ANDROID
#include <pthread.h>
#include <pthread.h>
#else
#include <iostream>
#include <iostream>
#endif
#if defined(_DEBUG)
#define BUILDMODE "d"
#define BUILDMODE "d"
#elif defined(DEBUG)
#define BUILDMODE "d"
#define BUILDMODE "d"
#elif defined(NDEBUG)
#define BUILDMODE "r"
#define BUILDMODE "r"
#else
#define BUILDMODE "?"
#define BUILDMODE "?"
#endif
#define BUILDTIME __TIME__
#define BUILDDATE __DATE__
@@ -37,84 +37,75 @@
#define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE
namespace webrtc {
TracePosix::TracePosix()
{
struct timeval systemTimeHighRes;
gettimeofday(&systemTimeHighRes, 0);
_prevAPITickCount = _prevTickCount = systemTimeHighRes.tv_sec;
TracePosix::TracePosix() {
struct timeval system_time_high_res;
gettimeofday(&system_time_high_res, 0);
prev_api_tick_count_ = prev_tick_count_ = system_time_high_res.tv_sec;
}
TracePosix::~TracePosix()
{
StopThread();
TracePosix::~TracePosix() {
StopThread();
}
WebRtc_Word32 TracePosix::AddTime(char* traceMessage,
const TraceLevel level) const
{
struct timeval systemTimeHighRes;
if (gettimeofday(&systemTimeHighRes, 0) == -1)
{
return -1;
}
struct tm buffer;
const struct tm* systemTime =
localtime_r(&systemTimeHighRes.tv_sec, &buffer);
WebRtc_Word32 TracePosix::AddTime(char* trace_message,
const TraceLevel level) const {
struct timeval system_time_high_res;
if (gettimeofday(&system_time_high_res, 0) == -1) {
return -1;
}
struct tm buffer;
const struct tm* system_time =
localtime_r(&system_time_high_res.tv_sec, &buffer);
const WebRtc_UWord32 ms_time = systemTimeHighRes.tv_usec / 1000;
WebRtc_UWord32 prevTickCount = 0;
if (level == kTraceApiCall)
{
prevTickCount = _prevTickCount;
_prevTickCount = ms_time;
} else {
prevTickCount = _prevAPITickCount;
_prevAPITickCount = ms_time;
}
WebRtc_UWord32 dwDeltaTime = ms_time - prevTickCount;
if (prevTickCount == 0)
{
dwDeltaTime = 0;
}
if (dwDeltaTime > 0x0fffffff)
{
// Either wraparound or data race.
dwDeltaTime = 0;
}
if(dwDeltaTime > 99999)
{
dwDeltaTime = 99999;
}
const WebRtc_UWord32 ms_time = system_time_high_res.tv_usec / 1000;
WebRtc_UWord32 prev_tickCount = 0;
if (level == kTraceApiCall) {
prev_tickCount = prev_tick_count_;
prev_tick_count_ = ms_time;
} else {
prev_tickCount = prev_api_tick_count_;
prev_api_tick_count_ = ms_time;
}
WebRtc_UWord32 dw_delta_time = ms_time - prev_tickCount;
if (prev_tickCount == 0) {
dw_delta_time = 0;
}
if (dw_delta_time > 0x0fffffff) {
// Either wraparound or data race.
dw_delta_time = 0;
}
if (dw_delta_time > 99999) {
dw_delta_time = 99999;
}
sprintf(traceMessage, "(%2u:%2u:%2u:%3u |%5lu) ", systemTime->tm_hour,
systemTime->tm_min, systemTime->tm_sec, ms_time,
static_cast<unsigned long>(dwDeltaTime));
// Messages are 22 characters.
return 22;
sprintf(trace_message, "(%2u:%2u:%2u:%3u |%5lu) ", system_time->tm_hour,
system_time->tm_min, system_time->tm_sec, ms_time,
static_cast<unsigned long>(dw_delta_time));
// Messages are 22 characters.
return 22;
}
WebRtc_Word32 TracePosix::AddBuildInfo(char* traceMessage) const
{
sprintf(traceMessage, "Build info: %s", BUILDINFO);
// Include NULL termination (hence + 1).
return strlen(traceMessage) + 1;
WebRtc_Word32 TracePosix::AddBuildInfo(char* trace_message) const {
sprintf(trace_message, "Build info: %s", BUILDINFO);
// Include NULL termination (hence + 1).
return strlen(trace_message) + 1;
}
WebRtc_Word32 TracePosix::AddDateTimeInfo(char* traceMessage) const
{
time_t t;
time(&t);
char buffer[26]; // man ctime says buffer should have room for >=26 bytes.
sprintf(traceMessage, "Local Date: %s", ctime_r(&t, buffer));
WebRtc_Word32 len = static_cast<WebRtc_Word32>(strlen(traceMessage));
WebRtc_Word32 TracePosix::AddDateTimeInfo(char* trace_message) const {
time_t t;
time(&t);
char buffer[26]; // man ctime says buffer should have room for >=26 bytes.
sprintf(trace_message, "Local Date: %s", ctime_r(&t, buffer));
WebRtc_Word32 len = static_cast<WebRtc_Word32>(strlen(trace_message));
if ('\n' == traceMessage[len - 1])
{
traceMessage[len - 1] = '\0';
--len;
}
if ('\n' == trace_message[len - 1]) {
trace_message[len - 1] = '\0';
--len;
}
// Messages is 12 characters.
return len + 1;
// Messages is 12 characters.
return len + 1;
}
} // namespace webrtc
} // namespace webrtc

View File

@@ -11,26 +11,27 @@
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_POSIX_H_
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_POSIX_H_
#include "critical_section_wrapper.h"
#include "trace_impl.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/source/trace_impl.h"
namespace webrtc {
class TracePosix : public TraceImpl
{
public:
TracePosix();
virtual ~TracePosix();
virtual WebRtc_Word32 AddTime(char* traceMessage,
const TraceLevel level) const;
class TracePosix : public TraceImpl {
public:
TracePosix();
virtual ~TracePosix();
virtual WebRtc_Word32 AddBuildInfo(char* traceMessage) const;
virtual WebRtc_Word32 AddDateTimeInfo(char* traceMessage) const;
virtual WebRtc_Word32 AddTime(char* trace_message,
const TraceLevel level) const;
private:
volatile mutable WebRtc_UWord32 _prevAPITickCount;
volatile mutable WebRtc_UWord32 _prevTickCount;
virtual WebRtc_Word32 AddBuildInfo(char* trace_message) const;
virtual WebRtc_Word32 AddDateTimeInfo(char* trace_message) const;
private:
volatile mutable WebRtc_UWord32 prev_api_tick_count_;
volatile mutable WebRtc_UWord32 prev_tick_count_;
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_POSIX_H_
} // namespace webrtc
#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.
*/
#include "system_wrappers/interface/trace.h"
#include "gtest/gtest.h"
#include "system_wrappers/source/cpu_measurement_harness.h"
#include "testsupport/fileutils.h"
#include "webrtc/system_wrappers/interface/trace.h"
#include "webrtc/system_wrappers/source/cpu_measurement_harness.h"
#include "webrtc/test/testsupport/fileutils.h"
using webrtc::CpuMeasurementHarness;
using webrtc::Trace;
@@ -23,8 +22,7 @@ class Logger : public webrtc::CpuTarget {
public:
Logger() {
Trace::CreateTrace();
std::string trace_file = webrtc::test::OutputPath() +
"trace_unittest.txt";
std::string trace_file = webrtc::test::OutputPath() + "trace_unittest.txt";
Trace::SetTraceFile(trace_file.c_str());
Trace::SetLevelFilter(webrtc::kTraceAll);
}
@@ -49,8 +47,8 @@ TEST(TraceTest, DISABLED_CpuUsage) {
const int iterations_per_period = 10;
const int duration_ms = 1000;
CpuMeasurementHarness* cpu_harness =
CpuMeasurementHarness::Create(&logger, periodicity_ms,
iterations_per_period, duration_ms);
CpuMeasurementHarness::Create(&logger, periodicity_ms,
iterations_per_period, duration_ms);
cpu_harness->Run();
const int average_cpu = cpu_harness->AverageCpu();
EXPECT_GE(5, average_cpu);

View File

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