16
16
17
17
#include < stdio.h>
18
18
19
+ #include < cstdint>
20
+ #include < cstdlib>
21
+ #include < cstring>
19
22
#include < fstream>
20
23
#include < iostream>
24
+ #include < iterator>
21
25
#include < limits>
26
+ #include < string>
22
27
#include < vector>
23
28
29
+ #include " perfetto/base/build_config.h"
24
30
#include " perfetto/base/logging.h"
25
31
#include " perfetto/ext/base/string_utils.h"
26
32
#include " perfetto/ext/base/version.h"
33
+ #include " src/protozero/text_to_proto/text_to_proto.h"
27
34
#include " src/traceconv/deobfuscate_profile.h"
28
35
#include " src/traceconv/symbolize_profile.h"
36
+ #include " src/traceconv/trace.descriptor.h"
29
37
#include " src/traceconv/trace_to_firefox.h"
30
38
#include " src/traceconv/trace_to_hprof.h"
31
39
#include " src/traceconv/trace_to_json.h"
@@ -51,7 +59,7 @@ int Usage(const char* argv0) {
51
59
" Usage: %s MODE [OPTIONS] [input file] [output file]\n "
52
60
" modes:\n "
53
61
" systrace|json|ctrace|text|profile|hprof|symbolize|deobfuscate|firefox"
54
- " |java_heap_profile|decompress_packets\n "
62
+ " |java_heap_profile|decompress_packets|binary \n "
55
63
" options:\n "
56
64
" [--truncate start|end]\n "
57
65
" [--full-sort]\n "
@@ -76,6 +84,23 @@ uint64_t StringToUint64OrDie(const char* str) {
76
84
return number;
77
85
}
78
86
87
+ uint64_t TextToTrace (std::istream* input, std::ostream* output) {
88
+ std::string trace_text ((std::istreambuf_iterator<char >(*input)),
89
+ (std::istreambuf_iterator<char >()));
90
+ auto proto_status =
91
+ protozero::TextToProto (kTraceDescriptor .data (), kTraceDescriptor .size (),
92
+ " .perfetto.protos.Trace" , " trace" , trace_text);
93
+ if (!proto_status.ok ()) {
94
+ PERFETTO_ELOG (" Failed to parse trace: %s" ,
95
+ proto_status.status ().c_message ());
96
+ return 1 ;
97
+ }
98
+ const std::vector<uint8_t >& trace_proto = proto_status.value ();
99
+ output->write (reinterpret_cast <const char *>(trace_proto.data ()),
100
+ static_cast <int64_t >(trace_proto.size ()));
101
+ return 0 ;
102
+ }
103
+
79
104
int Main (int argc, char ** argv) {
80
105
std::vector<const char *> positional_args;
81
106
Keep truncate_keep = Keep::kAll ;
@@ -176,6 +201,10 @@ int Main(int argc, char** argv) {
176
201
return 1 ;
177
202
}
178
203
204
+ if (format == " binary" ) {
205
+ return TextToTrace (input_stream, output_stream);
206
+ }
207
+
179
208
if (format == " json" )
180
209
return TraceToJson (input_stream, output_stream, /* compress=*/ false ,
181
210
truncate_keep, full_sort);
0 commit comments