1 /*
2  * Copyright (C) 2020 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_PERFETTO_SQL_INTRINSICS_TABLE_FUNCTIONS_EXPERIMENTAL_FLAMEGRAPH_H_
18 #define SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_TABLE_FUNCTIONS_EXPERIMENTAL_FLAMEGRAPH_H_
19 
20 #include <cstdint>
21 #include <memory>
22 #include <optional>
23 #include <string>
24 #include <vector>
25 
26 #include "perfetto/ext/base/status_or.h"
27 #include "perfetto/trace_processor/basic_types.h"
28 #include "src/trace_processor/db/table.h"
29 #include "src/trace_processor/perfetto_sql/intrinsics/table_functions/flamegraph_construction_algorithms.h"
30 #include "src/trace_processor/perfetto_sql/intrinsics/table_functions/static_table_function.h"
31 #include "src/trace_processor/storage/trace_storage.h"
32 
33 namespace perfetto::trace_processor {
34 
35 class TraceProcessorContext;
36 
37 class ExperimentalFlamegraph : public StaticTableFunction {
38  public:
39   enum class ProfileType { kGraph, kHeapProfile, kPerf };
40 
41   struct InputValues {
42     ProfileType profile_type;
43     std::optional<int64_t> ts;
44     std::vector<TimeConstraints> time_constraints;
45     std::optional<UniquePid> upid;
46     std::optional<std::string> upid_group;
47     std::optional<std::string> focus_str;
48   };
49 
50   explicit ExperimentalFlamegraph(TraceProcessorContext* context);
51   virtual ~ExperimentalFlamegraph() override;
52 
53   Table::Schema CreateSchema() override;
54   std::string TableName() override;
55   uint32_t EstimateRowCount() override;
56   base::StatusOr<std::unique_ptr<Table>> ComputeTable(
57       const std::vector<SqlValue>& arguments) override;
58 
59  private:
60   TraceProcessorContext* context_ = nullptr;
61 };
62 
63 }  // namespace perfetto::trace_processor
64 
65 #endif  // SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_TABLE_FUNCTIONS_EXPERIMENTAL_FLAMEGRAPH_H_
66