niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 | |
| 11 | #ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_ |
| 12 | #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_ |
| 13 | |
| 14 | #include "system_wrappers/interface/critical_section_wrapper.h" |
| 15 | #include "system_wrappers/interface/event_wrapper.h" |
| 16 | #include "system_wrappers/interface/file_wrapper.h" |
henrike@webrtc.org | 315282c | 2011-12-09 17:46:20 +0000 | [diff] [blame] | 17 | #include "system_wrappers/interface/static_instance.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | #include "system_wrappers/interface/trace.h" |
| 19 | #include "system_wrappers/interface/thread_wrapper.h" |
| 20 | |
| 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
| 23 | // TODO (pwestin) WEBRTC_TRACE_MAX_QUEUE needs to be tweaked |
| 24 | // TODO (hellner) the buffer should be close to how much the system can write to |
| 25 | // file. Increasing the buffer will not solve anything. Sooner or |
| 26 | // later the buffer is going to fill up anyways. |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 27 | #if defined(WEBRTC_IOS) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | #define WEBRTC_TRACE_MAX_QUEUE 2000 |
| 29 | #else |
| 30 | #define WEBRTC_TRACE_MAX_QUEUE 8000 |
| 31 | #endif |
| 32 | #define WEBRTC_TRACE_NUM_ARRAY 2 |
| 33 | #define WEBRTC_TRACE_MAX_MESSAGE_SIZE 256 |
| 34 | // Total buffer size is WEBRTC_TRACE_NUM_ARRAY (number of buffer partitions) * |
| 35 | // WEBRTC_TRACE_MAX_QUEUE (number of lines per buffer partition) * |
| 36 | // WEBRTC_TRACE_MAX_MESSAGE_SIZE (number of 1 byte charachters per line) = |
| 37 | // 1 or 4 Mbyte |
| 38 | |
| 39 | #define WEBRTC_TRACE_MAX_FILE_SIZE 100*1000 |
| 40 | // Number of rows that may be written to file. On average 110 bytes per row (max |
| 41 | // 256 bytes per row). So on average 110*100*1000 = 11 Mbyte, max 256*100*1000 = |
| 42 | // 25.6 Mbyte |
| 43 | |
| 44 | class TraceImpl : public Trace |
| 45 | { |
| 46 | public: |
| 47 | virtual ~TraceImpl(); |
| 48 | |
henrike@webrtc.org | 315282c | 2011-12-09 17:46:20 +0000 | [diff] [blame] | 49 | static TraceImpl* CreateInstance(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | static TraceImpl* GetTrace(const TraceLevel level = kTraceAll); |
| 51 | |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 52 | WebRtc_Word32 SetTraceFileImpl(const char* fileName, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | const bool addFileCounter); |
| 54 | WebRtc_Word32 TraceFileImpl( |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 55 | char fileName[FileWrapper::kMaxFileNameSize]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | |
| 57 | WebRtc_Word32 SetTraceCallbackImpl(TraceCallback* callback); |
| 58 | |
| 59 | void AddImpl(const TraceLevel level, const TraceModule module, |
| 60 | const WebRtc_Word32 id, const char* msg); |
| 61 | |
| 62 | bool StopThread(); |
| 63 | |
| 64 | bool TraceCheck(const TraceLevel level) const; |
| 65 | |
| 66 | protected: |
| 67 | TraceImpl(); |
| 68 | |
henrike@webrtc.org | 315282c | 2011-12-09 17:46:20 +0000 | [diff] [blame] | 69 | static TraceImpl* StaticInstance(CountOperation count_operation, |
| 70 | const TraceLevel level = kTraceAll); |
| 71 | |
pwestin@webrtc.org | b54d727 | 2012-01-11 08:28:04 +0000 | [diff] [blame] | 72 | WebRtc_Word32 AddThreadId(char* traceMessage) const; |
| 73 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | // OS specific implementations |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | virtual WebRtc_Word32 AddTime(char* traceMessage, |
| 76 | const TraceLevel level) const = 0; |
| 77 | |
| 78 | virtual WebRtc_Word32 AddBuildInfo(char* traceMessage) const = 0; |
| 79 | virtual WebRtc_Word32 AddDateTimeInfo(char* traceMessage) const = 0; |
| 80 | |
| 81 | static bool Run(void* obj); |
| 82 | bool Process(); |
| 83 | |
| 84 | private: |
henrike@webrtc.org | 315282c | 2011-12-09 17:46:20 +0000 | [diff] [blame] | 85 | friend class Trace; |
| 86 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | WebRtc_Word32 AddLevel(char* szMessage, const TraceLevel level) const; |
| 88 | |
| 89 | WebRtc_Word32 AddModuleAndId(char* traceMessage, const TraceModule module, |
| 90 | const WebRtc_Word32 id) const; |
| 91 | |
| 92 | WebRtc_Word32 AddMessage(char* traceMessage, |
| 93 | const char msg[WEBRTC_TRACE_MAX_MESSAGE_SIZE], |
| 94 | const WebRtc_UWord16 writtenSoFar) const; |
| 95 | |
| 96 | void AddMessageToList( |
| 97 | const char traceMessage[WEBRTC_TRACE_MAX_MESSAGE_SIZE], |
| 98 | const WebRtc_UWord16 length, |
| 99 | const TraceLevel level); |
| 100 | |
| 101 | bool UpdateFileName( |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 102 | const char fileNameUTF8[FileWrapper::kMaxFileNameSize], |
| 103 | char fileNameWithCounterUTF8[FileWrapper::kMaxFileNameSize], |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | const WebRtc_UWord32 newCount) const; |
| 105 | |
| 106 | bool CreateFileName( |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 107 | const char fileNameUTF8[FileWrapper::kMaxFileNameSize], |
| 108 | char fileNameWithCounterUTF8[FileWrapper::kMaxFileNameSize], |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | const WebRtc_UWord32 newCount) const; |
| 110 | |
| 111 | void WriteToFile(); |
| 112 | |
henrike@webrtc.org | bfa80ce | 2011-12-15 17:59:58 +0000 | [diff] [blame] | 113 | CriticalSectionWrapper* _critsectInterface; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | TraceCallback* _callback; |
| 115 | WebRtc_UWord32 _rowCountText; |
| 116 | WebRtc_UWord32 _fileCountText; |
| 117 | |
| 118 | FileWrapper& _traceFile; |
| 119 | ThreadWrapper& _thread; |
| 120 | EventWrapper& _event; |
| 121 | |
| 122 | // _critsectArray protects _activeQueue |
henrike@webrtc.org | bfa80ce | 2011-12-15 17:59:58 +0000 | [diff] [blame] | 123 | CriticalSectionWrapper* _critsectArray; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 124 | WebRtc_UWord16 _nextFreeIdx[WEBRTC_TRACE_NUM_ARRAY]; |
| 125 | TraceLevel _level[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE]; |
| 126 | WebRtc_UWord16 _length[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE]; |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 127 | char* _messageQueue[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | WebRtc_UWord8 _activeQueue; |
| 129 | }; |
| 130 | } // namespace webrtc |
| 131 | |
| 132 | #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_ |