diff options
author | Fredrik Solenberg <solenberg@webrtc.org> | 2017-10-03 13:41:33 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2017-10-03 13:20:48 +0000 |
commit | 2209b90449473e1df3e0797b6271c7624b41907d (patch) | |
tree | a75c45bb6e4ec51c591c9297964b0480e7b38e15 /system_wrappers | |
parent | f4898a650954691d79bbc146d5b454fb5e67ec47 (diff) | |
download | webrtc-2209b90449473e1df3e0797b6271c7624b41907d.tar.gz |
Remove WEBRTC_TRACE.
Bug: webrtc:5118
Change-Id: I0af0f8845ee016fa61d7cecc526e2a672ec8732d
Reviewed-on: https://webrtc-review.googlesource.com/5382
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20114}
Diffstat (limited to 'system_wrappers')
-rw-r--r-- | system_wrappers/BUILD.gn | 12 | ||||
-rw-r--r-- | system_wrappers/include/logcat_trace_context.h | 35 | ||||
-rw-r--r-- | system_wrappers/include/trace.h | 89 | ||||
-rw-r--r-- | system_wrappers/source/logcat_trace_context.cc | 63 | ||||
-rw-r--r-- | system_wrappers/source/trace_impl.cc | 583 | ||||
-rw-r--r-- | system_wrappers/source/trace_impl.h | 105 | ||||
-rw-r--r-- | system_wrappers/source/trace_posix.cc | 85 | ||||
-rw-r--r-- | system_wrappers/source/trace_posix.h | 39 | ||||
-rw-r--r-- | system_wrappers/source/trace_win.cc | 97 | ||||
-rw-r--r-- | system_wrappers/source/trace_win.h | 36 |
10 files changed, 0 insertions, 1144 deletions
diff --git a/system_wrappers/BUILD.gn b/system_wrappers/BUILD.gn index 29ee8b87de..30ebc4742b 100644 --- a/system_wrappers/BUILD.gn +++ b/system_wrappers/BUILD.gn @@ -28,7 +28,6 @@ rtc_static_library("system_wrappers") { "include/sleep.h", "include/static_instance.h", "include/timestamp_extrapolator.h", - "include/trace.h", "source/aligned_malloc.cc", "source/atomic32_win.cc", "source/clock.cc", @@ -48,12 +47,6 @@ rtc_static_library("system_wrappers") { "source/rw_lock_win.h", "source/sleep.cc", "source/timestamp_extrapolator.cc", - "source/trace_impl.cc", - "source/trace_impl.h", - "source/trace_posix.cc", - "source/trace_posix.h", - "source/trace_win.cc", - "source/trace_win.h", ] defines = [] @@ -68,11 +61,6 @@ rtc_static_library("system_wrappers") { ] if (is_android) { - sources += [ - "include/logcat_trace_context.h", - "source/logcat_trace_context.cc", - ] - defines += [ "WEBRTC_THREAD_RR" ] deps += [ ":cpu_features_android" ] diff --git a/system_wrappers/include/logcat_trace_context.h b/system_wrappers/include/logcat_trace_context.h deleted file mode 100644 index 8eb688dc8b..0000000000 --- a/system_wrappers/include/logcat_trace_context.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * 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 SYSTEM_WRAPPERS_INCLUDE_LOGCAT_TRACE_CONTEXT_H_ -#define SYSTEM_WRAPPERS_INCLUDE_LOGCAT_TRACE_CONTEXT_H_ - -#include "system_wrappers/include/trace.h" - -#ifndef ANDROID -#error This file only makes sense to include on Android! -#endif - -namespace webrtc { - -// Scoped helper class for directing Traces to Android's logcat facility. While -// this object lives, Trace output will be sent to logcat. -class LogcatTraceContext : public webrtc::TraceCallback { - public: - LogcatTraceContext(); - ~LogcatTraceContext() override; - - // TraceCallback impl. - void Print(TraceLevel level, const char* message, int length) override; -}; - -} // namespace webrtc - -#endif // SYSTEM_WRAPPERS_INCLUDE_LOGCAT_TRACE_CONTEXT_H_ diff --git a/system_wrappers/include/trace.h b/system_wrappers/include/trace.h deleted file mode 100644 index e498a52537..0000000000 --- a/system_wrappers/include/trace.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * 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. - * - * 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 SYSTEM_WRAPPERS_INCLUDE_TRACE_H_ -#define SYSTEM_WRAPPERS_INCLUDE_TRACE_H_ - -#include "common_types.h" // NOLINT(build/include) -#include "typedefs.h" // NOLINT(build/include) - -namespace webrtc { - -#if defined(WEBRTC_RESTRICT_LOGGING) -// Disable all TRACE macros. The LOG macro is still functional. -#define WEBRTC_TRACE true ? (void) 0 : Trace::Add -#else -#define WEBRTC_TRACE Trace::Add -#endif - -class Trace { - public: - // The length of the trace text preceeding the log message. - static const int kBoilerplateLength; - // The position of the timestamp text within a trace. - static const int kTimestampPosition; - // The length of the timestamp (without "delta" field). - static const int kTimestampLength; - - // 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 void set_level_filter(int filter); - - // Returns what type of messages are written to the trace file. - static int level_filter(); - - // 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 int32_t SetTraceFile(const char* file_name, - const bool add_file_counter = false); - - // Registers callback to receive trace messages. - // TODO(hellner): Why not use OutStream instead? Why is TraceCallback not - // defined in this file? - static int32_t 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 int32_t id, - const char* msg, ...); - - private: - static volatile int level_filter_; -}; - -} // namespace webrtc - -#endif // SYSTEM_WRAPPERS_INCLUDE_TRACE_H_ diff --git a/system_wrappers/source/logcat_trace_context.cc b/system_wrappers/source/logcat_trace_context.cc deleted file mode 100644 index cb43dddd5b..0000000000 --- a/system_wrappers/source/logcat_trace_context.cc +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * 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. - */ - -#include "system_wrappers/include/logcat_trace_context.h" - -#include <android/log.h> -#include <assert.h> - -#include "rtc_base/logging.h" - -namespace webrtc { - -static android_LogPriority AndroidLogPriorityFromWebRtcLogLevel( - TraceLevel webrtc_level) { - // NOTE: this mapping is somewhat arbitrary. StateInfo and Info are mapped - // to DEBUG because they are highly verbose in webrtc code (which is - // unfortunate). - switch (webrtc_level) { - case webrtc::kTraceStateInfo: return ANDROID_LOG_DEBUG; - case webrtc::kTraceWarning: return ANDROID_LOG_WARN; - case webrtc::kTraceError: return ANDROID_LOG_ERROR; - case webrtc::kTraceCritical: return ANDROID_LOG_FATAL; - case webrtc::kTraceApiCall: return ANDROID_LOG_VERBOSE; - case webrtc::kTraceModuleCall: return ANDROID_LOG_VERBOSE; - case webrtc::kTraceMemory: return ANDROID_LOG_VERBOSE; - case webrtc::kTraceTimer: return ANDROID_LOG_VERBOSE; - case webrtc::kTraceStream: return ANDROID_LOG_VERBOSE; - case webrtc::kTraceDebug: return ANDROID_LOG_DEBUG; - case webrtc::kTraceInfo: return ANDROID_LOG_DEBUG; - case webrtc::kTraceTerseInfo: return ANDROID_LOG_INFO; - default: - LOG(LS_ERROR) << "Unexpected log level" << webrtc_level; - return ANDROID_LOG_FATAL; - } -} - -LogcatTraceContext::LogcatTraceContext() { - webrtc::Trace::CreateTrace(); - if (webrtc::Trace::SetTraceCallback(this) != 0) - assert(false); -} - -LogcatTraceContext::~LogcatTraceContext() { - if (webrtc::Trace::SetTraceCallback(NULL) != 0) - assert(false); - webrtc::Trace::ReturnTrace(); -} - -void LogcatTraceContext::Print(TraceLevel level, - const char* message, - int length) { - __android_log_print(AndroidLogPriorityFromWebRtcLogLevel(level), - "WEBRTC", "%.*s", length, message); -} - -} // namespace webrtc diff --git a/system_wrappers/source/trace_impl.cc b/system_wrappers/source/trace_impl.cc deleted file mode 100644 index c1ec984f6d..0000000000 --- a/system_wrappers/source/trace_impl.cc +++ /dev/null @@ -1,583 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * 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. - */ - -#include "system_wrappers/source/trace_impl.h" - -#include <assert.h> -#include <stdarg.h> -#include <stdio.h> -#include <string.h> - -#include "rtc_base/atomicops.h" -#include "rtc_base/platform_thread.h" -#ifdef _WIN32 -#include "system_wrappers/source/trace_win.h" -#else -#include "system_wrappers/source/trace_posix.h" -#endif // _WIN32 - -#define KEY_LEN_CHARS 31 - -#ifdef _WIN32 -#pragma warning(disable:4355) -#endif // _WIN32 - -namespace webrtc { - -const int Trace::kBoilerplateLength = 71; -const int Trace::kTimestampPosition = 13; -const int Trace::kTimestampLength = 12; -volatile int Trace::level_filter_ = kTraceDefault; - -// Construct On First Use idiom. Avoids "static initialization order fiasco". -TraceImpl* TraceImpl::StaticInstance(CountOperation count_operation, - const TraceLevel level) { - // Sanities to avoid taking lock unless absolutely necessary (for - // performance reasons). count_operation == kAddRefNoCreate implies that a - // message will be written to file. - if ((level != kTraceAll) && (count_operation == kAddRefNoCreate)) { - if (!(level & level_filter())) { - return NULL; - } - } - TraceImpl* impl = - GetStaticInstance<TraceImpl>(count_operation); - return impl; -} - -TraceImpl* TraceImpl::GetTrace(const TraceLevel level) { - return StaticInstance(kAddRefNoCreate, level); -} - -TraceImpl* TraceImpl::CreateInstance() { -#if defined(_WIN32) - return new TraceWindows(); -#else - return new TracePosix(); -#endif -} - -TraceImpl::TraceImpl() - : callback_(NULL), - row_count_text_(0), - file_count_text_(0), - trace_file_(FileWrapper::Create()) { -} - -TraceImpl::~TraceImpl() { - trace_file_->CloseFile(); -} - -int32_t TraceImpl::AddThreadId(char* trace_message) const { - uint32_t thread_id = rtc::CurrentThreadId(); - // Messages is 12 characters. - return sprintf(trace_message, "%10u; ", thread_id); -} - -int32_t TraceImpl::AddLevel(char* sz_message, const TraceLevel level) const { - const int kMessageLength = 12; - switch (level) { - case kTraceTerseInfo: - // Add the appropriate amount of whitespace. - memset(sz_message, ' ', kMessageLength); - sz_message[kMessageLength] = '\0'; - break; - case kTraceStateInfo: - sprintf(sz_message, "STATEINFO ; "); - break; - case kTraceWarning: - sprintf(sz_message, "WARNING ; "); - break; - case kTraceError: - sprintf(sz_message, "ERROR ; "); - break; - case kTraceCritical: - sprintf(sz_message, "CRITICAL ; "); - break; - case kTraceInfo: - sprintf(sz_message, "DEBUGINFO ; "); - break; - case kTraceModuleCall: - sprintf(sz_message, "MODULECALL; "); - break; - case kTraceMemory: - sprintf(sz_message, "MEMORY ; "); - break; - case kTraceTimer: - sprintf(sz_message, "TIMER ; "); - break; - case kTraceStream: - sprintf(sz_message, "STREAM ; "); - break; - case kTraceApiCall: - sprintf(sz_message, "APICALL ; "); - break; - case kTraceDebug: - sprintf(sz_message, "DEBUG ; "); - break; - default: - assert(false); - return 0; - } - // All messages are 12 characters. - return kMessageLength; -} - -int32_t TraceImpl::AddModuleAndId(char* trace_message, - const TraceModule module, - const int32_t id) const { - // Use long int to prevent problems with different definitions of - // int32_t. - // TODO(hellner): is this actually a problem? If so, it should be better to - // clean up int32_t - const long int idl = id; - const int kMessageLength = 25; - if (idl != -1) { - const unsigned long int id_engine = id >> 16; - const unsigned long int id_channel = id & 0xffff; - - switch (module) { - case kTraceUndefined: - // Add the appropriate amount of whitespace. - memset(trace_message, ' ', kMessageLength); - trace_message[kMessageLength] = '\0'; - break; - case kTraceVoice: - sprintf(trace_message, " VOICE:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceVideo: - sprintf(trace_message, " VIDEO:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceUtility: - sprintf(trace_message, " UTILITY:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceRtpRtcp: - sprintf(trace_message, " RTP/RTCP:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceTransport: - sprintf(trace_message, " TRANSPORT:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceAudioCoding: - sprintf(trace_message, "AUDIO CODING:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceSrtp: - sprintf(trace_message, " SRTP:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceAudioMixerServer: - sprintf(trace_message, " AUDIO MIX/S:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceAudioMixerClient: - sprintf(trace_message, " AUDIO MIX/C:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceVideoCoding: - sprintf(trace_message, "VIDEO CODING:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceVideoMixer: - // Print sleep time and API call - sprintf(trace_message, " VIDEO MIX:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceFile: - sprintf(trace_message, " FILE:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceAudioProcessing: - sprintf(trace_message, " AUDIO PROC:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceAudioDevice: - sprintf(trace_message, "AUDIO DEVICE:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceVideoRenderer: - sprintf(trace_message, "VIDEO RENDER:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceVideoCapture: - sprintf(trace_message, "VIDEO CAPTUR:%5ld %5ld;", id_engine, - id_channel); - break; - case kTraceRemoteBitrateEstimator: - sprintf(trace_message, " BWE RBE:%5ld %5ld;", id_engine, - id_channel); - break; - } - } else { - switch (module) { - case kTraceUndefined: - // Add the appropriate amount of whitespace. - memset(trace_message, ' ', kMessageLength); - trace_message[kMessageLength] = '\0'; - break; - case kTraceVoice: - sprintf(trace_message, " VOICE:%11ld;", idl); - break; - case kTraceVideo: - sprintf(trace_message, " VIDEO:%11ld;", idl); - break; - case kTraceUtility: - sprintf(trace_message, " UTILITY:%11ld;", idl); - break; - case kTraceRtpRtcp: - sprintf(trace_message, " RTP/RTCP:%11ld;", idl); - break; - case kTraceTransport: - sprintf(trace_message, " TRANSPORT:%11ld;", idl); - break; - case kTraceAudioCoding: - sprintf(trace_message, "AUDIO CODING:%11ld;", idl); - break; - case kTraceSrtp: - sprintf(trace_message, " SRTP:%11ld;", idl); - break; - case kTraceAudioMixerServer: - sprintf(trace_message, " AUDIO MIX/S:%11ld;", idl); - break; - case kTraceAudioMixerClient: - sprintf(trace_message, " AUDIO MIX/C:%11ld;", idl); - break; - case kTraceVideoCoding: - sprintf(trace_message, "VIDEO CODING:%11ld;", idl); - break; - case kTraceVideoMixer: - sprintf(trace_message, " VIDEO MIX:%11ld;", idl); - break; - case kTraceFile: - sprintf(trace_message, " FILE:%11ld;", idl); - break; - case kTraceAudioProcessing: - sprintf(trace_message, " AUDIO PROC:%11ld;", idl); - break; - case kTraceAudioDevice: - sprintf(trace_message, "AUDIO DEVICE:%11ld;", idl); - break; - case kTraceVideoRenderer: - sprintf(trace_message, "VIDEO RENDER:%11ld;", idl); - break; - case kTraceVideoCapture: - sprintf(trace_message, "VIDEO CAPTUR:%11ld;", idl); - break; - case kTraceRemoteBitrateEstimator: - sprintf(trace_message, " BWE RBE:%11ld;", idl); - break; - } - } - return kMessageLength; -} - -int32_t TraceImpl::SetTraceFileImpl(const char* file_name_utf8, - const bool add_file_counter) { - rtc::CritScope lock(&crit_); - - trace_file_->CloseFile(); - trace_file_path_.clear(); - - if (file_name_utf8) { - if (add_file_counter) { - file_count_text_ = 1; - - char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize]; - CreateFileName(file_name_utf8, file_name_with_counter_utf8, - file_count_text_); - if (!trace_file_->OpenFile(file_name_with_counter_utf8, false)) { - return -1; - } - trace_file_path_ = file_name_with_counter_utf8; - } else { - file_count_text_ = 0; - if (!trace_file_->OpenFile(file_name_utf8, false)) { - return -1; - } - trace_file_path_ = file_name_utf8; - } - } - row_count_text_ = 0; - return 0; -} - -int32_t TraceImpl::SetTraceCallbackImpl(TraceCallback* callback) { - rtc::CritScope lock(&crit_); - callback_ = callback; - return 0; -} - -int32_t TraceImpl::AddMessage( - char* trace_message, - const char msg[WEBRTC_TRACE_MAX_MESSAGE_SIZE], - const uint16_t written_so_far) const { - int length = 0; - if (written_so_far >= WEBRTC_TRACE_MAX_MESSAGE_SIZE) { - return -1; - } - // - 2 to leave room for newline and NULL termination. -#ifdef _WIN32 - length = _snprintf(trace_message, - WEBRTC_TRACE_MAX_MESSAGE_SIZE - written_so_far - 2, - "%s", msg); - if (length < 0) { - length = WEBRTC_TRACE_MAX_MESSAGE_SIZE - written_so_far - 2; - trace_message[length] = 0; - } -#else - length = snprintf(trace_message, - WEBRTC_TRACE_MAX_MESSAGE_SIZE - written_so_far - 2, - "%s", msg); - if (length < 0 || - length > WEBRTC_TRACE_MAX_MESSAGE_SIZE - written_so_far - 2) { - length = WEBRTC_TRACE_MAX_MESSAGE_SIZE - written_so_far - 2; - trace_message[length] = 0; - } -#endif - // Length with NULL termination. - return length + 1; -} - -void TraceImpl::AddMessageToList( - const char trace_message[WEBRTC_TRACE_MAX_MESSAGE_SIZE], - const uint16_t length, - const TraceLevel level) { - rtc::CritScope lock(&crit_); - if (callback_) - callback_->Print(level, trace_message, length); - WriteToFile(trace_message, length); -} - -void TraceImpl::WriteToFile(const char* msg, uint16_t length) { - if (!trace_file_->is_open()) - return; - - if (row_count_text_ > WEBRTC_TRACE_MAX_FILE_SIZE) { - // wrap file - row_count_text_ = 0; - trace_file_->Flush(); - - if (file_count_text_ == 0) { - trace_file_->Rewind(); - } else { - char new_file_name[FileWrapper::kMaxFileNameSize]; - - // get current name - file_count_text_++; - UpdateFileName(new_file_name, file_count_text_); - - trace_file_->CloseFile(); - trace_file_path_.clear(); - - if (!trace_file_->OpenFile(new_file_name, false)) { - return; - } - trace_file_path_ = new_file_name; - } - } - if (row_count_text_ == 0) { - char message[WEBRTC_TRACE_MAX_MESSAGE_SIZE + 1]; - int32_t length = AddDateTimeInfo(message); - if (length != -1) { - message[length] = 0; - message[length - 1] = '\n'; - trace_file_->Write(message, length); - row_count_text_++; - } - } - - char trace_message[WEBRTC_TRACE_MAX_MESSAGE_SIZE]; - memcpy(trace_message, msg, length); - trace_message[length] = 0; - trace_message[length - 1] = '\n'; - trace_file_->Write(trace_message, length); - row_count_text_++; -} - -void TraceImpl::AddImpl(const TraceLevel level, - const TraceModule module, - const int32_t id, - const char msg[WEBRTC_TRACE_MAX_MESSAGE_SIZE]) { - if (!TraceCheck(level)) - return; - - char trace_message[WEBRTC_TRACE_MAX_MESSAGE_SIZE]; - char* message_ptr = &trace_message[0]; - int32_t len = AddLevel(message_ptr, level); - if (len == -1) - return; - - message_ptr += len; - int32_t ack_len = len; - - len = AddTime(message_ptr, level); - if (len == -1) - return; - - message_ptr += len; - ack_len += len; - - len = AddModuleAndId(message_ptr, module, id); - if (len == -1) - return; - - message_ptr += len; - ack_len += len; - - len = AddThreadId(message_ptr); - if (len < 0) - return; - - message_ptr += len; - ack_len += len; - - len = AddMessage(message_ptr, msg, static_cast<uint16_t>(ack_len)); - if (len == -1) - return; - - ack_len += len; - AddMessageToList(trace_message, static_cast<uint16_t>(ack_len), level); -} - -bool TraceImpl::TraceCheck(const TraceLevel level) const { - return (level & level_filter()) ? true : false; -} - -bool TraceImpl::UpdateFileName( - char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize], - const uint32_t new_count) const { - int32_t length = static_cast<int32_t>(trace_file_path_.length()); - - int32_t length_without_file_ending = length - 1; - while (length_without_file_ending > 0) { - if (trace_file_path_[length_without_file_ending] == '.') { - break; - } else { - length_without_file_ending--; - } - } - if (length_without_file_ending == 0) { - length_without_file_ending = length; - } - int32_t length_to_ = length_without_file_ending - 1; - while (length_to_ > 0) { - if (trace_file_path_[length_to_] == '_') { - break; - } else { - length_to_--; - } - } - - memcpy(file_name_with_counter_utf8, &trace_file_path_[0], length_to_); - sprintf(file_name_with_counter_utf8 + length_to_, "_%lu%s", - static_cast<long unsigned int>(new_count), - &trace_file_path_[length_without_file_ending]); - return true; -} - -bool TraceImpl::CreateFileName( - const char file_name_utf8[FileWrapper::kMaxFileNameSize], - char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize], - const uint32_t new_count) const { - int32_t length = (int32_t)strlen(file_name_utf8); - if (length < 0) { - return false; - } - - int32_t length_without_file_ending = length - 1; - while (length_without_file_ending > 0) { - if (file_name_utf8[length_without_file_ending] == '.') { - break; - } else { - length_without_file_ending--; - } - } - if (length_without_file_ending == 0) { - length_without_file_ending = length; - } - memcpy(file_name_with_counter_utf8, file_name_utf8, - length_without_file_ending); - sprintf(file_name_with_counter_utf8 + length_without_file_ending, "_%lu%s", - static_cast<long unsigned int>(new_count), - file_name_utf8 + length_without_file_ending); - return true; -} - -// static -void Trace::CreateTrace() { - TraceImpl::StaticInstance(kAddRef); -} - -// static -void Trace::ReturnTrace() { - TraceImpl::StaticInstance(kRelease); -} - -// static -void Trace::set_level_filter(int filter) { - rtc::AtomicOps::ReleaseStore(&level_filter_, filter); -} - -// static -int Trace::level_filter() { - return rtc::AtomicOps::AcquireLoad(&level_filter_); -} - -// static -int32_t Trace::SetTraceFile(const char* file_name, - const bool add_file_counter) { - TraceImpl* trace = TraceImpl::GetTrace(); - if (trace) { - int ret_val = trace->SetTraceFileImpl(file_name, add_file_counter); - ReturnTrace(); - return ret_val; - } - return -1; -} - -int32_t Trace::SetTraceCallback(TraceCallback* callback) { - TraceImpl* trace = TraceImpl::GetTrace(); - if (trace) { - int ret_val = trace->SetTraceCallbackImpl(callback); - ReturnTrace(); - return ret_val; - } - return -1; -} - -void Trace::Add(const TraceLevel level, const TraceModule module, - const int32_t id, const char* msg, ...) { - TraceImpl* trace = TraceImpl::GetTrace(level); - if (trace) { - if (trace->TraceCheck(level)) { - char temp_buff[WEBRTC_TRACE_MAX_MESSAGE_SIZE]; - char* buff = 0; - if (msg) { - va_list args; - va_start(args, msg); -#ifdef _WIN32 - _vsnprintf(temp_buff, WEBRTC_TRACE_MAX_MESSAGE_SIZE - 1, msg, args); -#else - vsnprintf(temp_buff, WEBRTC_TRACE_MAX_MESSAGE_SIZE - 1, msg, args); -#endif - va_end(args); - buff = temp_buff; - } - trace->AddImpl(level, module, id, buff); - } - ReturnTrace(); - } -} - -} // namespace webrtc diff --git a/system_wrappers/source/trace_impl.h b/system_wrappers/source/trace_impl.h deleted file mode 100644 index 3e730f6818..0000000000 --- a/system_wrappers/source/trace_impl.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * 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 SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_ -#define SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_ - -#include <memory> - -#include "rtc_base/criticalsection.h" -#include "rtc_base/platform_thread.h" -#include "system_wrappers/include/event_wrapper.h" -#include "system_wrappers/include/file_wrapper.h" -#include "system_wrappers/include/static_instance.h" -#include "system_wrappers/include/trace.h" - -namespace webrtc { - -#define WEBRTC_TRACE_MAX_MESSAGE_SIZE 1024 -// 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. - -#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(); - - static TraceImpl* CreateInstance(); - static TraceImpl* GetTrace(const TraceLevel level = kTraceAll); - - int32_t SetTraceFileImpl(const char* file_name, const bool add_file_counter); - int32_t SetTraceCallbackImpl(TraceCallback* callback); - - void AddImpl(const TraceLevel level, const TraceModule module, - const int32_t id, const char* msg); - - bool TraceCheck(const TraceLevel level) const; - - protected: - TraceImpl(); - - static TraceImpl* StaticInstance(CountOperation count_operation, - const TraceLevel level = kTraceAll); - - int32_t AddThreadId(char* trace_message) const; - - // OS specific implementations. - virtual int32_t AddTime(char* trace_message, - const TraceLevel level) const = 0; - - virtual int32_t AddDateTimeInfo(char* trace_message) const = 0; - - private: - friend class Trace; - - int32_t AddLevel(char* sz_message, const TraceLevel level) const; - - int32_t AddModuleAndId(char* trace_message, const TraceModule module, - const int32_t id) const; - - int32_t AddMessage(char* trace_message, - const char msg[WEBRTC_TRACE_MAX_MESSAGE_SIZE], - const uint16_t written_so_far) const; - - void AddMessageToList( - const char trace_message[WEBRTC_TRACE_MAX_MESSAGE_SIZE], - const uint16_t length, - const TraceLevel level); - - bool UpdateFileName( - char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize], - const uint32_t new_count) const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); - - bool CreateFileName( - const char file_name_utf8[FileWrapper::kMaxFileNameSize], - char file_name_with_counter_utf8[FileWrapper::kMaxFileNameSize], - const uint32_t new_count) const; - - void WriteToFile(const char* msg, uint16_t length) - RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); - - TraceCallback* callback_ RTC_GUARDED_BY(crit_); - uint32_t row_count_text_ RTC_GUARDED_BY(crit_); - uint32_t file_count_text_ RTC_GUARDED_BY(crit_); - - const std::unique_ptr<FileWrapper> trace_file_ RTC_GUARDED_BY(crit_); - std::string trace_file_path_ RTC_GUARDED_BY(crit_); - rtc::CriticalSection crit_; -}; - -} // namespace webrtc - -#endif // SYSTEM_WRAPPERS_SOURCE_TRACE_IMPL_H_ diff --git a/system_wrappers/source/trace_posix.cc b/system_wrappers/source/trace_posix.cc deleted file mode 100644 index a01733325e..0000000000 --- a/system_wrappers/source/trace_posix.cc +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * 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. - */ - -#include "system_wrappers/source/trace_posix.h" - -#include <assert.h> -#include <stdarg.h> -#include <stdio.h> -#include <string.h> -#include <sys/time.h> -#include <time.h> - -namespace webrtc { - -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; -} - -int32_t 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 uint32_t ms_time = system_time_high_res.tv_usec / 1000; - uint32_t prev_tickCount = 0; - { - rtc::CritScope lock(&crit_sect_); - 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; - } - } - - uint32_t 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(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; -} - -int32_t 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)); - int32_t len = static_cast<int32_t>(strlen(trace_message)); - - if ('\n' == trace_message[len - 1]) { - trace_message[len - 1] = '\0'; - --len; - } - - // Messages is 12 characters. - return len + 1; -} - -} // namespace webrtc diff --git a/system_wrappers/source/trace_posix.h b/system_wrappers/source/trace_posix.h deleted file mode 100644 index 357d226a3c..0000000000 --- a/system_wrappers/source/trace_posix.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * 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 SYSTEM_WRAPPERS_SOURCE_TRACE_POSIX_H_ -#define SYSTEM_WRAPPERS_SOURCE_TRACE_POSIX_H_ - -#include "rtc_base/criticalsection.h" -#include "system_wrappers/source/trace_impl.h" - -namespace webrtc { - -class TracePosix : public TraceImpl { - public: - TracePosix(); - ~TracePosix() override = default; - - // This method can be called on several different threads different from - // the creating thread. - int32_t AddTime(char* trace_message, const TraceLevel level) const override; - - int32_t AddDateTimeInfo(char* trace_message) const override; - - private: - volatile mutable uint32_t prev_api_tick_count_; - volatile mutable uint32_t prev_tick_count_; - - rtc::CriticalSection crit_sect_; -}; - -} // namespace webrtc - -#endif // SYSTEM_WRAPPERS_SOURCE_TRACE_POSIX_H_ diff --git a/system_wrappers/source/trace_win.cc b/system_wrappers/source/trace_win.cc deleted file mode 100644 index 2becb78291..0000000000 --- a/system_wrappers/source/trace_win.cc +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * 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. - */ - -#include "system_wrappers/source/trace_win.h" - -#include <assert.h> -#include <stdarg.h> - -#include "Mmsystem.h" - -namespace webrtc { -TraceWindows::TraceWindows() - : prev_api_tick_count_(0), - prev_tick_count_(0) { -} - -TraceWindows::~TraceWindows() { -} - -int32_t TraceWindows::AddTime(char* trace_message, - const TraceLevel level) const { - uint32_t dw_current_time = timeGetTime(); - SYSTEMTIME system_time; - GetSystemTime(&system_time); - - if (level == kTraceApiCall) { - uint32_t dw_delta_time = dw_current_time - prev_tick_count_; - prev_tick_count_ = dw_current_time; - - if (prev_tick_count_ == 0) { - dw_delta_time = 0; - } - 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 |%5u) ", system_time.wHour, - system_time.wMinute, system_time.wSecond, - system_time.wMilliseconds, dw_delta_time); - } else { - uint32_t 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 |%5u) ", system_time.wHour, - system_time.wMinute, system_time.wSecond, - system_time.wMilliseconds, dw_delta_time); - } - return 22; -} - -int32_t TraceWindows::AddDateTimeInfo(char* trace_message) const { - prev_api_tick_count_ = timeGetTime(); - prev_tick_count_ = prev_api_tick_count_; - - SYSTEMTIME sys_time; - GetLocalTime(&sys_time); - - TCHAR sz_date_str[20]; - TCHAR sz_time_str[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, &sys_time, TEXT("HH':'mm':'ss"), - sz_time_str, 20); - - sprintf(trace_message, "Local Date: %ls Local Time: %ls", sz_date_str, - sz_time_str); - - // Include NULL termination (hence + 1). - return static_cast<int32_t>(strlen(trace_message) + 1); -} - -} // namespace webrtc diff --git a/system_wrappers/source/trace_win.h b/system_wrappers/source/trace_win.h deleted file mode 100644 index b1a41f296b..0000000000 --- a/system_wrappers/source/trace_win.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * 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 SYSTEM_WRAPPERS_SOURCE_TRACE_WIN_H_ -#define SYSTEM_WRAPPERS_SOURCE_TRACE_WIN_H_ - -#include <stdio.h> -#include <windows.h> - -#include "system_wrappers/source/trace_impl.h" - -namespace webrtc { - -class TraceWindows : public TraceImpl { - public: - TraceWindows(); - virtual ~TraceWindows(); - - virtual int32_t AddTime(char* trace_message, const TraceLevel level) const; - - virtual int32_t AddDateTimeInfo(char* trace_message) const; - private: - volatile mutable uint32_t prev_api_tick_count_; - volatile mutable uint32_t prev_tick_count_; -}; - -} // namespace webrtc - -#endif // SYSTEM_WRAPPERS_SOURCE_TRACE_WIN_H_ |