1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Use TestTraceProcessor to load a perfetto trace and run queries on the trace. 6 // Documentation on how to use the trace processor and write queries can be 7 // found here: https://perfetto.dev/docs/analysis/trace-processor. 8 // TODO(b/224531105): Implement EXTRACT_ARGS to return multiple args to simplify 9 // queries. 10 11 #ifndef BASE_TEST_TEST_TRACE_PROCESSOR_H_ 12 #define BASE_TEST_TEST_TRACE_PROCESSOR_H_ 13 14 #include <memory> 15 #include "test_trace_processor_export.h" 16 #include "third_party/abseil-cpp/absl/status/status.h" 17 18 namespace perfetto::trace_processor { 19 struct Config; 20 class TraceProcessor; 21 } // namespace perfetto::trace_processor 22 23 namespace base::test { 24 25 class TEST_TRACE_PROCESSOR_EXPORT TestTraceProcessor { 26 public: 27 TestTraceProcessor(); 28 ~TestTraceProcessor(); 29 30 absl::Status ParseTrace(std::unique_ptr<uint8_t[]> buf, size_t size); 31 absl::Status ParseTrace(const std::vector<char>& raw_trace); 32 33 // Runs the sql query on the parsed trace and returns the result as a 34 // vector of strings. 35 std::vector<std::vector<std::string>> ExecuteQuery(const std::string& sql); 36 37 private: 38 std::unique_ptr<perfetto::trace_processor::Config> config_; 39 std::unique_ptr<perfetto::trace_processor::TraceProcessor> trace_processor_; 40 }; 41 42 } // namespace base::test 43 44 #endif // BASE_TEST_TEST_TRACE_PROCESSOR_H_ 45