Lalit Maganti | 00ca67c | 2021-11-10 14:11:19 +0000 | [diff] [blame] | 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 | |
Lalit Maganti | 628aca7 | 2022-12-08 14:20:25 +0000 | [diff] [blame] | 17 | #ifndef SRC_TRACE_PROCESSOR_PRELUDE_FUNCTIONS_CREATE_FUNCTION_H_ |
| 18 | #define SRC_TRACE_PROCESSOR_PRELUDE_FUNCTIONS_CREATE_FUNCTION_H_ |
Lalit Maganti | 00ca67c | 2021-11-10 14:11:19 +0000 | [diff] [blame] | 19 | |
| 20 | #include <sqlite3.h> |
| 21 | #include <unordered_map> |
| 22 | |
Lalit Maganti | d88300d | 2023-05-15 13:54:51 +0100 | [diff] [blame] | 23 | #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 Maganti | 00ca67c | 2021-11-10 14:11:19 +0000 | [diff] [blame] | 26 | |
| 27 | namespace perfetto { |
| 28 | namespace trace_processor { |
| 29 | |
Lalit Maganti | 842d361 | 2023-05-26 01:30:37 +0100 | [diff] [blame] | 30 | class PerfettoSqlEngine; |
| 31 | |
Lalit Maganti | 00ca67c | 2021-11-10 14:11:19 +0000 | [diff] [blame] | 32 | // Implementation of CREATE_FUNCTION SQL function. |
| 33 | // See https://perfetto.dev/docs/analysis/metrics#metric-helper-functions for |
| 34 | // usage of this function. |
| 35 | struct CreateFunction : public SqlFunction { |
Lalit Maganti | 842d361 | 2023-05-26 01:30:37 +0100 | [diff] [blame] | 36 | using Context = PerfettoSqlEngine; |
Lalit Maganti | 00ca67c | 2021-11-10 14:11:19 +0000 | [diff] [blame] | 37 | |
Lalit Maganti | 8de39bc | 2022-08-26 11:34:14 +0100 | [diff] [blame] | 38 | static constexpr bool kVoidReturn = true; |
| 39 | |
Lalit Maganti | 00ca67c | 2021-11-10 14:11:19 +0000 | [diff] [blame] | 40 | static base::Status Run(Context* ctx, |
| 41 | size_t argc, |
| 42 | sqlite3_value** argv, |
| 43 | SqlValue& out, |
| 44 | Destructors&); |
| 45 | }; |
| 46 | |
Alexander Timin | d330a28 | 2023-06-02 15:19:31 +0100 | [diff] [blame] | 47 | // 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. |
| 52 | struct 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 Maganti | 00ca67c | 2021-11-10 14:11:19 +0000 | [diff] [blame] | 64 | } // namespace trace_processor |
| 65 | } // namespace perfetto |
| 66 | |
Lalit Maganti | 628aca7 | 2022-12-08 14:20:25 +0000 | [diff] [blame] | 67 | #endif // SRC_TRACE_PROCESSOR_PRELUDE_FUNCTIONS_CREATE_FUNCTION_H_ |