1 /* 2 * Copyright (C) 2024 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_PERF_PERF_COUNTER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PERF_PERF_COUNTER_H_ 19 20 #include <cstdint> 21 22 #include "src/trace_processor/tables/counter_tables_py.h" 23 #include "src/trace_processor/tables/track_tables_py.h" 24 25 namespace perfetto::trace_processor::perf_importer { 26 27 // Helper class to keep track of perf counters and convert delta values found in 28 // perf files to absolute values needed for the perfetto counter table. 29 class PerfCounter { 30 public: PerfCounter(tables::CounterTable * counter_table,tables::TrackTable::Id track_id,bool is_timebase)31 PerfCounter(tables::CounterTable* counter_table, 32 tables::TrackTable::Id track_id, 33 bool is_timebase) 34 : counter_table_(*counter_table), 35 track_id_(track_id), 36 is_timebase_(is_timebase) {} 37 is_timebase()38 bool is_timebase() const { return is_timebase_; } 39 40 void AddDelta(int64_t ts, double delta); 41 void AddCount(int64_t ts, double count); 42 43 private: 44 tables::CounterTable& counter_table_; 45 tables::TrackTable::Id track_id_; 46 const bool is_timebase_; 47 double last_count_{0}; 48 }; 49 50 } // namespace perfetto::trace_processor::perf_importer 51 52 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PERF_PERF_COUNTER_H_ 53