2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-24 17:16:59 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_
|
|
|
|
|
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_
|
|
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
#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"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
// 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.
|
2012-09-11 17:25:46 +00:00
|
|
|
#if defined(WEBRTC_IOS)
|
2013-01-03 09:37:03 +00:00
|
|
|
#define WEBRTC_TRACE_MAX_QUEUE 2000
|
2011-07-07 08:21:25 +00:00
|
|
|
#else
|
2013-01-03 09:37:03 +00:00
|
|
|
#define WEBRTC_TRACE_MAX_QUEUE 8000
|
2011-07-07 08:21:25 +00:00
|
|
|
#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) =
|
2013-01-03 09:37:03 +00:00
|
|
|
// 1 or 4 Mbyte.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
class TraceImpl : public Trace {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~TraceImpl();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
static TraceImpl* CreateInstance();
|
|
|
|
|
static TraceImpl* GetTrace(const TraceLevel level = kTraceAll);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
WebRtc_Word32 SetTraceFileImpl(const char* file_name,
|
|
|
|
|
const bool add_file_counter);
|
|
|
|
|
WebRtc_Word32 TraceFileImpl(
|
|
|
|
|
char file_name[FileWrapper::kMaxFileNameSize]);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
WebRtc_Word32 SetTraceCallbackImpl(TraceCallback* callback);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
void AddImpl(const TraceLevel level, const TraceModule module,
|
|
|
|
|
const WebRtc_Word32 id, const char* msg);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
bool StopThread();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
bool TraceCheck(const TraceLevel level) const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
protected:
|
|
|
|
|
TraceImpl();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
static TraceImpl* StaticInstance(CountOperation count_operation,
|
|
|
|
|
const TraceLevel level = kTraceAll);
|
2011-12-09 17:46:20 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
WebRtc_Word32 AddThreadId(char* trace_message) const;
|
2012-01-11 08:28:04 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
// OS specific implementations.
|
|
|
|
|
virtual WebRtc_Word32 AddTime(char* trace_message,
|
|
|
|
|
const TraceLevel level) const = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
virtual WebRtc_Word32 AddBuildInfo(char* trace_message) const = 0;
|
|
|
|
|
virtual WebRtc_Word32 AddDateTimeInfo(char* trace_message) const = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
static bool Run(void* obj);
|
|
|
|
|
bool Process();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
private:
|
|
|
|
|
friend class Trace;
|
2011-12-09 17:46:20 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
WebRtc_Word32 AddLevel(char* sz_message, const TraceLevel level) const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
WebRtc_Word32 AddModuleAndId(char* trace_message, const TraceModule module,
|
|
|
|
|
const WebRtc_Word32 id) const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
WebRtc_Word32 AddMessage(char* trace_message,
|
|
|
|
|
const char msg[WEBRTC_TRACE_MAX_MESSAGE_SIZE],
|
|
|
|
|
const WebRtc_UWord16 written_so_far) const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
void AddMessageToList(
|
|
|
|
|
const char trace_message[WEBRTC_TRACE_MAX_MESSAGE_SIZE],
|
|
|
|
|
const WebRtc_UWord16 length,
|
|
|
|
|
const TraceLevel level);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
bool UpdateFileName(
|
|
|
|
|
const char file_name_utf8[FileWrapper::kMaxFileNameSize],
|
|
|
|
|
char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize],
|
|
|
|
|
const WebRtc_UWord32 new_count) const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
bool CreateFileName(
|
|
|
|
|
const char file_name_utf8[FileWrapper::kMaxFileNameSize],
|
|
|
|
|
char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize],
|
|
|
|
|
const WebRtc_UWord32 new_count) const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
void WriteToFile();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
CriticalSectionWrapper* critsect_interface_;
|
|
|
|
|
TraceCallback* callback_;
|
|
|
|
|
WebRtc_UWord32 row_count_text_;
|
|
|
|
|
WebRtc_UWord32 file_count_text_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
FileWrapper& trace_file_;
|
|
|
|
|
ThreadWrapper& thread_;
|
|
|
|
|
EventWrapper& event_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
// 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_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
2013-01-03 09:37:03 +00:00
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_
|