1 /* 2 * Copyright (C) 2019 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 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_FTRACE_TOKENIZER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_FTRACE_TOKENIZER_H_ 19 20 #include <optional> 21 #include <vector> 22 23 #include "perfetto/trace_processor/trace_blob_view.h" 24 #include "src/trace_processor/importers/common/clock_tracker.h" 25 #include "src/trace_processor/importers/proto/packet_sequence_state_generation.h" 26 #include "src/trace_processor/storage/trace_storage.h" 27 #include "src/trace_processor/types/trace_processor_context.h" 28 29 #include "protos/perfetto/trace/ftrace/ftrace_event_bundle.pbzero.h" 30 31 namespace perfetto { 32 namespace trace_processor { 33 34 class FtraceTokenizer { 35 public: FtraceTokenizer(TraceProcessorContext * context)36 explicit FtraceTokenizer(TraceProcessorContext* context) 37 : context_(context) {} 38 39 base::Status TokenizeFtraceBundle(TraceBlobView bundle, 40 RefPtr<PacketSequenceStateGeneration>, 41 uint32_t packet_sequence_id); 42 43 private: 44 void TokenizeFtraceEvent(uint32_t cpu, 45 ClockTracker::ClockId, 46 TraceBlobView event, 47 RefPtr<PacketSequenceStateGeneration> state); 48 void TokenizeFtraceCompactSched(uint32_t cpu, 49 ClockTracker::ClockId, 50 protozero::ConstBytes); 51 void TokenizeFtraceCompactSchedSwitch( 52 uint32_t cpu, 53 ClockTracker::ClockId, 54 const protos::pbzero::FtraceEventBundle::CompactSched::Decoder& compact, 55 const std::vector<StringId>& string_table); 56 void TokenizeFtraceCompactSchedWaking( 57 uint32_t cpu, 58 ClockTracker::ClockId, 59 const protos::pbzero::FtraceEventBundle::CompactSched::Decoder& compact, 60 const std::vector<StringId>& string_table); 61 62 void HandleFtraceClockSnapshot(int64_t ftrace_ts, 63 int64_t boot_ts, 64 uint32_t packet_sequence_id); 65 void TokenizeFtraceGpuWorkPeriod(uint32_t cpu, 66 TraceBlobView event, 67 RefPtr<PacketSequenceStateGeneration> state); 68 void TokenizeFtraceThermalExynosAcpmBulk( 69 uint32_t cpu, 70 TraceBlobView event, 71 RefPtr<PacketSequenceStateGeneration> state); 72 void TokenizeFtraceParamSetValueCpm( 73 uint32_t cpu, TraceBlobView event, 74 RefPtr<PacketSequenceStateGeneration> state); 75 std::optional<protozero::Field> GetFtraceEventField( 76 uint32_t event_id, const TraceBlobView& event); 77 DlogWithLimit(const base::Status & status)78 void DlogWithLimit(const base::Status& status) { 79 static std::atomic<uint32_t> dlog_count(0); 80 if (dlog_count++ < 10) 81 PERFETTO_DLOG("%s", status.c_message()); 82 } 83 84 int64_t latest_ftrace_clock_snapshot_ts_ = 0; 85 std::vector<bool> per_cpu_seen_first_bundle_; 86 TraceProcessorContext* context_; 87 }; 88 89 } // namespace trace_processor 90 } // namespace perfetto 91 92 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_FTRACE_TOKENIZER_H_ 93