trace.h revision 046deb9b2050ebdf98a41e2d22f852e104dd365a
1470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/* 2f6bb77a6f0d250f8c4c2c4dbf059556c00cf8eafpwestin@webrtc.org * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * 4470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * Use of this source code is governed by a BSD-style license 5470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * that can be found in the LICENSE file in the root of the source 6470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * tree. An additional intellectual property rights grant can be found 7470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * in the file PATENTS. All contributing project authors may 8470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * be found in the AUTHORS file in the root of the source tree. 9daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org * 10daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org * System independent wrapper for logging runtime information to file. 11daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org * Note: All log messages will be written to the same trace file. 12daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org * Note: If too many messages are written to file there will be a build up of 13daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org * messages. Apply filtering to avoid that. 14470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com */ 15470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 16470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ 17470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ 18470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 19daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org#include "webrtc/common_types.h" 20daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org#include "webrtc/typedefs.h" 21470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 227bf7326d0bbfc4bea634f8ef0af15d5ac7464542wjia@webrtc.org#if !defined(WEBRTC_LOGGING) 237bf7326d0bbfc4bea634f8ef0af15d5ac7464542wjia@webrtc.org#define WEBRTC_TRACE (true) ? (void)0 : Trace::Add 247bf7326d0bbfc4bea634f8ef0af15d5ac7464542wjia@webrtc.org#else 254158c35820f0de05cc3a3a3cb7f822f6e7a7d56ehenrike@webrtc.org#define WEBRTC_TRACE Trace::Add 267bf7326d0bbfc4bea634f8ef0af15d5ac7464542wjia@webrtc.org#endif 27470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 28470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.comnamespace webrtc { 29470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 30daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.orgclass Trace { 31daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org public: 32c1ffd337f14788d596f2c3b869e20b3cca5b1e8aandrew@webrtc.org // The length of the trace text preceeding the log message. 33c1ffd337f14788d596f2c3b869e20b3cca5b1e8aandrew@webrtc.org static const int kBoilerplateLength; 34c1ffd337f14788d596f2c3b869e20b3cca5b1e8aandrew@webrtc.org // The position of the timestamp text within a trace. 35c1ffd337f14788d596f2c3b869e20b3cca5b1e8aandrew@webrtc.org static const int kTimestampPosition; 36c1ffd337f14788d596f2c3b869e20b3cca5b1e8aandrew@webrtc.org // The length of the timestamp (without "delta" field). 37c1ffd337f14788d596f2c3b869e20b3cca5b1e8aandrew@webrtc.org static const int kTimestampLength; 38c1ffd337f14788d596f2c3b869e20b3cca5b1e8aandrew@webrtc.org 39daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // Increments the reference count to the trace. 40daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org static void CreateTrace(); 41daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // Decrements the reference count to the trace. 42daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org static void ReturnTrace(); 43daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // Note: any instance that writes to the trace file should increment and 44daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // decrement the reference count on construction and destruction, 45daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // respectively. 46470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 47daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // Specifies what type of messages should be written to the trace file. The 48daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // filter parameter is a bitmask where each message type is enumerated by the 49daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // TraceLevel enumerator. TODO(hellner): why is the TraceLevel enumerator not 50daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // defined in this file? 51046deb9b2050ebdf98a41e2d22f852e104dd365apbos@webrtc.org static int32_t SetLevelFilter(const uint32_t filter); 52470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 53daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // Returns what type of messages are written to the trace file. 54046deb9b2050ebdf98a41e2d22f852e104dd365apbos@webrtc.org static int32_t LevelFilter(uint32_t& filter); 55470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 56daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // Sets the file name. If add_file_counter is false the same file will be 57daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // reused when it fills up. If it's true a new file with incremented name 58daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // will be used. 59046deb9b2050ebdf98a41e2d22f852e104dd365apbos@webrtc.org static int32_t SetTraceFile(const char* file_name, 60046deb9b2050ebdf98a41e2d22f852e104dd365apbos@webrtc.org const bool add_file_counter = false); 61470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 62daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // Returns the name of the file that the trace is currently writing to. 63046deb9b2050ebdf98a41e2d22f852e104dd365apbos@webrtc.org static int32_t TraceFile(char file_name[1024]); 64470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 65daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // Registers callback to receive trace messages. 66daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // TODO(hellner): Why not use OutStream instead? Why is TraceCallback not 67daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // defined in this file? 68046deb9b2050ebdf98a41e2d22f852e104dd365apbos@webrtc.org static int32_t SetTraceCallback(TraceCallback* callback); 69470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 70daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // Adds a trace message for writing to file. The message is put in a queue 71daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // for writing to file whenever possible for performance reasons. I.e. there 72daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // is a crash it is possible that the last, vital logs are not logged yet. 73daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // level is the type of message to log. If that type of messages is 74daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // filtered it will not be written to file. module is an identifier for what 75daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // part of the code the message is coming. 76daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // id is an identifier that should be unique for that set of classes that 77daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // are associated (e.g. all instances owned by an engine). 78daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // msg and the ellipsis are the same as e.g. sprintf. 79daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org // TODO(hellner) Why is TraceModule not defined in this file? 80daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org static void Add(const TraceLevel level, 81daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org const TraceModule module, 82046deb9b2050ebdf98a41e2d22f852e104dd365apbos@webrtc.org const int32_t id, 83daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org const char* msg, ...); 84470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com}; 8550419b07772de974964072478886c4c35ab9c8ccandrew@webrtc.org 86daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org} // namespace webrtc 87daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org 88daabfd25a6067a62f5c6385353606577b163296bphoglund@webrtc.org#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ 89