xref: /aosp_15_r20/external/perfetto/src/trace_processor/perfetto_sql/engine/created_function.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2021 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_ENGINE_CREATED_FUNCTION_H_
18 #define SRC_TRACE_PROCESSOR_PERFETTO_SQL_ENGINE_CREATED_FUNCTION_H_
19 
20 #include <sqlite3.h>
21 #include <cstddef>
22 #include <memory>
23 
24 #include "perfetto/base/status.h"
25 #include "perfetto/trace_processor/basic_types.h"
26 #include "src/trace_processor/perfetto_sql/intrinsics/functions/sql_function.h"
27 #include "src/trace_processor/perfetto_sql/parser/function_util.h"
28 #include "src/trace_processor/sqlite/sql_source.h"
29 #include "src/trace_processor/types/destructible.h"
30 #include "src/trace_processor/util/sql_argument.h"
31 
32 namespace perfetto::trace_processor {
33 
34 class PerfettoSqlEngine;
35 
36 struct CreatedFunction : public SqlFunction {
37   // Expose a do-nothing context
38   using Context = Destructible;
39 
40   // SqlFunction implementation.
41   static base::Status Run(Context* ctx,
42                           size_t argc,
43                           sqlite3_value** argv,
44                           SqlValue& out,
45                           Destructors&);
46   static base::Status VerifyPostConditions(Context*);
47   static void Cleanup(Context*);
48 
49   // Glue code for PerfettoSqlEngine.
50   static std::unique_ptr<Context> MakeContext(PerfettoSqlEngine*);
51   static bool IsValid(Context*);
52   static void Reset(Context*, PerfettoSqlEngine*);
53   static base::Status Prepare(Context*,
54                               FunctionPrototype,
55                               sql_argument::Type return_type,
56                               SqlSource sql);
57   static base::Status EnableMemoization(Context*);
58 };
59 
60 }  // namespace perfetto::trace_processor
61 
62 #endif  // SRC_TRACE_PROCESSOR_PERFETTO_SQL_ENGINE_CREATED_FUNCTION_H_
63