1# Copyright (C) 2018 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import("../../gn/fuzzer.gni")
16import("../../gn/perfetto.gni")
17import("../../gn/perfetto_cc_proto_descriptor.gni")
18import("../../gn/perfetto_host_executable.gni")
19import("../../gn/test.gni")
20import("../../gn/wasm.gni")
21
22# Prevent that this file is accidentally included in embedder builds.
23assert(enable_perfetto_trace_processor)
24
25# The library which eases processing of Perfetto traces by exposing reading
26# friendly APIs.
27if (enable_perfetto_trace_processor_sqlite) {
28  static_library("trace_processor") {
29    complete_static_lib = true
30    public_deps = [ ":lib" ]
31  }
32}
33
34if (enable_perfetto_ui) {
35  wasm_lib("trace_processor_wasm") {
36    name = "trace_processor"
37    deps = [
38      ":lib",
39      "../../gn:default_deps",
40      "../base",
41      "rpc:wasm_bridge",
42    ]
43  }
44}
45
46source_set("metatrace") {
47  sources = [
48    "tp_metatrace.cc",
49    "tp_metatrace.h",
50  ]
51  deps = [
52    "../../gn:default_deps",
53    "../../include/perfetto/ext/base",
54  ]
55}
56
57source_set("ftrace_descriptors") {
58  sources = [
59    "importers/ftrace/ftrace_descriptors.cc",
60    "importers/ftrace/ftrace_descriptors.h",
61  ]
62  deps = [
63    "../../gn:default_deps",
64    "../../include/perfetto/ext/base:base",
65    "../protozero",
66  ]
67}
68
69source_set("storage_minimal") {
70  sources = [
71    "forwarding_trace_parser.cc",
72    "forwarding_trace_parser.h",
73    "importers/default_modules.cc",
74    "importers/default_modules.h",
75    "importers/ftrace/ftrace_module.cc",
76    "importers/ftrace/ftrace_module.h",
77    "importers/fuchsia/fuchsia_record.h",
78    "importers/fuchsia/fuchsia_trace_utils.h",
79    "importers/gzip/gzip_utils.cc",
80    "importers/gzip/gzip_utils.h",
81    "importers/json/json_utils.cc",
82    "importers/json/json_utils.h",
83    "importers/ninja/ninja_log_parser.cc",
84    "importers/ninja/ninja_log_parser.h",
85    "importers/proto/async_track_set_tracker.cc",
86    "importers/proto/async_track_set_tracker.h",
87    "importers/proto/chrome_string_lookup.cc",
88    "importers/proto/chrome_string_lookup.h",
89    "importers/proto/chrome_system_probes_module.cc",
90    "importers/proto/chrome_system_probes_module.h",
91    "importers/proto/chrome_system_probes_parser.cc",
92    "importers/proto/chrome_system_probes_parser.h",
93    "importers/proto/heap_profile_tracker.cc",
94    "importers/proto/heap_profile_tracker.h",
95    "importers/proto/memory_tracker_snapshot_module.cc",
96    "importers/proto/memory_tracker_snapshot_module.h",
97    "importers/proto/memory_tracker_snapshot_parser.cc",
98    "importers/proto/memory_tracker_snapshot_parser.h",
99    "importers/proto/metadata_module.cc",
100    "importers/proto/metadata_module.h",
101    "importers/proto/metadata_tracker.cc",
102    "importers/proto/metadata_tracker.h",
103    "importers/proto/packet_sequence_state.cc",
104    "importers/proto/packet_sequence_state.h",
105    "importers/proto/perf_sample_tracker.cc",
106    "importers/proto/perf_sample_tracker.h",
107    "importers/proto/profile_module.cc",
108    "importers/proto/profile_module.h",
109    "importers/proto/profile_packet_utils.cc",
110    "importers/proto/profile_packet_utils.h",
111    "importers/proto/profiler_util.cc",
112    "importers/proto/profiler_util.h",
113    "importers/proto/proto_importer_module.cc",
114    "importers/proto/proto_importer_module.h",
115    "importers/proto/proto_incremental_state.h",
116    "importers/proto/proto_trace_parser.cc",
117    "importers/proto/proto_trace_parser.h",
118    "importers/proto/proto_trace_reader.cc",
119    "importers/proto/proto_trace_reader.h",
120    "importers/proto/proto_trace_tokenizer.cc",
121    "importers/proto/proto_trace_tokenizer.h",
122    "importers/proto/stack_profile_tracker.cc",
123    "importers/proto/stack_profile_tracker.h",
124    "importers/proto/track_event_module.cc",
125    "importers/proto/track_event_module.h",
126    "importers/proto/track_event_parser.cc",
127    "importers/proto/track_event_parser.h",
128    "importers/proto/track_event_tokenizer.cc",
129    "importers/proto/track_event_tokenizer.h",
130    "importers/proto/track_event_tracker.cc",
131    "importers/proto/track_event_tracker.h",
132    "importers/syscalls/syscall_tracker.h",
133    "importers/systrace/systrace_line.h",
134    "timestamped_trace_piece.h",
135    "trace_processor_context.cc",
136    "trace_processor_storage.cc",
137    "trace_processor_storage_impl.cc",
138    "trace_processor_storage_impl.h",
139    "trace_sorter.cc",
140    "trace_sorter.h",
141    "virtual_destructors.cc",
142  ]
143  deps = [
144    "../../gn:default_deps",
145    "../base",
146    "../protozero",
147    "containers",
148    "importers:gen_cc_chrome_track_event_descriptor",
149    "importers:gen_cc_track_event_descriptor",
150    "importers/common",
151    "importers/memory_tracker:graph_processor",
152    "storage",
153    "tables",
154    "types",
155    "util",
156    "util:descriptors",
157    "util:proto_to_args_parser",
158  ]
159  public_deps = [
160    "../../include/perfetto/trace_processor:storage",
161    "../../protos/perfetto/common:zero",
162    "../../protos/perfetto/config:zero",
163    "../../protos/perfetto/trace:zero",
164    "../../protos/perfetto/trace/android:zero",
165    "../../protos/perfetto/trace/chrome:zero",
166    "../../protos/perfetto/trace/ftrace:zero",
167    "../../protos/perfetto/trace/interned_data:zero",
168    "../../protos/perfetto/trace/perfetto:zero",
169    "../../protos/perfetto/trace/power:zero",
170    "../../protos/perfetto/trace/profiling:zero",
171    "../../protos/perfetto/trace/ps:zero",
172    "../../protos/perfetto/trace/sys_stats:zero",
173    "../../protos/perfetto/trace/system_info:zero",
174    "../../protos/perfetto/trace/track_event:zero",
175  ]
176
177  # json_utils optionally depends on jsoncpp.
178  if (enable_perfetto_trace_processor_json) {
179    deps += [ "../../gn:jsoncpp" ]
180  }
181
182  # gzip_utils optionally depends on zlib.
183  if (enable_perfetto_zlib) {
184    deps += [ "../../gn:zlib" ]
185  }
186}
187
188source_set("storage_full") {
189  sources = [
190    "importers/additional_modules.cc",
191    "importers/additional_modules.h",
192    "importers/ftrace/binder_tracker.cc",
193    "importers/ftrace/binder_tracker.h",
194    "importers/ftrace/ftrace_module_impl.cc",
195    "importers/ftrace/ftrace_module_impl.h",
196    "importers/ftrace/ftrace_parser.cc",
197    "importers/ftrace/ftrace_parser.h",
198    "importers/ftrace/ftrace_tokenizer.cc",
199    "importers/ftrace/ftrace_tokenizer.h",
200    "importers/ftrace/rss_stat_tracker.cc",
201    "importers/ftrace/rss_stat_tracker.h",
202    "importers/ftrace/sched_event_tracker.cc",
203    "importers/ftrace/sched_event_tracker.h",
204    "importers/fuchsia/fuchsia_record.cc",
205    "importers/fuchsia/fuchsia_trace_parser.cc",
206    "importers/fuchsia/fuchsia_trace_parser.h",
207    "importers/fuchsia/fuchsia_trace_tokenizer.cc",
208    "importers/fuchsia/fuchsia_trace_tokenizer.h",
209    "importers/fuchsia/fuchsia_trace_utils.cc",
210    "importers/gzip/gzip_trace_parser.cc",
211    "importers/gzip/gzip_trace_parser.h",
212    "importers/json/json_trace_parser.cc",
213    "importers/json/json_trace_parser.h",
214    "importers/json/json_trace_tokenizer.cc",
215    "importers/json/json_trace_tokenizer.h",
216    "importers/json/json_tracker.cc",
217    "importers/json/json_tracker.h",
218    "importers/proto/android_probes_module.cc",
219    "importers/proto/android_probes_module.h",
220    "importers/proto/android_probes_parser.cc",
221    "importers/proto/android_probes_parser.h",
222    "importers/proto/android_probes_tracker.cc",
223    "importers/proto/android_probes_tracker.h",
224    "importers/proto/frame_timeline_event_parser.cc",
225    "importers/proto/frame_timeline_event_parser.h",
226    "importers/proto/gpu_event_parser.cc",
227    "importers/proto/gpu_event_parser.h",
228    "importers/proto/graphics_event_module.cc",
229    "importers/proto/graphics_event_module.h",
230    "importers/proto/graphics_frame_event_parser.cc",
231    "importers/proto/graphics_frame_event_parser.h",
232    "importers/proto/heap_graph_module.cc",
233    "importers/proto/heap_graph_module.h",
234    "importers/proto/heap_graph_tracker.cc",
235    "importers/proto/heap_graph_tracker.h",
236    "importers/proto/system_probes_module.cc",
237    "importers/proto/system_probes_module.h",
238    "importers/proto/system_probes_parser.cc",
239    "importers/proto/system_probes_parser.h",
240    "importers/proto/vulkan_memory_tracker.cc",
241    "importers/proto/vulkan_memory_tracker.h",
242    "importers/syscalls/syscall_tracker.cc",
243    "importers/syscalls/syscalls_aarch32.h",
244    "importers/syscalls/syscalls_aarch64.h",
245    "importers/syscalls/syscalls_armeabi.h",
246    "importers/syscalls/syscalls_x86.h",
247    "importers/syscalls/syscalls_x86_64.h",
248    "importers/systrace/systrace_line_parser.cc",
249    "importers/systrace/systrace_line_parser.h",
250    "importers/systrace/systrace_line_tokenizer.cc",
251    "importers/systrace/systrace_line_tokenizer.h",
252    "importers/systrace/systrace_parser.cc",
253    "importers/systrace/systrace_parser.h",
254    "importers/systrace/systrace_trace_parser.cc",
255    "importers/systrace/systrace_trace_parser.h",
256  ]
257  public_deps = [ ":storage_minimal" ]
258  deps = [
259    ":ftrace_descriptors",
260    "../../include/perfetto/ext/base:base",
261    "../../include/perfetto/ext/traced:sys_stats_counters",
262    "../../protos/perfetto/common:zero",
263    "../../protos/perfetto/trace:zero",
264    "../../protos/perfetto/trace/android:zero",
265    "../../protos/perfetto/trace/gpu:zero",
266    "../../protos/perfetto/trace/interned_data:zero",
267    "../protozero",
268    "importers/common",
269    "storage",
270    "tables",
271    "types",
272    "util",
273  ]
274  if (enable_perfetto_trace_processor_json) {
275    deps += [ "../../gn:jsoncpp" ]
276  }
277}
278
279source_set("export_json") {
280  sources = [
281    "export_json.cc",
282    "export_json.h",
283  ]
284  deps = [
285    ":storage_minimal",
286    "../../gn:default_deps",
287    "../base",
288    "storage",
289    "types",
290  ]
291  public_deps = [ "../../include/perfetto/ext/trace_processor:export_json" ]
292  if (enable_perfetto_trace_processor_json) {
293    deps += [ "../../gn:jsoncpp" ]
294  }
295}
296
297if (enable_perfetto_trace_processor_sqlite) {
298  source_set("lib") {
299    sources = [
300      "dynamic/ancestor_generator.cc",
301      "dynamic/ancestor_generator.h",
302      "dynamic/connected_flow_generator.cc",
303      "dynamic/connected_flow_generator.h",
304      "dynamic/descendant_slice_generator.cc",
305      "dynamic/descendant_slice_generator.h",
306      "dynamic/describe_slice_generator.cc",
307      "dynamic/describe_slice_generator.h",
308      "dynamic/experimental_annotated_stack_generator.cc",
309      "dynamic/experimental_annotated_stack_generator.h",
310      "dynamic/experimental_counter_dur_generator.cc",
311      "dynamic/experimental_counter_dur_generator.h",
312      "dynamic/experimental_flamegraph_generator.cc",
313      "dynamic/experimental_flamegraph_generator.h",
314      "dynamic/experimental_sched_upid_generator.cc",
315      "dynamic/experimental_sched_upid_generator.h",
316      "dynamic/experimental_slice_layout_generator.cc",
317      "dynamic/experimental_slice_layout_generator.h",
318      "dynamic/thread_state_generator.cc",
319      "dynamic/thread_state_generator.h",
320      "iterator_impl.cc",
321      "iterator_impl.h",
322      "read_trace.cc",
323      "trace_processor.cc",
324      "trace_processor_impl.cc",
325      "trace_processor_impl.h",
326    ]
327
328    deps = [
329      ":export_json",
330      ":metatrace",
331      ":storage_full",
332      "../../gn:default_deps",
333      "../../protos/perfetto/trace/ftrace:zero",
334      "../base",
335      "../protozero",
336      "analysis",
337      "db",
338      "importers/common",
339      "metrics:lib",
340      "sqlite",
341      "storage",
342      "tables",
343      "types",
344      "util",
345      "util:protozero_to_text",
346    ]
347    public_deps = [
348      "../../gn:sqlite",  # iterator_impl.h includes sqlite3.h.
349      "../../include/perfetto/trace_processor",
350    ]
351    if (enable_perfetto_trace_processor_json) {
352      deps += [ "../../gn:jsoncpp" ]
353    }
354  }
355
356  executable("trace_processor_shell") {
357    deps = [
358      ":lib",
359      "../../gn:default_deps",
360      "../../gn:protobuf_full",
361      "../../src/profiling:deobfuscator",
362      "../../src/profiling/symbolizer",
363      "../../src/profiling/symbolizer:symbolize_database",
364      "../base",
365      "metrics:lib",
366      "util",
367    ]
368    if (enable_perfetto_trace_processor_linenoise) {
369      deps += [ "../../gn:linenoise" ]
370    }
371    if (enable_perfetto_trace_processor_httpd) {
372      deps += [ "rpc:httpd" ]
373    }
374    sources = [
375      "trace_processor_shell.cc",
376      "util/proto_to_json.cc",
377      "util/proto_to_json.h",
378    ]
379    if (perfetto_build_standalone && !is_perfetto_build_generator) {
380      data_deps = [
381        # The diff testing framework depends on these descriptors.
382        "../../protos/perfetto/metrics:descriptor",
383        "../../protos/perfetto/trace:descriptor",
384        "../../protos/perfetto/trace:test_extensions_descriptor",
385      ]
386    }
387  }
388}  # if (enable_perfetto_trace_processor_sqlite)
389
390perfetto_unittest_source_set("unittests") {
391  testonly = true
392  sources = [
393    "forwarding_trace_parser_unittest.cc",
394    "importers/ftrace/sched_event_tracker_unittest.cc",
395    "importers/fuchsia/fuchsia_trace_utils_unittest.cc",
396    "importers/memory_tracker/graph_processor_unittest.cc",
397    "importers/memory_tracker/graph_unittest.cc",
398    "importers/memory_tracker/raw_process_memory_node_unittest.cc",
399    "importers/proto/async_track_set_tracker_unittest.cc",
400    "importers/proto/heap_graph_tracker_unittest.cc",
401    "importers/proto/heap_profile_tracker_unittest.cc",
402    "importers/proto/perf_sample_tracker_unittest.cc",
403    "importers/proto/proto_trace_parser_unittest.cc",
404    "importers/syscalls/syscall_tracker_unittest.cc",
405    "importers/systrace/systrace_parser_unittest.cc",
406    "trace_sorter_unittest.cc",
407  ]
408  deps = [
409    ":gen_cc_test_messages_descriptor",
410    ":storage_full",
411    "../../gn:default_deps",
412    "../../gn:gtest_and_gmock",
413    "../../protos/perfetto/common:cpp",
414    "../../protos/perfetto/common:zero",
415    "../../protos/perfetto/trace:cpp",
416    "../../protos/perfetto/trace:minimal_zero",
417    "../../protos/perfetto/trace:zero",
418    "../../protos/perfetto/trace/android:zero",
419    "../../protos/perfetto/trace/chrome:zero",
420    "../../protos/perfetto/trace/ftrace:zero",
421    "../../protos/perfetto/trace/gpu:zero",
422    "../../protos/perfetto/trace/interned_data:zero",
423    "../../protos/perfetto/trace/profiling:cpp",
424    "../../protos/perfetto/trace/ps:zero",
425    "../../protos/perfetto/trace/sys_stats:zero",
426    "../../protos/perfetto/trace/track_event:zero",
427    "../base",
428    "../protozero",
429    "../protozero:testing_messages_zero",
430    "containers:unittests",
431    "db:unittests",
432    "importers/common",
433    "importers/common:unittests",
434    "importers/memory_tracker:graph_processor",
435    "rpc:unittests",
436    "storage",
437    "tables:unittests",
438    "types",
439    "types:unittests",
440    "util:descriptors",
441    "util:unittests",
442  ]
443
444  if (enable_perfetto_trace_processor_sqlite) {
445    sources += [
446      "dynamic/experimental_counter_dur_generator_unittest.cc",
447      "dynamic/experimental_slice_layout_generator_unittest.cc",
448      "dynamic/thread_state_generator_unittest.cc",
449    ]
450    deps += [
451      ":lib",
452      "../../gn:sqlite",
453      "sqlite:unittests",
454    ]
455  }
456
457  if (enable_perfetto_trace_processor_json) {
458    sources += [
459      "importers/json/json_trace_tokenizer_unittest.cc",
460      "importers/json/json_tracker_unittest.cc",
461      "importers/json/json_utils_unittest.cc",
462    ]
463    deps += [ "../../gn:jsoncpp" ]
464
465    if (!is_win) {
466      # export_json_unittest.cc uses base::TempFile, which is not supported on
467      # windows.
468      sources += [ "export_json_unittest.cc" ]
469      deps += [
470        ":export_json",
471        "../../include/perfetto/ext/trace_processor:export_json",
472      ]
473    }
474  }
475}
476
477perfetto_cc_proto_descriptor("gen_cc_test_messages_descriptor") {
478  descriptor_name = "test_messages.descriptor"
479  descriptor_target = "../protozero:test_messages_descriptor"
480}
481
482source_set("integrationtests") {
483  testonly = true
484  sources = []
485  deps = []
486  if (enable_perfetto_trace_processor_sqlite) {
487    sources += [
488      "read_trace_integrationtest.cc",
489      "trace_database_integrationtest.cc",
490    ]
491    deps += [
492      ":lib",
493      "../../gn:default_deps",
494      "../../gn:gtest_and_gmock",
495      "../../protos/perfetto/common:zero",
496      "../../protos/perfetto/trace:zero",
497      "../../protos/perfetto/trace_processor:zero",
498      "../base",
499      "../base:test_support",
500      "sqlite",
501    ]
502    if (enable_perfetto_trace_processor_json) {
503      deps += [ "../../gn:jsoncpp" ]
504    }
505  }
506}
507
508if (enable_perfetto_trace_processor_json) {
509  source_set("storage_minimal_smoke_tests") {
510    testonly = true
511    sources = [ "storage_minimal_smoke_test.cc" ]
512    deps = [
513      ":export_json",
514      ":storage_minimal",
515      "../../gn:default_deps",
516      "../../gn:gtest_and_gmock",
517      "../../gn:gtest_main",
518      "../../gn:jsoncpp",
519      "../base:test_support",
520    ]
521  }
522}
523
524perfetto_fuzzer_test("trace_processor_fuzzer") {
525  testonly = true
526  sources = [ "trace_parsing_fuzzer.cc" ]
527  deps = [
528    ":storage_full",
529    "../../gn:default_deps",
530    "../base",
531  ]
532}
533