tommi@webrtc.org | 7c64ed2 | 2015-03-17 14:25:37 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 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 | // This file defines the interface for event tracing in WebRTC. |
| 12 | // |
| 13 | // Event log handlers are set through SetupEventTracer(). User of this API will |
| 14 | // provide two function pointers to handle event tracing calls. |
| 15 | // |
| 16 | // * GetCategoryEnabledPtr |
| 17 | // Event tracing system calls this function to determine if a particular |
| 18 | // event category is enabled. |
| 19 | // |
| 20 | // * AddTraceEventPtr |
| 21 | // Adds a tracing event. It is the user's responsibility to log the data |
| 22 | // provided. |
| 23 | // |
| 24 | // Parameters for the above two functions are described in trace_event.h. |
| 25 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 26 | #ifndef RTC_BASE_EVENT_TRACER_H_ |
| 27 | #define RTC_BASE_EVENT_TRACER_H_ |
tommi@webrtc.org | 7c64ed2 | 2015-03-17 14:25:37 | [diff] [blame] | 28 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 29 | #include <stdio.h> |
Peter Boström | 6f28cf0 | 2015-12-07 22:17:15 | [diff] [blame] | 30 | |
Ali Tofigh | 2ab914c | 2022-04-13 10:55:15 | [diff] [blame] | 31 | #include "absl/strings/string_view.h" |
Nicolas Avrutin | a62dcd8 | 2022-01-18 19:28:16 | [diff] [blame] | 32 | #include "rtc_base/system/rtc_export.h" |
| 33 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 34 | namespace webrtc { |
| 35 | |
| 36 | typedef const unsigned char* (*GetCategoryEnabledPtr)(const char* name); |
| 37 | typedef void (*AddTraceEventPtr)(char phase, |
| 38 | const unsigned char* category_enabled, |
| 39 | const char* name, |
| 40 | unsigned long long id, |
| 41 | int num_args, |
| 42 | const char** arg_names, |
| 43 | const unsigned char* arg_types, |
| 44 | const unsigned long long* arg_values, |
| 45 | unsigned char flags); |
| 46 | |
| 47 | // User of WebRTC can call this method to setup event tracing. |
| 48 | // |
| 49 | // This method must be called before any WebRTC methods. Functions |
| 50 | // provided should be thread-safe. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 51 | void SetupEventTracer(GetCategoryEnabledPtr get_category_enabled_ptr, |
| 52 | AddTraceEventPtr add_trace_event_ptr); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 53 | |
| 54 | // This class defines interface for the event tracing system to call |
| 55 | // internally. Do not call these methods directly. |
| 56 | class EventTracer { |
| 57 | public: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 58 | static const unsigned char* GetCategoryEnabled(const char* name); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 59 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 60 | static void AddTraceEvent(char phase, |
| 61 | const unsigned char* category_enabled, |
| 62 | const char* name, |
| 63 | unsigned long long id, |
| 64 | int num_args, |
| 65 | const char** arg_names, |
| 66 | const unsigned char* arg_types, |
| 67 | const unsigned long long* arg_values, |
| 68 | unsigned char flags); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace webrtc |
| 72 | |
| 73 | namespace rtc { |
| 74 | namespace tracing { |
| 75 | // Set up internal event tracer. |
Jianhui Dai | 8712d0b | 2022-05-10 01:41:01 | [diff] [blame] | 76 | RTC_EXPORT void SetupInternalTracer(bool enable_all_categories = true); |
Ali Tofigh | 2ab914c | 2022-04-13 10:55:15 | [diff] [blame] | 77 | RTC_EXPORT bool StartInternalCapture(absl::string_view filename); |
Nicolas Avrutin | a62dcd8 | 2022-01-18 19:28:16 | [diff] [blame] | 78 | RTC_EXPORT void StartInternalCaptureToFile(FILE* file); |
| 79 | RTC_EXPORT void StopInternalCapture(); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 80 | // Make sure we run this, this will tear down the internal tracing. |
Nicolas Avrutin | a62dcd8 | 2022-01-18 19:28:16 | [diff] [blame] | 81 | RTC_EXPORT void ShutdownInternalTracer(); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 82 | } // namespace tracing |
| 83 | } // namespace rtc |
Peter Boström | 6f28cf0 | 2015-12-07 22:17:15 | [diff] [blame] | 84 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 85 | #endif // RTC_BASE_EVENT_TRACER_H_ |