blob: 612abf1b8e10f631db6d0fdba56c667639d78181 [file] [log] [blame]
Lalit Maganti00ca67c2021-11-10 14:11:19 +00001/*
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
Lalit Maganti628aca72022-12-08 14:20:25 +000017#ifndef SRC_TRACE_PROCESSOR_PRELUDE_FUNCTIONS_CREATE_FUNCTION_H_
18#define SRC_TRACE_PROCESSOR_PRELUDE_FUNCTIONS_CREATE_FUNCTION_H_
Lalit Maganti00ca67c2021-11-10 14:11:19 +000019
20#include <sqlite3.h>
21#include <unordered_map>
22
Lalit Magantid88300d2023-05-15 13:54:51 +010023#include "src/trace_processor/prelude/functions/sql_function.h"
24#include "src/trace_processor/sqlite/scoped_db.h"
25#include "src/trace_processor/sqlite/sqlite_table.h"
Lalit Maganti00ca67c2021-11-10 14:11:19 +000026
27namespace perfetto {
28namespace trace_processor {
29
Lalit Maganti842d3612023-05-26 01:30:37 +010030class PerfettoSqlEngine;
31
Lalit Maganti00ca67c2021-11-10 14:11:19 +000032// Implementation of CREATE_FUNCTION SQL function.
33// See https://perfetto.dev/docs/analysis/metrics#metric-helper-functions for
34// usage of this function.
35struct CreateFunction : public SqlFunction {
Lalit Maganti842d3612023-05-26 01:30:37 +010036 using Context = PerfettoSqlEngine;
Lalit Maganti00ca67c2021-11-10 14:11:19 +000037
Lalit Maganti8de39bc2022-08-26 11:34:14 +010038 static constexpr bool kVoidReturn = true;
39
Lalit Maganti00ca67c2021-11-10 14:11:19 +000040 static base::Status Run(Context* ctx,
41 size_t argc,
42 sqlite3_value** argv,
43 SqlValue& out,
44 Destructors&);
45};
46
Alexander Timind330a282023-06-02 15:19:31 +010047// Implementation of MEMOIZE SQL function.
48// SELECT EXPERIMENTAL_MEMOIZE('my_func') enables memoization for the results of
49// the calls to `my_func`. `my_func` must be a Perfetto SQL function created
50// through CREATE_FUNCTION that takes a single integer argument and returns a
51// int.
52struct ExperimentalMemoize : public SqlFunction {
53 using Context = PerfettoSqlEngine;
54
55 static constexpr bool kVoidReturn = true;
56
57 static base::Status Run(Context* ctx,
58 size_t argc,
59 sqlite3_value** argv,
60 SqlValue& out,
61 Destructors&);
62};
63
Lalit Maganti00ca67c2021-11-10 14:11:19 +000064} // namespace trace_processor
65} // namespace perfetto
66
Lalit Maganti628aca72022-12-08 14:20:25 +000067#endif // SRC_TRACE_PROCESSOR_PRELUDE_FUNCTIONS_CREATE_FUNCTION_H_