xref: /aosp_15_r20/external/perfetto/src/traceconv/pprof_reader.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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_TRACECONV_PPROF_READER_H_
18 #define SRC_TRACECONV_PPROF_READER_H_
19 
20 #include <cstdint>
21 
22 #include "protos/third_party/pprof/profile.gen.h"
23 
24 namespace perfetto {
25 namespace pprof {
26 
27 class PprofProfileReader {
28  public:
29   explicit PprofProfileReader(const std::string& path);
30 
31   uint64_t get_sample_count() const;
32 
33   std::string get_string_by_index(uint64_t string_index) const;
34 
35   int64_t get_string_index(const std::string& str) const;
36 
37   uint64_t find_location_id(const std::string& function_name) const;
38 
39   std::vector<std::string> get_sample_function_names(
40       const third_party::perftools::profiles::gen::Sample& sample) const;
41 
42   // Finds all samples from the profile where its location equals to the passed
43   // function name and returns them. It looks for the last (the most specific)
44   // function name to be equal to last_function_name
45   std::vector<third_party::perftools::profiles::gen::Sample> get_samples(
46       const std::string& last_function_name) const;
47 
48   third_party::perftools::profiles::gen::Location find_location(
49       const uint64_t location_id) const;
50 
51   third_party::perftools::profiles::gen::Function find_function(
52       const uint64_t function_id) const;
53 
54   uint64_t get_sample_value_index(const std::string& value_name) const;
55 
56   int64_t get_samples_value_sum(const std::string& last_function_name,
57                                 const std::string& value_name) const;
58 
59  private:
60   third_party::perftools::profiles::gen::Profile profile_;
61 };
62 
63 }  // namespace pprof
64 }  // namespace perfetto
65 
66 #endif  // SRC_TRACECONV_PPROF_READER_H_
67