• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/profiler_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,const tables::PerfCounterTrackTable::ConstRowReference & track)31   PerfCounter(tables::CounterTable* counter_table,
32               const tables::PerfCounterTrackTable::ConstRowReference& track)
33       : counter_table_(*counter_table),
34         track_id_(track.id()),
35         is_timebase_(track.is_timebase()) {}
36 
is_timebase()37   bool is_timebase() const { return is_timebase_; }
38 
39   void AddDelta(int64_t ts, double delta);
40   void AddCount(int64_t ts, double count);
41 
42  private:
43   tables::CounterTable& counter_table_;
44   tables::PerfCounterTrackTable::Id track_id_;
45   const bool is_timebase_;
46   double last_count_{0};
47 };
48 
49 }  // namespace perfetto::trace_processor::perf_importer
50 
51 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_PERF_PERF_COUNTER_H_
52