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 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 14 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 15 | #include "webrtc/system_wrappers/interface/event_wrapper.h" |
| 16 | #include "webrtc/system_wrappers/interface/file_wrapper.h" |
| 17 | #include "webrtc/system_wrappers/interface/static_instance.h" |
| 18 | #include "webrtc/system_wrappers/interface/thread_wrapper.h" |
| 19 | #include "webrtc/system_wrappers/interface/trace.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 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) |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 28 | #define WEBRTC_TRACE_MAX_QUEUE 2000 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | #else |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 30 | #define WEBRTC_TRACE_MAX_QUEUE 8000 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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) = |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 37 | // 1 or 4 Mbyte. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 44 | class TraceImpl : public Trace { |
| 45 | public: |
| 46 | virtual ~TraceImpl(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 48 | static TraceImpl* CreateInstance(); |
| 49 | static TraceImpl* GetTrace(const TraceLevel level = kTraceAll); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 51 | WebRtc_Word32 SetTraceFileImpl(const char* file_name, |
| 52 | const bool add_file_counter); |
| 53 | WebRtc_Word32 TraceFileImpl( |
| 54 | char file_name[FileWrapper::kMaxFileNameSize]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 56 | WebRtc_Word32 SetTraceCallbackImpl(TraceCallback* callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 58 | void AddImpl(const TraceLevel level, const TraceModule module, |
| 59 | const WebRtc_Word32 id, const char* msg); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 61 | bool StopThread(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 63 | bool TraceCheck(const TraceLevel level) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 65 | protected: |
| 66 | TraceImpl(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 68 | static TraceImpl* StaticInstance(CountOperation count_operation, |
| 69 | const TraceLevel level = kTraceAll); |
henrike@webrtc.org | 315282c | 2011-12-09 17:46:20 +0000 | [diff] [blame] | 70 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 71 | WebRtc_Word32 AddThreadId(char* trace_message) const; |
pwestin@webrtc.org | b54d727 | 2012-01-11 08:28:04 +0000 | [diff] [blame] | 72 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 73 | // OS specific implementations. |
| 74 | virtual WebRtc_Word32 AddTime(char* trace_message, |
| 75 | const TraceLevel level) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 77 | virtual WebRtc_Word32 AddBuildInfo(char* trace_message) const = 0; |
| 78 | virtual WebRtc_Word32 AddDateTimeInfo(char* trace_message) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 80 | static bool Run(void* obj); |
| 81 | bool Process(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 83 | private: |
| 84 | friend class Trace; |
henrike@webrtc.org | 315282c | 2011-12-09 17:46:20 +0000 | [diff] [blame] | 85 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 86 | WebRtc_Word32 AddLevel(char* sz_message, const TraceLevel level) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 88 | WebRtc_Word32 AddModuleAndId(char* trace_message, const TraceModule module, |
| 89 | const WebRtc_Word32 id) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 91 | WebRtc_Word32 AddMessage(char* trace_message, |
| 92 | const char msg[WEBRTC_TRACE_MAX_MESSAGE_SIZE], |
| 93 | const WebRtc_UWord16 written_so_far) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 95 | void AddMessageToList( |
| 96 | const char trace_message[WEBRTC_TRACE_MAX_MESSAGE_SIZE], |
| 97 | const WebRtc_UWord16 length, |
| 98 | const TraceLevel level); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 100 | bool UpdateFileName( |
| 101 | const char file_name_utf8[FileWrapper::kMaxFileNameSize], |
| 102 | char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize], |
| 103 | const WebRtc_UWord32 new_count) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 105 | bool CreateFileName( |
| 106 | const char file_name_utf8[FileWrapper::kMaxFileNameSize], |
| 107 | char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize], |
| 108 | const WebRtc_UWord32 new_count) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 110 | void WriteToFile(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 112 | CriticalSectionWrapper* critsect_interface_; |
| 113 | TraceCallback* callback_; |
| 114 | WebRtc_UWord32 row_count_text_; |
| 115 | WebRtc_UWord32 file_count_text_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 117 | FileWrapper& trace_file_; |
| 118 | ThreadWrapper& thread_; |
| 119 | EventWrapper& event_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 121 | // critsect_array_ protects active_queue_. |
| 122 | CriticalSectionWrapper* critsect_array_; |
| 123 | WebRtc_UWord16 next_free_idx_[WEBRTC_TRACE_NUM_ARRAY]; |
| 124 | TraceLevel level_[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE]; |
| 125 | WebRtc_UWord16 length_[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE]; |
| 126 | char* message_queue_[WEBRTC_TRACE_NUM_ARRAY][WEBRTC_TRACE_MAX_QUEUE]; |
| 127 | WebRtc_UWord8 active_queue_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame^] | 130 | } // namespace webrtc |
| 131 | |
| 132 | #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_ |