• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INTRINSICS_FUNCTIONS_CREATE_FUNCTION_H_
18 #define SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_FUNCTIONS_CREATE_FUNCTION_H_
19 
20 #include <sqlite3.h>
21 #include <cstddef>
22 
23 #include "perfetto/base/status.h"
24 #include "perfetto/trace_processor/basic_types.h"
25 #include "src/trace_processor/perfetto_sql/intrinsics/functions/sql_function.h"
26 
27 namespace perfetto::trace_processor {
28 
29 class PerfettoSqlEngine;
30 
31 // Implementation of CREATE_FUNCTION SQL function.
32 // See https://perfetto.dev/docs/analysis/metrics#metric-helper-functions for
33 // usage of this function.
34 struct CreateFunction : public SqlFunction {
35   using Context = PerfettoSqlEngine;
36 
37   static constexpr bool kVoidReturn = true;
38 
39   static base::Status Run(Context* ctx,
40                           size_t argc,
41                           sqlite3_value** argv,
42                           SqlValue& out,
43                           Destructors&);
44 };
45 
46 // Implementation of MEMOIZE SQL function.
47 // SELECT EXPERIMENTAL_MEMOIZE('my_func') enables memoization for the results of
48 // the calls to `my_func`. `my_func` must be a Perfetto SQL function created
49 // through CREATE_FUNCTION that takes a single integer argument and returns a
50 // int.
51 struct ExperimentalMemoize : public SqlFunction {
52   using Context = PerfettoSqlEngine;
53 
54   static constexpr bool kVoidReturn = true;
55 
56   static base::Status Run(Context* ctx,
57                           size_t argc,
58                           sqlite3_value** argv,
59                           SqlValue& out,
60                           Destructors&);
61 };
62 
63 }  // namespace perfetto::trace_processor
64 
65 #endif  // SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_FUNCTIONS_CREATE_FUNCTION_H_
66