From a86fcd7808c4f97e9bce376df5d8a8d068d8cdc1 Mon Sep 17 00:00:00 2001 From: lilong Date: Fri, 26 Apr 2024 13:07:16 +0800 Subject: [PATCH] =?UTF-8?q?gms=5Fprofiler=E6=8F=92=E4=BB=B6=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contrib/CMakeLists.txt | 2 ++ contrib/Makefile | 3 ++- contrib/gms_profiler/CMakeLists.txt | 24 +++++++++++++++++++++ contrib/gms_profiler/gms_profiler--1.0.sql | 14 +++++++++--- contrib/gms_profiler/gms_profiler.cpp | 25 ++++++++++++++++++++++ contrib/gms_profiler/gms_profiler.h | 2 ++ 6 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 contrib/gms_profiler/CMakeLists.txt diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 8f8db20bf..a7917aa1c 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -24,6 +24,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/gc_fdw ${CMAKE_CURRENT_SOURCE_DIR}/ndpplugin ${CMAKE_CURRENT_SOURCE_DIR}/spq_plugin + ${CMAKE_CURRENT_SOURCE_DIR}/gms_profiler ) add_subdirectory(hstore) @@ -48,3 +49,4 @@ add_subdirectory(ndpplugin) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/spq_plugin) add_subdirectory(spq_plugin) endif() +add_subdirectory(gms_profiler) diff --git a/contrib/Makefile b/contrib/Makefile index f1f57913c..91eda6c9a 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -56,7 +56,8 @@ SUBDIRS = \ unaccent \ vacuumlo \ security_plugin \ - ndpplugin + ndpplugin \ + gms_profiler ifeq ($(with_openssl),yes) SUBDIRS += sslinfo diff --git a/contrib/gms_profiler/CMakeLists.txt b/contrib/gms_profiler/CMakeLists.txt new file mode 100644 index 000000000..c3b72cc11 --- /dev/null +++ b/contrib/gms_profiler/CMakeLists.txt @@ -0,0 +1,24 @@ +#This is the main CMAKE for build all gms_profiler. +# gms_profiler.so + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} TGT_gms_profiler_SRC) + +SET(TGT_gms_profiler_INC + ${CMAKE_CURRENT_SOURCE_DIR} +) + +set(gms_profiler_DEF_OPTIONS ${MACRO_OPTIONS} -DNDP_CLIENT -DGlobalCache) +set(gms_profiler_COMPILE_OPTIONS ${OPTIMIZE_OPTIONS} ${OS_OPTIONS} ${PROTECT_OPTIONS} ${WARNING_OPTIONS} ${LIB_SECURE_OPTIONS} ${CHECK_OPTIONS}) +set(gms_profiler_LINK_OPTIONS ${LIB_LINK_OPTIONS}) + +add_shared_libtarget(gms_profiler TGT_gms_profiler_SRC TGT_gms_profiler_INC "${gms_profiler_DEF_OPTIONS}" "${gms_profiler_COMPILE_OPTIONS}" "${gms_profiler_LINK_OPTIONS}") +set_target_properties(gms_profiler PROPERTIES PREFIX "") + +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_profiler.control + DESTINATION share/postgresql/extension/ +) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_profiler--1.0.sql + DESTINATION share/postgresql/extension/ +) + +install(TARGETS gms_profiler DESTINATION lib/postgresql) diff --git a/contrib/gms_profiler/gms_profiler--1.0.sql b/contrib/gms_profiler/gms_profiler--1.0.sql index fd7b1c5f4..2e78ef3d1 100644 --- a/contrib/gms_profiler/gms_profiler--1.0.sql +++ b/contrib/gms_profiler/gms_profiler--1.0.sql @@ -5,17 +5,25 @@ CREATE SCHEMA gms_profiler; -CREATE or REPLACE FUNCTION gms_profiler.start_profiler(IN run_comment varchar2 DEFAULT '', IN run_comment1 varchar2 DEFAULT '') -returns binary_integer +CREATE or REPLACE FUNCTION gms_profiler.start_profiler(IN run_comment varchar2 DEFAULT '', IN run_comment1 varchar2 DEFAULT '', OUT run_result binary_integer) AS 'MODULE_PATHNAME', 'start_profiler' LANGUAGE C VOLATILE NOT FENCED; +CREATE or REPLACE FUNCTION gms_profiler.start_profiler_1(IN run_comment varchar2 DEFAULT '', IN run_comment1 varchar2 DEFAULT '') +returns void +AS 'MODULE_PATHNAME', 'start_profiler_1' +LANGUAGE C VOLATILE NOT FENCED; + CREATE or REPLACE FUNCTION gms_profiler.start_profiler_ext(IN run_comment varchar2 DEFAULT '' , IN run_comment1 varchar2 DEFAULT '', OUT run_number binary_integer, OUT run_result binary_integer) -returns record AS 'MODULE_PATHNAME', 'start_profiler_ext' LANGUAGE C VOLATILE NOT FENCED; +CREATE or REPLACE FUNCTION gms_profiler.start_profiler_ext_1(IN run_comment varchar2 DEFAULT '' , +IN run_comment1 varchar2 DEFAULT '', OUT run_number binary_integer) +AS 'MODULE_PATHNAME', 'start_profiler_ext_1' +LANGUAGE C VOLATILE NOT FENCED; + CREATE or REPLACE FUNCTION gms_profiler.stop_profiler() returns binary_integer AS 'MODULE_PATHNAME', 'stop_profiler' diff --git a/contrib/gms_profiler/gms_profiler.cpp b/contrib/gms_profiler/gms_profiler.cpp index 943426989..2d13af075 100644 --- a/contrib/gms_profiler/gms_profiler.cpp +++ b/contrib/gms_profiler/gms_profiler.cpp @@ -26,7 +26,9 @@ PG_MODULE_MAGIC; PG_FUNCTION_INFO_V1(start_profiler); +PG_FUNCTION_INFO_V1(start_profiler_1); PG_FUNCTION_INFO_V1(start_profiler_ext); +PG_FUNCTION_INFO_V1(start_profiler_ext_1); PG_FUNCTION_INFO_V1(stop_profiler); PG_FUNCTION_INFO_V1(flush_data); PG_FUNCTION_INFO_V1(pause_profiler); @@ -1125,6 +1127,16 @@ Datum start_profiler(PG_FUNCTION_ARGS) PG_RETURN_INT32(result); } +Datum start_profiler_1(PG_FUNCTION_ARGS) +{ + uint32 runid = 0; + int result; + + result = start_profiler_internal(fcinfo, &runid); + + PG_RETURN_VOID(); +} + Datum start_profiler_ext(PG_FUNCTION_ARGS) { uint32 runid = 0; @@ -1138,6 +1150,19 @@ Datum start_profiler_ext(PG_FUNCTION_ARGS) return make_profiler_result(0, result); } +Datum start_profiler_ext_1(PG_FUNCTION_ARGS) +{ + uint32 runid = 0; + int result; + + result = start_profiler_internal(fcinfo, &runid); + + if (result == PROFILER_ERROR_OK) + PG_RETURN_INT32(runid); + else + PG_RETURN_INT32(0); +} + Datum stop_profiler(PG_FUNCTION_ARGS) { ProfilerContext *profiler_cxt = get_session_context(); diff --git a/contrib/gms_profiler/gms_profiler.h b/contrib/gms_profiler/gms_profiler.h index 3f423b74d..03db2817c 100644 --- a/contrib/gms_profiler/gms_profiler.h +++ b/contrib/gms_profiler/gms_profiler.h @@ -86,7 +86,9 @@ typedef struct ProfilerUnitHashEntry * External declarations */ extern "C" Datum start_profiler(PG_FUNCTION_ARGS); +extern "C" Datum start_profiler_1(PG_FUNCTION_ARGS); extern "C" Datum start_profiler_ext(PG_FUNCTION_ARGS); +extern "C" Datum start_profiler_ext_1(PG_FUNCTION_ARGS); extern "C" Datum stop_profiler(PG_FUNCTION_ARGS); extern "C" Datum flush_data(PG_FUNCTION_ARGS); extern "C" Datum pause_profiler(PG_FUNCTION_ARGS);