14
14
* limitations under the License.
15
15
*/
16
16
17
- #include < stdio.h>
18
-
17
+ #include < cstdint>
18
+ #include < cstdio>
19
+ #include < cstdlib>
20
+ #include < cstring>
19
21
#include < fstream>
20
22
#include < iostream>
21
- #include < limits>
23
+ #include < iterator>
24
+ #include < string>
22
25
#include < vector>
23
26
27
+ #include " perfetto/base/build_config.h"
24
28
#include " perfetto/base/logging.h"
25
29
#include " perfetto/ext/base/string_utils.h"
26
30
#include " perfetto/ext/base/version.h"
31
+ #include " src/protozero/text_to_proto/text_to_proto.h"
27
32
#include " src/traceconv/deobfuscate_profile.h"
28
33
#include " src/traceconv/symbolize_profile.h"
34
+ #include " src/traceconv/trace.descriptor.h"
29
35
#include " src/traceconv/trace_to_firefox.h"
30
36
#include " src/traceconv/trace_to_hprof.h"
31
37
#include " src/traceconv/trace_to_json.h"
41
47
#include < unistd.h>
42
48
#endif
43
49
44
- namespace perfetto {
45
- namespace trace_to_text {
50
+ namespace perfetto ::trace_to_text {
46
51
namespace {
47
52
48
53
int Usage (const char * argv0) {
@@ -51,7 +56,7 @@ int Usage(const char* argv0) {
51
56
" Usage: %s MODE [OPTIONS] [input file] [output file]\n "
52
57
" modes:\n "
53
58
" systrace|json|ctrace|text|profile|hprof|symbolize|deobfuscate|firefox"
54
- " |java_heap_profile|decompress_packets\n "
59
+ " |java_heap_profile|decompress_packets|binary \n "
55
60
" options:\n "
56
61
" [--truncate start|end]\n "
57
62
" [--full-sort]\n "
@@ -76,6 +81,23 @@ uint64_t StringToUint64OrDie(const char* str) {
76
81
return number;
77
82
}
78
83
84
+ int TextToTrace (std::istream* input, std::ostream* output) {
85
+ std::string trace_text ((std::istreambuf_iterator<char >(*input)),
86
+ (std::istreambuf_iterator<char >()));
87
+ auto proto_status =
88
+ protozero::TextToProto (kTraceDescriptor .data (), kTraceDescriptor .size (),
89
+ " .perfetto.protos.Trace" , " trace" , trace_text);
90
+ if (!proto_status.ok ()) {
91
+ PERFETTO_ELOG (" Failed to parse trace: %s" ,
92
+ proto_status.status ().c_message ());
93
+ return 1 ;
94
+ }
95
+ const std::vector<uint8_t >& trace_proto = proto_status.value ();
96
+ output->write (reinterpret_cast <const char *>(trace_proto.data ()),
97
+ static_cast <int64_t >(trace_proto.size ()));
98
+ return 0 ;
99
+ }
100
+
79
101
int Main (int argc, char ** argv) {
80
102
std::vector<const char *> positional_args;
81
103
Keep truncate_keep = Keep::kAll ;
@@ -88,8 +110,8 @@ int Main(int argc, char** argv) {
88
110
if (strcmp (argv[i], " -v" ) == 0 || strcmp (argv[i], " --version" ) == 0 ) {
89
111
printf (" %s\n " , base::GetVersionString ());
90
112
return 0 ;
91
- } else if ( strcmp (argv[i], " -t " ) == 0 ||
92
- strcmp (argv[i], " --truncate" ) == 0 ) {
113
+ }
114
+ if ( strcmp (argv[i], " -t " ) == 0 || strcmp (argv[i], " --truncate" ) == 0 ) {
93
115
i++;
94
116
if (i <= argc && strcmp (argv[i], " start" ) == 0 ) {
95
117
truncate_keep = Keep::kStart ;
@@ -176,6 +198,10 @@ int Main(int argc, char** argv) {
176
198
return 1 ;
177
199
}
178
200
201
+ if (format == " binary" ) {
202
+ return TextToTrace (input_stream, output_stream);
203
+ }
204
+
179
205
if (format == " json" )
180
206
return TraceToJson (input_stream, output_stream, /* compress=*/ false ,
181
207
truncate_keep, full_sort);
@@ -238,8 +264,7 @@ int Main(int argc, char** argv) {
238
264
}
239
265
240
266
} // namespace
241
- } // namespace trace_to_text
242
- } // namespace perfetto
267
+ } // namespace perfetto::trace_to_text
243
268
244
269
int main (int argc, char ** argv) {
245
270
return perfetto::trace_to_text::Main (argc, argv);
0 commit comments