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 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame^] | 14 | #include <memory> |
| 15 | |
pbos@webrtc.org | 4b3618c | 2015-02-27 15:05:03 +0000 | [diff] [blame] | 16 | #include "webrtc/base/criticalsection.h" |
| 17 | #include "webrtc/base/scoped_ptr.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 18 | #include "webrtc/system_wrappers/include/event_wrapper.h" |
| 19 | #include "webrtc/system_wrappers/include/file_wrapper.h" |
| 20 | #include "webrtc/system_wrappers/include/static_instance.h" |
pbos | 12411ef | 2015-11-23 14:47:56 -0800 | [diff] [blame] | 21 | #include "webrtc/base/platform_thread.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 22 | #include "webrtc/system_wrappers/include/trace.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
pbos@webrtc.org | 9fed099 | 2014-10-27 09:31:05 +0000 | [diff] [blame] | 26 | #define WEBRTC_TRACE_MAX_MESSAGE_SIZE 1024 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | // Total buffer size is WEBRTC_TRACE_NUM_ARRAY (number of buffer partitions) * |
| 28 | // WEBRTC_TRACE_MAX_QUEUE (number of lines per buffer partition) * |
| 29 | // 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] | 30 | // 1 or 4 Mbyte. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | |
| 32 | #define WEBRTC_TRACE_MAX_FILE_SIZE 100*1000 |
| 33 | // Number of rows that may be written to file. On average 110 bytes per row (max |
| 34 | // 256 bytes per row). So on average 110*100*1000 = 11 Mbyte, max 256*100*1000 = |
| 35 | // 25.6 Mbyte |
| 36 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 37 | class TraceImpl : public Trace { |
| 38 | public: |
| 39 | virtual ~TraceImpl(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 41 | static TraceImpl* CreateInstance(); |
| 42 | static TraceImpl* GetTrace(const TraceLevel level = kTraceAll); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 44 | int32_t SetTraceFileImpl(const char* file_name, const bool add_file_counter); |
| 45 | int32_t TraceFileImpl(char file_name[FileWrapper::kMaxFileNameSize]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 47 | int32_t SetTraceCallbackImpl(TraceCallback* callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 49 | void AddImpl(const TraceLevel level, const TraceModule module, |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 50 | const int32_t id, const char* msg); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 52 | bool TraceCheck(const TraceLevel level) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 54 | protected: |
| 55 | TraceImpl(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 57 | static TraceImpl* StaticInstance(CountOperation count_operation, |
| 58 | const TraceLevel level = kTraceAll); |
henrike@webrtc.org | 315282c | 2011-12-09 17:46:20 +0000 | [diff] [blame] | 59 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 60 | int32_t AddThreadId(char* trace_message) const; |
pwestin@webrtc.org | b54d727 | 2012-01-11 08:28:04 +0000 | [diff] [blame] | 61 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 62 | // OS specific implementations. |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 63 | virtual int32_t AddTime(char* trace_message, |
| 64 | const TraceLevel level) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 66 | virtual int32_t AddDateTimeInfo(char* trace_message) const = 0; |
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 | private: |
| 69 | friend class Trace; |
henrike@webrtc.org | 315282c | 2011-12-09 17:46:20 +0000 | [diff] [blame] | 70 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 71 | int32_t AddLevel(char* sz_message, const TraceLevel level) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 73 | int32_t AddModuleAndId(char* trace_message, const TraceModule module, |
| 74 | const int32_t id) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 76 | int32_t AddMessage(char* trace_message, |
| 77 | const char msg[WEBRTC_TRACE_MAX_MESSAGE_SIZE], |
| 78 | const uint16_t written_so_far) const; |
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 | void AddMessageToList( |
| 81 | const char trace_message[WEBRTC_TRACE_MAX_MESSAGE_SIZE], |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 82 | const uint16_t length, |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 83 | const TraceLevel level); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 85 | bool UpdateFileName( |
| 86 | const char file_name_utf8[FileWrapper::kMaxFileNameSize], |
| 87 | char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize], |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 88 | const uint32_t new_count) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 90 | bool CreateFileName( |
| 91 | const char file_name_utf8[FileWrapper::kMaxFileNameSize], |
| 92 | char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize], |
pbos@webrtc.org | 046deb9 | 2013-04-09 09:06:11 +0000 | [diff] [blame] | 93 | const uint32_t new_count) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | |
pbos@webrtc.org | 4b3618c | 2015-02-27 15:05:03 +0000 | [diff] [blame] | 95 | void WriteToFile(const char* msg, uint16_t length) |
| 96 | EXCLUSIVE_LOCKS_REQUIRED(crit_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | |
pbos@webrtc.org | 4b3618c | 2015-02-27 15:05:03 +0000 | [diff] [blame] | 98 | TraceCallback* callback_ GUARDED_BY(crit_); |
| 99 | uint32_t row_count_text_ GUARDED_BY(crit_); |
| 100 | uint32_t file_count_text_ GUARDED_BY(crit_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame^] | 102 | const std::unique_ptr<FileWrapper> trace_file_ GUARDED_BY(crit_); |
tommi@webrtc.org | d312505 | 2015-02-28 00:01:11 +0000 | [diff] [blame] | 103 | rtc::CriticalSection crit_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | |
phoglund@webrtc.org | daabfd2 | 2013-01-03 09:37:03 +0000 | [diff] [blame] | 106 | } // namespace webrtc |
| 107 | |
| 108 | #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_ |