|
3 | 3 | #include "duckdb/catalog/default/default_types.hpp" |
4 | 4 | #include "duckdb/common/arrow/arrow.hpp" |
5 | 5 | #include "duckdb/common/enums/file_compression_type.hpp" |
| 6 | +#include "duckdb/common/enums/profiler_format.hpp" |
6 | 7 | #include "duckdb/common/printer.hpp" |
7 | 8 | #include "duckdb/common/types.hpp" |
8 | 9 | #include "duckdb/common/types/vector.hpp" |
@@ -285,6 +286,9 @@ static void InitializeConnectionMethods(py::class_<DuckDBPyConnection, shared_pt |
285 | 286 | py::arg("extension"), py::kw_only(), py::arg("force_install") = false, py::arg("repository") = py::none(), |
286 | 287 | py::arg("repository_url") = py::none(), py::arg("version") = py::none()); |
287 | 288 | m.def("load_extension", &DuckDBPyConnection::LoadExtension, "Load an installed extension", py::arg("extension")); |
| 289 | + m.def("get_profiling_information", &DuckDBPyConnection::GetProfilingInformation, "Get profiling information for a query", py::arg("format") = "json"); |
| 290 | + m.def("enable_profiling", &DuckDBPyConnection::EnableProfiling, "Enable profiling for subsequent queries"); |
| 291 | + m.def("disable_profiling", &DuckDBPyConnection::DisableProfiling, "Disable profiling for subsequent queries"); |
288 | 292 | } // END_OF_CONNECTION_METHODS |
289 | 293 |
|
290 | 294 | void DuckDBPyConnection::UnregisterFilesystem(const py::str &name) { |
@@ -331,6 +335,39 @@ py::list DuckDBPyConnection::ListFilesystems() { |
331 | 335 | return names; |
332 | 336 | } |
333 | 337 |
|
| 338 | +py::str DuckDBPyConnection::GetProfilingInformation(const py::str &format) { |
| 339 | + // We want to expose ProfilerPrintFormat as a string to Python users |
| 340 | + ProfilerPrintFormat format_enum; |
| 341 | + if (format == "query_tree") { |
| 342 | + format_enum = ProfilerPrintFormat::QUERY_TREE; |
| 343 | + } else if (format == "json") { |
| 344 | + format_enum = ProfilerPrintFormat::JSON; |
| 345 | + } else if (format == "query_tree_optimizer") { |
| 346 | + format_enum = ProfilerPrintFormat::QUERY_TREE_OPTIMIZER; |
| 347 | + } else if (format == "no_output") { |
| 348 | + format_enum = ProfilerPrintFormat::NO_OUTPUT; |
| 349 | + } else if (format == "html") { |
| 350 | + format_enum = ProfilerPrintFormat::HTML; |
| 351 | + } else if (format == "graphviz") { |
| 352 | + format_enum = ProfilerPrintFormat::GRAPHVIZ; |
| 353 | + } else { |
| 354 | + throw InvalidInputException("Invalid ProfilerPrintFormat string: " + std::string(format) + ". Valid options are: query_tree, json, query_tree_optimizer, no_output, html, graphviz."); |
| 355 | + } |
| 356 | + auto &connection = con.GetConnection(); |
| 357 | + py::str profiling_info = connection.GetProfilingInformation(format_enum); |
| 358 | + return profiling_info; |
| 359 | +} |
| 360 | + |
| 361 | +void DuckDBPyConnection::EnableProfiling() { |
| 362 | + auto &connection = con.GetConnection(); |
| 363 | + connection.EnableProfiling(); |
| 364 | +} |
| 365 | + |
| 366 | +void DuckDBPyConnection::DisableProfiling() { |
| 367 | + auto &connection = con.GetConnection(); |
| 368 | + connection.DisableProfiling(); |
| 369 | +} |
| 370 | + |
334 | 371 | py::list DuckDBPyConnection::ExtractStatements(const string &query) { |
335 | 372 | py::list result; |
336 | 373 | auto &connection = con.GetConnection(); |
|
0 commit comments