blob: 707589d19e31d53a9e83d426c44def536d71cb85 [file] [log] [blame]
Hector Dearman20b3c1c2018-01-15 15:34:03 +00001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <inttypes.h>
18
19#include <stdio.h>
Hector Dearman85ef5362018-03-27 14:48:47 +010020#include <sys/ioctl.h>
21#include <unistd.h>
22
Hector Dearman20b3c1c2018-01-15 15:34:03 +000023#include <algorithm>
24#include <fstream>
Lalit Maganti910852d2018-03-28 13:16:45 +010025#include <functional>
Hector Dearman20b3c1c2018-01-15 15:34:03 +000026#include <iostream>
27#include <istream>
Hector Dearman85ef5362018-03-27 14:48:47 +010028#include <limits>
Hector Dearman20b3c1c2018-01-15 15:34:03 +000029#include <map>
30#include <memory>
31#include <ostream>
32#include <sstream>
Hector Dearman20b3c1c2018-01-15 15:34:03 +000033#include <utility>
34
35#include <google/protobuf/compiler/importer.h>
36#include <google/protobuf/dynamic_message.h>
37#include <google/protobuf/io/zero_copy_stream_impl.h>
38#include <google/protobuf/text_format.h>
39#include <google/protobuf/util/field_comparator.h>
40#include <google/protobuf/util/message_differencer.h>
41
42#include "perfetto/base/logging.h"
Primiano Tucci20b760c2018-01-19 12:36:12 +000043#include "perfetto/trace/trace.pb.h"
44#include "perfetto/trace/trace_packet.pb.h"
Hector Dearman85ef5362018-03-27 14:48:47 +010045#include "tools/trace_to_text/ftrace_event_formatter.h"
Anna Zappone7c104622018-03-28 16:35:18 +010046#include "tools/trace_to_text/ftrace_inode_handler.h"
Hector Dearman20b3c1c2018-01-15 15:34:03 +000047
48namespace perfetto {
49namespace {
50
51const char kTraceHeader[] = R"({
52 "traceEvents": [],
53)";
54
55const char kTraceFooter[] = R"(\n",
56 "controllerTraceDataKey": "systraceController"
57})";
58
59const char kFtraceHeader[] =
60 ""
61 " \"systemTraceEvents\": \""
62 "# tracer: nop\\n"
63 "#\\n"
64 "# entries-in-buffer/entries-written: 30624/30624 #P:4\\n"
65 "#\\n"
66 "# _-----=> irqs-off\\n"
67 "# / _----=> need-resched\\n"
68 "# | / _---=> hardirq/softirq\\n"
69 "# || / _--=> preempt-depth\\n"
70 "# ||| / delay\\n"
71 "# TASK-PID TGID CPU# |||| TIMESTAMP FUNCTION\\n"
72 "# | | | | |||| | |\\n";
73
74using google::protobuf::Descriptor;
75using google::protobuf::DynamicMessageFactory;
76using google::protobuf::FileDescriptor;
77using google::protobuf::Message;
78using google::protobuf::TextFormat;
79using google::protobuf::compiler::DiskSourceTree;
80using google::protobuf::compiler::Importer;
81using google::protobuf::compiler::MultiFileErrorCollector;
82using google::protobuf::io::OstreamOutputStream;
Anna Zappone6e4e0382018-02-27 11:15:30 +000083
Anna Zappone6e4e0382018-02-27 11:15:30 +000084using protos::FtraceEvent;
85using protos::FtraceEventBundle;
Anna Zappone27ac99c2018-03-06 14:25:35 +000086using protos::InodeFileMap;
Anna Zappone6e4e0382018-02-27 11:15:30 +000087using protos::PrintFtraceEvent;
88using protos::ProcessTree;
89using protos::Trace;
90using protos::TracePacket;
Anna Zappone27ac99c2018-03-06 14:25:35 +000091using Entry = protos::InodeFileMap::Entry;
Isabelle Taylord404ea12018-02-19 17:28:01 +000092using Process = protos::ProcessTree::Process;
93
94// TODO(hjd): Add tests.
Hector Dearman20b3c1c2018-01-15 15:34:03 +000095
Hector Dearman85ef5362018-03-27 14:48:47 +010096size_t GetWidth() {
97 if (!isatty(STDOUT_FILENO))
98 return 80;
99 struct winsize win_size;
100 ioctl(STDOUT_FILENO, TIOCGWINSZ, &win_size);
101 return win_size.ws_col;
102}
103
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000104class MFE : public MultiFileErrorCollector {
105 virtual void AddError(const std::string& filename,
106 int line,
107 int column,
108 const std::string& message) {
109 PERFETTO_ELOG("Error %s %d:%d: %s", filename.c_str(), line, column,
110 message.c_str());
111 }
112
113 virtual void AddWarning(const std::string& filename,
114 int line,
115 int column,
116 const std::string& message) {
117 PERFETTO_ELOG("Error %s %d:%d: %s", filename.c_str(), line, column,
118 message.c_str());
119 }
120};
121
Hector Dearman85ef5362018-03-27 14:48:47 +0100122void ForEachPacketInTrace(
123 std::istream* input,
124 const std::function<void(const protos::TracePacket&)>& f) {
Primiano Tucci2ffd1a52018-03-27 01:01:30 +0100125 size_t bytes_processed = 0;
126 // The trace stream can be very large. We cannot just pass it in one go to
127 // libprotobuf as that will refuse to parse messages > 64MB. However we know
128 // that a trace is merely a sequence of TracePackets. Here we just manually
129 // tokenize the repeated TracePacket messages and parse them individually
130 // using libprotobuf.
131 for (;;) {
132 fprintf(stderr, "Processing trace: %8zu KB\r", bytes_processed / 1024);
133 fflush(stderr);
134 // A TracePacket consists in one byte stating its field id and type ...
135 char preamble;
136 input->get(preamble);
137 if (!input->good())
138 break;
139 bytes_processed++;
140 PERFETTO_DCHECK(preamble == 0x0a); // Field ID:1, type:length delimited.
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000141
Primiano Tucci2ffd1a52018-03-27 01:01:30 +0100142 // ... a varint stating its size ...
143 uint32_t field_size = 0;
144 uint32_t shift = 0;
145 for (;;) {
146 char c = 0;
147 input->get(c);
148 field_size |= static_cast<uint32_t>(c & 0x7f) << shift;
149 shift += 7;
150 bytes_processed++;
151 if (!(c & 0x80))
152 break;
153 }
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000154
Primiano Tucci2ffd1a52018-03-27 01:01:30 +0100155 // ... and the actual TracePacket itself.
156 std::unique_ptr<char[]> buf(new char[field_size]);
Primiano Tucci3cbb10a2018-04-10 17:52:40 +0100157 input->read(buf.get(), static_cast<std::streamsize>(field_size));
Primiano Tucci2ffd1a52018-03-27 01:01:30 +0100158 bytes_processed += field_size;
159
160 protos::TracePacket packet;
Primiano Tucci3cbb10a2018-04-10 17:52:40 +0100161 auto res = packet.ParseFromArray(buf.get(), static_cast<int>(field_size));
162 PERFETTO_CHECK(res);
Hector Dearman85ef5362018-03-27 14:48:47 +0100163 f(packet);
164 }
165}
166
Primiano Tucci45c9b182018-03-29 14:10:51 +0100167int TraceToSystrace(std::istream* input,
168 std::ostream* output,
169 bool wrap_in_json) {
Hector Dearman85ef5362018-03-27 14:48:47 +0100170 std::multimap<uint64_t, std::string> sorted;
171
172 ForEachPacketInTrace(input, [&sorted](const protos::TracePacket& packet) {
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000173 if (!packet.has_ftrace_events())
Hector Dearman85ef5362018-03-27 14:48:47 +0100174 return;
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000175
176 const FtraceEventBundle& bundle = packet.ftrace_events();
177 for (const FtraceEvent& event : bundle.event()) {
Hector Dearman85ef5362018-03-27 14:48:47 +0100178 std::string line =
179 FormatFtraceEvent(event.timestamp(), bundle.cpu(), event);
180 if (line == "")
Hector Dearman7f37dc82018-01-25 12:25:40 +0000181 continue;
Hector Dearman85ef5362018-03-27 14:48:47 +0100182 sorted.emplace(event.timestamp(), line);
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000183 }
Hector Dearman85ef5362018-03-27 14:48:47 +0100184 });
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000185
Primiano Tucci45c9b182018-03-29 14:10:51 +0100186 if (wrap_in_json) {
187 *output << kTraceHeader;
188 *output << kFtraceHeader;
189 }
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000190
Primiano Tucci2ffd1a52018-03-27 01:01:30 +0100191 fprintf(stderr, "\n");
192 size_t total_events = sorted.size();
193 size_t written_events = 0;
194 for (auto it = sorted.begin(); it != sorted.end(); it++) {
Primiano Tucci45c9b182018-03-29 14:10:51 +0100195 *output << it->second << (wrap_in_json ? "\\n" : "\n");
196 if (written_events++ % 100 == 0 && !isatty(STDOUT_FILENO)) {
Primiano Tucci2ffd1a52018-03-27 01:01:30 +0100197 fprintf(stderr, "Writing trace: %.2f %%\r",
198 written_events * 100.0 / total_events);
199 fflush(stderr);
200 }
201 }
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000202
Primiano Tucci45c9b182018-03-29 14:10:51 +0100203 if (wrap_in_json)
204 *output << kTraceFooter;
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000205
206 return 0;
207}
208
Hector Dearman85ef5362018-03-27 14:48:47 +0100209int TraceToText(std::istream* input, std::ostream* output) {
210 DiskSourceTree dst;
211 dst.MapPath("perfetto", "protos/perfetto");
212 MFE mfe;
213 Importer importer(&dst, &mfe);
214 const FileDescriptor* parsed_file =
215 importer.Import("perfetto/trace/trace.proto");
216
217 DynamicMessageFactory dmf;
218 const Descriptor* trace_descriptor = parsed_file->message_type(0);
219 const Message* msg_root = dmf.GetPrototype(trace_descriptor);
220 Message* msg = msg_root->New();
221
222 if (!msg->ParseFromIstream(input)) {
223 PERFETTO_ELOG("Could not parse input.");
224 return 1;
225 }
226 OstreamOutputStream zero_copy_output(output);
227 TextFormat::Print(*msg, &zero_copy_output);
228 return 0;
229}
230
Anna Zappone7c104622018-03-28 16:35:18 +0100231void PrintFtraceTrack(std::ostream* output,
232 const uint64_t& start,
233 const uint64_t& end,
234 const std::multiset<uint64_t>& ftrace_timestamps) {
Hector Dearman85ef5362018-03-27 14:48:47 +0100235 constexpr char kFtraceTrackName[] = "ftrace ";
236 size_t width = GetWidth();
237 size_t bucket_count = width - strlen(kFtraceTrackName);
Primiano Tucci3cbb10a2018-04-10 17:52:40 +0100238 size_t bucket_size = static_cast<size_t>(end - start) / bucket_count;
Hector Dearman85ef5362018-03-27 14:48:47 +0100239 size_t max = 0;
240 std::vector<size_t> buckets(bucket_count);
241 for (size_t i = 0; i < bucket_count; i++) {
242 auto low = ftrace_timestamps.lower_bound(i * bucket_size + start);
243 auto high = ftrace_timestamps.upper_bound((i + 1) * bucket_size + start);
Primiano Tucci3cbb10a2018-04-10 17:52:40 +0100244 buckets[i] = static_cast<size_t>(std::distance(low, high));
Hector Dearman85ef5362018-03-27 14:48:47 +0100245 max = std::max(max, buckets[i]);
246 }
247
248 std::vector<std::string> out =
249 std::vector<std::string>({" ", "▁", "▂", "▃", "▄", "▅", "▆", "▇"});
Anna Zappone7c104622018-03-28 16:35:18 +0100250 *output << "-------------------- " << kFtraceTrackName
251 << "--------------------\n";
252 char line[2048];
Hector Dearman85ef5362018-03-27 14:48:47 +0100253 for (size_t i = 0; i < bucket_count; i++) {
254 sprintf(
255 line, "%s",
256 out[std::min(buckets[i] / (max / out.size()), out.size() - 1)].c_str());
257 *output << std::string(line);
258 }
Isabelle Taylord496ea52018-03-28 11:59:59 +0100259 *output << "\n\n";
Anna Zappone7c104622018-03-28 16:35:18 +0100260}
Isabelle Taylord496ea52018-03-28 11:59:59 +0100261
Anna Zappone7c104622018-03-28 16:35:18 +0100262void PrintInodeStats(std::ostream* output,
Anna Zappone5e8fa4b2018-03-29 12:56:22 +0100263 const std::set<uint64_t>& ftrace_inodes,
264 const uint64_t& ftrace_inode_count,
265 const std::set<uint64_t>& resolved_map_inodes,
Lalit Magantic27975c2018-04-10 21:42:18 +0100266 const std::set<uint64_t>& resolved_scan_inodes,
267 bool compact_output) {
268 if (!compact_output)
269 *output << "--------------------Inode Stats-------------------\n";
270
Anna Zappone7c104622018-03-28 16:35:18 +0100271 char line[2048];
Lalit Magantic27975c2018-04-10 21:42:18 +0100272 if (compact_output) {
273 sprintf(line, "events_inodes,%" PRIu64 "\n", ftrace_inode_count);
274 } else {
275 sprintf(line, "Events with inodes: %" PRIu64 "\n", ftrace_inode_count);
276 }
Anna Zappone7c104622018-03-28 16:35:18 +0100277 *output << std::string(line);
278
Lalit Magantic27975c2018-04-10 21:42:18 +0100279 if (compact_output) {
280 sprintf(line, "events_unique_inodes,%zu\n", ftrace_inodes.size());
281 } else {
282 sprintf(line, "Unique inodes from events: %zu\n", ftrace_inodes.size());
283 }
Anna Zappone7c104622018-03-28 16:35:18 +0100284 *output << std::string(line);
Anna Zappone5e8fa4b2018-03-29 12:56:22 +0100285
Lalit Magantic27975c2018-04-10 21:42:18 +0100286 if (compact_output) {
287 sprintf(line, "resolved_inodes_static,%zu\n", resolved_map_inodes.size());
288 } else {
289 sprintf(line, "Resolved inodes from static map: %zu\n",
290 resolved_map_inodes.size());
291 }
Anna Zappone5e8fa4b2018-03-29 12:56:22 +0100292 *output << std::string(line);
293
Lalit Magantic27975c2018-04-10 21:42:18 +0100294 if (compact_output) {
295 sprintf(line, "resolved_inodes_scan_cache,%zu\n",
296 resolved_scan_inodes.size());
297 } else {
298 sprintf(line, "Resolved inodes from scan and cache: %zu\n",
299 resolved_scan_inodes.size());
300 }
Anna Zappone5e8fa4b2018-03-29 12:56:22 +0100301 *output << std::string(line);
302
303 std::set<uint64_t> resolved_inodes;
304 set_union(resolved_map_inodes.begin(), resolved_map_inodes.end(),
305 resolved_scan_inodes.begin(), resolved_scan_inodes.end(),
306 std::inserter(resolved_inodes, resolved_inodes.begin()));
307
Lalit Magantic27975c2018-04-10 21:42:18 +0100308 if (compact_output) {
309 sprintf(line, "total_resolved_inodes,%zu\n", resolved_inodes.size());
310 } else {
311 sprintf(line, "Total resolved inodes: %zu\n", resolved_inodes.size());
312 }
Anna Zappone5e8fa4b2018-03-29 12:56:22 +0100313 *output << std::string(line);
314
315 std::set<uint64_t> intersect;
316 set_intersection(resolved_inodes.begin(), resolved_inodes.end(),
317 ftrace_inodes.begin(), ftrace_inodes.end(),
318 std::inserter(intersect, intersect.begin()));
319
Lalit Magantic27975c2018-04-10 21:42:18 +0100320 size_t unresolved_inodes = ftrace_inodes.size() - intersect.size();
321 if (compact_output) {
322 sprintf(line, "unresolved_inodes,%zu\n", unresolved_inodes);
323 } else {
324 sprintf(line, "Unresolved inodes: %zu\n", unresolved_inodes);
325 }
Anna Zappone5e8fa4b2018-03-29 12:56:22 +0100326 *output << std::string(line);
327
Lalit Magantic27975c2018-04-10 21:42:18 +0100328 size_t unexpected_inodes = resolved_inodes.size() - intersect.size();
329 if (compact_output) {
330 sprintf(line, "unexpected_inodes_fs,%zu\n", unexpected_inodes);
331 } else {
332 sprintf(line, "Unexpected inodes from filesystem: %zu\n",
333 unexpected_inodes);
334 }
335 *output << std::string(line);
336
337 if (!compact_output)
338 *output << "\n";
Anna Zappone7c104622018-03-28 16:35:18 +0100339}
340
341void PrintProcessStats(std::ostream* output,
342 const std::set<pid_t>& tids_in_tree,
Lalit Magantic27975c2018-04-10 21:42:18 +0100343 const std::set<pid_t>& tids_in_events,
344 bool compact_output) {
345 if (!compact_output)
346 *output << "----------------Process Tree Stats----------------\n";
Isabelle Taylord496ea52018-03-28 11:59:59 +0100347
348 char tid[2048];
Lalit Magantic27975c2018-04-10 21:42:18 +0100349 if (compact_output) {
350 sprintf(tid, "unique_thread_process,%zu\n", tids_in_tree.size());
351 } else {
352 sprintf(tid, "Unique thread ids in process tree: %zu\n",
353 tids_in_tree.size());
354 }
Isabelle Taylord496ea52018-03-28 11:59:59 +0100355 *output << std::string(tid);
356
357 char tid_event[2048];
Lalit Magantic27975c2018-04-10 21:42:18 +0100358 if (compact_output) {
359 sprintf(tid_event, "unique_thread_ftrace,%zu\n", tids_in_events.size());
360 } else {
361 sprintf(tid_event, "Unique thread ids in ftrace events: %zu\n",
362 tids_in_events.size());
363 }
Isabelle Taylord496ea52018-03-28 11:59:59 +0100364 *output << std::string(tid_event);
365
366 std::set<pid_t> intersect;
367 set_intersection(tids_in_tree.begin(), tids_in_tree.end(),
368 tids_in_events.begin(), tids_in_events.end(),
369 std::inserter(intersect, intersect.begin()));
370
371 char matching[2048];
Lalit Magantic27975c2018-04-10 21:42:18 +0100372 size_t thread_id_process_info =
373 (intersect.size() * 100) / tids_in_events.size();
374 if (compact_output) {
375 sprintf(matching,
376 "tids_with_pinfo,%zu\ntids,%zu\ntids_with_pinfo_percentage,%zu\n",
377 intersect.size(), tids_in_events.size(), thread_id_process_info);
378 } else {
379 sprintf(matching, "Thread ids with process info: %zu/%zu -> %zu %%\n\n",
380 intersect.size(), tids_in_events.size(), thread_id_process_info);
381 }
Isabelle Taylord496ea52018-03-28 11:59:59 +0100382 *output << std::string(matching);
Lalit Magantic27975c2018-04-10 21:42:18 +0100383
384 if (!compact_output)
385 *output << "\n";
Anna Zappone7c104622018-03-28 16:35:18 +0100386}
387
Lalit Magantic27975c2018-04-10 21:42:18 +0100388int TraceToSummary(std::istream* input,
389 std::ostream* output,
390 bool compact_output) {
Anna Zappone7c104622018-03-28 16:35:18 +0100391 uint64_t start = std::numeric_limits<uint64_t>::max();
392 uint64_t end = 0;
393 std::multiset<uint64_t> ftrace_timestamps;
394 std::set<pid_t> tids_in_tree;
395 std::set<pid_t> tids_in_events;
Anna Zappone5e8fa4b2018-03-29 12:56:22 +0100396 std::set<uint64_t> ftrace_inodes;
397 uint64_t ftrace_inode_count = 0;
398 std::set<uint64_t> resolved_map_inodes;
399 std::set<uint64_t> resolved_scan_inodes;
Anna Zappone7c104622018-03-28 16:35:18 +0100400
401 ForEachPacketInTrace(
Anna Zappone5e8fa4b2018-03-29 12:56:22 +0100402 input, [&start, &end, &ftrace_timestamps, &tids_in_tree, &tids_in_events,
403 &ftrace_inodes, &ftrace_inode_count, &resolved_map_inodes,
404 &resolved_scan_inodes](const protos::TracePacket& packet) {
Anna Zappone7c104622018-03-28 16:35:18 +0100405
406 if (packet.has_process_tree()) {
407 const ProcessTree& tree = packet.process_tree();
408 for (Process process : tree.processes()) {
Isabelle Taylorb2499472018-04-03 15:21:04 +0100409 tids_in_tree.insert(process.pid());
Primiano Tucci567a5112018-04-25 14:00:59 +0100410 for (ProcessTree::Thread thread : process.threads_deprecated())
Anna Zappone7c104622018-03-28 16:35:18 +0100411 tids_in_tree.insert(thread.tid());
Anna Zappone7c104622018-03-28 16:35:18 +0100412 }
Primiano Tucci567a5112018-04-25 14:00:59 +0100413 for (ProcessTree::Thread thread : tree.threads())
414 tids_in_tree.insert(thread.tid());
Anna Zappone7c104622018-03-28 16:35:18 +0100415 }
416
Anna Zappone5e8fa4b2018-03-29 12:56:22 +0100417 if (packet.has_inode_file_map()) {
418 const InodeFileMap& inode_file_map = packet.inode_file_map();
419 const auto& mount_points = inode_file_map.mount_points();
420 bool from_scan = std::find(mount_points.begin(), mount_points.end(),
421 "/data") != mount_points.end();
422 for (const auto& entry : inode_file_map.entries())
423 if (from_scan)
424 resolved_scan_inodes.insert(entry.inode_number());
425 else
426 resolved_map_inodes.insert(entry.inode_number());
427 }
428
Anna Zappone7c104622018-03-28 16:35:18 +0100429 if (!packet.has_ftrace_events())
430 return;
431
432 const FtraceEventBundle& bundle = packet.ftrace_events();
433 uint64_t inode_number = 0;
434 for (const FtraceEvent& event : bundle.event()) {
435 if (ParseInode(event, &inode_number)) {
Anna Zappone5e8fa4b2018-03-29 12:56:22 +0100436 ftrace_inodes.insert(inode_number);
437 ftrace_inode_count++;
Anna Zappone7c104622018-03-28 16:35:18 +0100438 }
439 if (event.pid()) {
Primiano Tucci3cbb10a2018-04-10 17:52:40 +0100440 tids_in_events.insert(static_cast<int>(event.pid()));
Anna Zappone7c104622018-03-28 16:35:18 +0100441 }
442 if (event.timestamp()) {
443 start = std::min<uint64_t>(start, event.timestamp());
444 end = std::max<uint64_t>(end, event.timestamp());
445 ftrace_timestamps.insert(event.timestamp());
446 }
447 }
448 });
449
450 fprintf(stderr, "\n");
451
452 char line[2048];
Lalit Magantic27975c2018-04-10 21:42:18 +0100453 uint64_t duration = (end - start) / (1000 * 1000);
454 if (compact_output) {
455 sprintf(line, "duration,%" PRIu64 "\n", duration);
456 } else {
457 sprintf(line, "Duration: %" PRIu64 "ms\n", duration);
458 }
Anna Zappone7c104622018-03-28 16:35:18 +0100459 *output << std::string(line);
460
Lalit Magantic27975c2018-04-10 21:42:18 +0100461 if (!compact_output)
462 PrintFtraceTrack(output, start, end, ftrace_timestamps);
463 PrintProcessStats(output, tids_in_tree, tids_in_events, compact_output);
Anna Zappone5e8fa4b2018-03-29 12:56:22 +0100464 PrintInodeStats(output, ftrace_inodes, ftrace_inode_count,
Lalit Magantic27975c2018-04-10 21:42:18 +0100465 resolved_map_inodes, resolved_scan_inodes, compact_output);
Isabelle Taylord496ea52018-03-28 11:59:59 +0100466
Hector Dearman85ef5362018-03-27 14:48:47 +0100467 return 0;
468}
469
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000470} // namespace
471} // namespace perfetto
472
473namespace {
474
Primiano Tucci3cbb10a2018-04-10 17:52:40 +0100475int Usage(const char* argv0) {
Lalit Magantic27975c2018-04-10 21:42:18 +0100476 printf(
477 "Usage: %s [systrace|json|text|summary|short_summary] < trace.proto > "
478 "trace.txt\n",
479 argv0);
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000480 return 1;
481}
482
483} // namespace
484
485int main(int argc, char** argv) {
486 if (argc != 2)
Primiano Tucci3cbb10a2018-04-10 17:52:40 +0100487 return Usage(argv[0]);
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000488
489 std::string format(argv[1]);
490
Primiano Tucci45c9b182018-03-29 14:10:51 +0100491 if (format == "json")
492 return perfetto::TraceToSystrace(&std::cin, &std::cout,
493 /*wrap_in_json=*/true);
494 if (format == "systrace")
495 return perfetto::TraceToSystrace(&std::cin, &std::cout,
496 /*wrap_in_json=*/false);
497 if (format == "text")
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000498 return perfetto::TraceToText(&std::cin, &std::cout);
Primiano Tucci45c9b182018-03-29 14:10:51 +0100499 if (format == "summary")
Lalit Magantic27975c2018-04-10 21:42:18 +0100500 return perfetto::TraceToSummary(&std::cin, &std::cout,
501 /* compact_output */ true);
502 if (format == "short_summary")
503 return perfetto::TraceToSummary(&std::cin, &std::cout,
504 /* compact_output */ true);
505
Primiano Tucci3cbb10a2018-04-10 17:52:40 +0100506 return Usage(argv[0]);
Hector Dearman20b3c1c2018-01-15 15:34:03 +0000507}