From cf8ff493bccd14a5d4e3cdc3a0e9d3fab6f6f5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 10 Oct 2019 08:36:43 +0300 Subject: [PATCH] Add query canonicalization profiling A small helper program like this helps figure out performance problems with the function. --- server/core/test/CMakeLists.txt | 2 + server/core/test/profile_get_canonical.cc | 46 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 server/core/test/profile_get_canonical.cc diff --git a/server/core/test/CMakeLists.txt b/server/core/test/CMakeLists.txt index 049b9d8c8..b250ae18e 100644 --- a/server/core/test/CMakeLists.txt +++ b/server/core/test/CMakeLists.txt @@ -1,4 +1,5 @@ add_executable(profile_trxboundaryparser profile_trxboundaryparser.cc) +add_executable(profile_get_canonical profile_get_canonical.cc) add_executable(test_adminusers test_adminusers.cc) add_executable(test_atomic test_atomic.cc) add_executable(test_buffer test_buffer.cc) @@ -26,6 +27,7 @@ add_executable(test_utils test_utils.cc) add_executable(test_session_track test_session_track.cc) target_link_libraries(profile_trxboundaryparser maxscale-common) +target_link_libraries(profile_get_canonical maxscale-common) target_link_libraries(test_adminusers maxscale-common) target_link_libraries(test_atomic maxscale-common) target_link_libraries(test_buffer maxscale-common) diff --git a/server/core/test/profile_get_canonical.cc b/server/core/test/profile_get_canonical.cc new file mode 100644 index 000000000..069770203 --- /dev/null +++ b/server/core/test/profile_get_canonical.cc @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016 MariaDB Corporation Ab + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file and at www.mariadb.com/bsl11. + * + * Change Date: 2022-01-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2 or later of the General + * Public License. + */ + +#include +#include +#include +#include +#include + +using Clock = std::chrono::steady_clock; +using std::chrono::duration_cast; +using std::chrono::milliseconds; + +int main(int argc, char* argv[]) +{ + int ITERATIONS = 10000000; + + for (std::string line; std::getline(std::cin, line);) + { + GWBUF* buf = modutil_create_query(line.c_str()); + auto start = Clock::now(); + + for (int i = 0; i < ITERATIONS; i++) + { + auto str = mxs::get_canonical(buf); + } + + auto end = Clock::now(); + gwbuf_free(buf); + + std::cout << line << "\n" + << duration_cast(end - start).count() << "ms\n\n"; + } + + return 0; +}