#include "src/trace_processor/perfetto_sql/engine/perfetto_sql_engine.h"
#include <algorithm>
#include <array>
#include <cctype>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <variant>
#include <vector>
#include "perfetto/base/compiler.h"
#include "perfetto/base/logging.h"
#include "perfetto/base/status.h"
#include "perfetto/ext/base/flat_hash_map.h"
#include "perfetto/ext/base/status_or.h"
#include "perfetto/ext/base/string_utils.h"
#include "perfetto/ext/base/string_view.h"
#include "perfetto/trace_processor/basic_types.h"
#include "src/trace_processor/containers/row_map.h"
#include "src/trace_processor/containers/string_pool.h"
#include "src/trace_processor/db/column/types.h"
#include "src/trace_processor/db/runtime_table.h"
#include "src/trace_processor/db/table.h"
#include "src/trace_processor/perfetto_sql/engine/created_function.h"
#include "src/trace_processor/perfetto_sql/engine/function_util.h"
#include "src/trace_processor/perfetto_sql/engine/perfetto_sql_parser.h"
#include "src/trace_processor/perfetto_sql/engine/perfetto_sql_preprocessor.h"
#include "src/trace_processor/perfetto_sql/engine/runtime_table_function.h"
#include "src/trace_processor/perfetto_sql/intrinsics/table_functions/static_table_function.h"
#include "src/trace_processor/sqlite/db_sqlite_table.h"
#include "src/trace_processor/sqlite/scoped_db.h"
#include "src/trace_processor/sqlite/sql_source.h"
#include "src/trace_processor/sqlite/sqlite_engine.h"
#include "src/trace_processor/sqlite/sqlite_utils.h"
#include "src/trace_processor/tp_metatrace.h"
#include "src/trace_processor/util/sql_argument.h"
#include "src/trace_processor/util/sql_modules.h"
#include "src/trace_processor/util/status_macros.h"
#include "protos/perfetto/trace_processor/metatrace_categories.pbzero.h"
namespace perfetto::trace_processor {
namespace {
void IncrementCountForStmt(const SqliteEngine::PreparedStatement& p_stmt,
PerfettoSqlEngine::ExecutionStats* res) { … }
base::Status AddTracebackIfNeeded(base::Status status,
const SqlSource& source) { … }
SqlSource RewriteToDummySql(const SqlSource& source) { … }
constexpr std::array<const char*, 8> kTokensAllowedInMacro({ … });
bool IsTokenAllowedInMacro(const std::string& view) { … }
std::string GetTokenNamesAllowedInMacro() { … }
}
PerfettoSqlEngine::PerfettoSqlEngine(StringPool* pool, bool enable_extra_checks)
: … { … }
base::StatusOr<SqliteEngine::PreparedStatement>
PerfettoSqlEngine::PrepareSqliteStatement(SqlSource sql_source) { … }
void PerfettoSqlEngine::RegisterStaticTable(Table* table,
const std::string& table_name,
Table::Schema schema) { … }
void PerfettoSqlEngine::RegisterStaticTableFunction(
std::unique_ptr<StaticTableFunction> fn) { … }
base::StatusOr<PerfettoSqlEngine::ExecutionStats> PerfettoSqlEngine::Execute(
SqlSource sql) { … }
base::StatusOr<PerfettoSqlEngine::ExecutionResult>
PerfettoSqlEngine::ExecuteUntilLastStatement(SqlSource sql_source) { … }
base::Status PerfettoSqlEngine::RegisterRuntimeFunction(
bool replace,
const FunctionPrototype& prototype,
const std::string& return_type_str,
SqlSource sql) { … }
base::StatusOr<std::unique_ptr<RuntimeTable>>
PerfettoSqlEngine::CreateTableImpl(
const char* tag,
const std::string& name,
SqliteEngine::PreparedStatement source,
const std::vector<std::string>& column_names,
const std::vector<sql_argument::ArgumentDefinition>& schema,
CreateTableType create_table_type) { … }
base::Status PerfettoSqlEngine::ExecuteCreateTable(
const PerfettoSqlParser::CreateTable& create_table) { … }
base::Status PerfettoSqlEngine::ExecuteCreateView(
const PerfettoSqlParser::CreateView& create_view) { … }
base::Status PerfettoSqlEngine::EnableSqlFunctionMemoization(
const std::string& name) { … }
base::Status PerfettoSqlEngine::ExecuteInclude(
const PerfettoSqlParser::Include& include,
const PerfettoSqlParser& parser) { … }
base::Status PerfettoSqlEngine::ExecuteCreateIndex(
const PerfettoSqlParser::CreateIndex& index) { … }
base::Status PerfettoSqlEngine::ExecuteDropIndex(
const PerfettoSqlParser::DropIndex& index) { … }
base::Status PerfettoSqlEngine::IncludeModuleImpl(
sql_modules::RegisteredModule& module,
const std::string& key,
const PerfettoSqlParser& parser) { … }
base::Status PerfettoSqlEngine::IncludeFileImpl(
sql_modules::RegisteredModule::ModuleFile& file,
const std::string& key,
const PerfettoSqlParser& parser) { … }
base::Status PerfettoSqlEngine::ExecuteCreateFunction(
const PerfettoSqlParser::CreateFunction& cf) { … }
base::Status PerfettoSqlEngine::ExecuteCreateMacro(
const PerfettoSqlParser::CreateMacro& create_macro) { … }
base::StatusOr<std::vector<std::string>>
PerfettoSqlEngine::GetColumnNamesFromSelectStatement(
const SqliteEngine::PreparedStatement& stmt,
const char* tag) const { … }
base::StatusOr<std::vector<sql_argument::ArgumentDefinition>>
PerfettoSqlEngine::ValidateAndGetEffectiveSchema(
const std::vector<std::string>& column_names,
const std::vector<sql_argument::ArgumentDefinition>& schema,
const char* tag) const { … }
const RuntimeTable* PerfettoSqlEngine::GetRuntimeTableOrNull(
std::string_view name) const { … }
RuntimeTable* PerfettoSqlEngine::GetMutableRuntimeTableOrNull(
std::string_view name) { … }
const Table* PerfettoSqlEngine::GetStaticTableOrNull(
std::string_view name) const { … }
Table* PerfettoSqlEngine::GetMutableStaticTableOrNull(std::string_view name) { … }
}