xref: /aosp_15_r20/external/webrtc/rtc_tools/rtc_event_log_to_text/main.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2022 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 #include <stdio.h>
12 
13 #include <string>
14 #include <vector>
15 
16 #include "absl/flags/flag.h"
17 #include "absl/flags/parse.h"
18 #include "absl/flags/usage.h"
19 #include "absl/strings/string_view.h"
20 #include "logging/rtc_event_log/rtc_event_log_parser.h"
21 #include "rtc_base/logging.h"
22 #include "rtc_tools/rtc_event_log_to_text/converter.h"
23 
24 ABSL_FLAG(bool,
25           parse_unconfigured_header_extensions,
26           true,
27           "Attempt to parse unconfigured header extensions using the default "
28           "WebRTC mapping. This can give very misleading results if the "
29           "application negotiates a different mapping.");
30 
31 // Prints an RTC event log as human readable text with one line per event.
32 // Note that the RTC event log text format isn't an API. Prefer to build
33 // tools directly on the parser (logging/rtc_event_log/rtc_event_log_parser.cc).
main(int argc,char * argv[])34 int main(int argc, char* argv[]) {
35   absl::SetProgramUsageMessage(
36       "A tool for converting WebRTC event logs to text.\n"
37       "The events are sorted by log time and printed\n"
38       "with one event per line, using the following format:\n"
39       "<EVENT_TYPE> <log_time_ms> <field1>=<value1> <field2>=<value2> ...\n"
40       "\n"
41       "Example usage:\n"
42       "./rtc_event_log_to_text <inputfile> <outputfile>\n"
43       "./rtc_event_log_to_text <inputfile>\n"
44       "If no output file is specified, the output is written to stdout\n");
45   std::vector<char*> args = absl::ParseCommandLine(argc, argv);
46 
47   // Print RTC_LOG warnings and errors even in release builds.
48   if (rtc::LogMessage::GetLogToDebug() > rtc::LS_WARNING) {
49     rtc::LogMessage::LogToDebug(rtc::LS_WARNING);
50   }
51   rtc::LogMessage::SetLogToStderr(true);
52 
53   webrtc::ParsedRtcEventLog::UnconfiguredHeaderExtensions header_extensions =
54       webrtc::ParsedRtcEventLog::UnconfiguredHeaderExtensions::kDontParse;
55   if (absl::GetFlag(FLAGS_parse_unconfigured_header_extensions)) {
56     header_extensions = webrtc::ParsedRtcEventLog::
57         UnconfiguredHeaderExtensions::kAttemptWebrtcDefaultConfig;
58   }
59 
60   std::string inputfile;
61   FILE* output = nullptr;
62   if (args.size() == 3) {
63     inputfile = args[1];
64     std::string outputfile = args[2];
65     output = fopen(outputfile.c_str(), "w");
66   } else if (args.size() == 2) {
67     inputfile = args[1];
68     output = stdout;
69   } else {
70     // Print usage information.
71     std::cerr << absl::ProgramUsageMessage();
72     return 1;
73   }
74 
75   bool success = webrtc::Convert(inputfile, output, header_extensions);
76 
77   return success ? 0 : 1;
78 }
79