OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <inttypes.h> | 11 #include <inttypes.h> |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 | 13 |
14 #include <fstream> | 14 #include <fstream> |
15 #include <iostream> | 15 #include <iostream> |
16 #include <map> | 16 #include <map> |
17 #include <string> | 17 #include <string> |
18 #include <tuple> | 18 #include <tuple> |
19 #include <utility> | 19 #include <utility> |
20 #include <vector> | 20 #include <vector> |
21 | 21 |
22 #include "gflags/gflags.h" | |
23 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 22 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
24 #include "webrtc/rtc_base/checks.h" | 23 #include "webrtc/rtc_base/checks.h" |
| 24 #include "webrtc/rtc_base/flags.h" |
25 #include "webrtc/rtc_base/ignore_wundef.h" | 25 #include "webrtc/rtc_base/ignore_wundef.h" |
26 #include "webrtc/rtc_base/logging.h" | 26 #include "webrtc/rtc_base/logging.h" |
27 | 27 |
28 // Files generated at build-time by the protobuf compiler. | 28 // Files generated at build-time by the protobuf compiler. |
29 RTC_PUSH_IGNORING_WUNDEF() | 29 RTC_PUSH_IGNORING_WUNDEF() |
30 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 30 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
31 #include "external/webrtc/webrtc/logging/rtc_event_log/rtc_event_log.pb.h" | 31 #include "external/webrtc/webrtc/logging/rtc_event_log/rtc_event_log.pb.h" |
32 #else | 32 #else |
33 #include "webrtc/logging/rtc_event_log/rtc_event_log.pb.h" | 33 #include "webrtc/logging/rtc_event_log/rtc_event_log.pb.h" |
34 #endif | 34 #endif |
35 RTC_POP_IGNORING_WUNDEF() | 35 RTC_POP_IGNORING_WUNDEF() |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
| 39 DEFINE_bool(help, false, "Prints this message."); |
| 40 |
39 struct Stats { | 41 struct Stats { |
40 int count = 0; | 42 int count = 0; |
41 size_t total_size = 0; | 43 size_t total_size = 0; |
42 }; | 44 }; |
43 | 45 |
44 // We are duplicating some parts of the parser here because we want to get | 46 // We are duplicating some parts of the parser here because we want to get |
45 // access to raw protobuf events. | 47 // access to raw protobuf events. |
46 std::pair<uint64_t, bool> ParseVarInt(std::istream& stream) { | 48 std::pair<uint64_t, bool> ParseVarInt(std::istream& stream) { |
47 uint64_t varint = 0; | 49 uint64_t varint = 0; |
48 for (size_t bytes_read = 0; bytes_read < 10; ++bytes_read) { | 50 for (size_t bytes_read = 0; bytes_read < 10; ++bytes_read) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 171 |
170 // This utility will print basic information about each packet to stdout. | 172 // This utility will print basic information about each packet to stdout. |
171 // Note that parser will assert if the protobuf event is missing some required | 173 // Note that parser will assert if the protobuf event is missing some required |
172 // fields and we attempt to access them. We don't handle this at the moment. | 174 // fields and we attempt to access them. We don't handle this at the moment. |
173 int main(int argc, char* argv[]) { | 175 int main(int argc, char* argv[]) { |
174 std::string program_name = argv[0]; | 176 std::string program_name = argv[0]; |
175 std::string usage = | 177 std::string usage = |
176 "Tool for file usage statistics from an RtcEventLog.\n" | 178 "Tool for file usage statistics from an RtcEventLog.\n" |
177 "Run " + | 179 "Run " + |
178 program_name + | 180 program_name + |
179 " --helpshort for usage.\n" | 181 " --help for usage.\n" |
180 "Example usage:\n" + | 182 "Example usage:\n" + |
181 program_name + " input.rel\n"; | 183 program_name + " input.rel\n"; |
182 google::SetUsageMessage(usage); | 184 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || |
183 google::ParseCommandLineFlags(&argc, &argv, true); | 185 FLAG_help || argc != 2) { |
184 | 186 std::cout << usage; |
185 if (argc != 2) { | 187 if (FLAG_help) { |
186 std::cout << google::ProgramUsage(); | 188 rtc::FlagList::Print(nullptr, false); |
187 return 0; | 189 return 0; |
| 190 } |
| 191 return 1; |
188 } | 192 } |
189 std::string file_name = argv[1]; | 193 std::string file_name = argv[1]; |
190 | 194 |
191 std::vector<webrtc::rtclog::Event> events; | 195 std::vector<webrtc::rtclog::Event> events; |
192 if (!ParseEvents(file_name, &events)) { | 196 if (!ParseEvents(file_name, &events)) { |
193 LOG(LS_ERROR) << "Failed to parse event log."; | 197 LOG(LS_ERROR) << "Failed to parse event log."; |
194 return -1; | 198 return -1; |
195 } | 199 } |
196 | 200 |
197 // Get file size | 201 // Get file size |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 static_cast<double>(malformed_event_size) / malformed_events, | 248 static_cast<double>(malformed_event_size) / malformed_events, |
245 static_cast<double>(malformed_event_size) / file_size * 100); | 249 static_cast<double>(malformed_event_size) / file_size * 100); |
246 } | 250 } |
247 if (file_size - accumulated_event_size != 0) { | 251 if (file_size - accumulated_event_size != 0) { |
248 printf("WARNING: %" PRId64 " bytes not accounted for\n", | 252 printf("WARNING: %" PRId64 " bytes not accounted for\n", |
249 file_size - accumulated_event_size); | 253 file_size - accumulated_event_size); |
250 } | 254 } |
251 | 255 |
252 return 0; | 256 return 0; |
253 } | 257 } |
OLD | NEW |