Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.x profiling poc1 [DONOTMERGE] #4436

Open
wants to merge 9 commits into
base: v2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions include/ProxySQL_Profiler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef PROXYSQL_PROFILER
#define PROXYSQL_PROFILER

#include <string>
#include <unordered_map>
#include <mutex>



// _BLOK0 passes 0 as first argument. This means that the object WON'T measure time BUT it will generate a path
#define PROFILER1_BLOCK0(a) Profiler1 a(0,__FILE__,__LINE__,__func__)
// when _2 suffix is added, a user defined C string can be passed as argument instead of function name
#define PROFILER1_BLOCK0_2(a,b) Profiler1 a(0,__FILE__,__LINE__,b)
// _BLOK0 passes 0 as first argument. This means that the object WILL measure time AND it will generate a path
#define PROFILER1_BLOCK1(a) Profiler1 a(1,__FILE__,__LINE__,__func__)
// when _2 suffix is added, a user defined C string can be passed as argument instead of function name
#define PROFILER1_BLOCK1_2(a,b) Profiler1 a(1,__FILE__,__LINE__,b)

class CounterProfiling1 {
public:
unsigned long long cnt = 0;
unsigned long long tottime = 0;
CounterProfiling1(unsigned long long t) {
tottime = t;
cnt = 1;
}
void add(unsigned long long t) {
tottime += t;
cnt++;
}
};

class Profiler1 {
private:
int log = 0;
timespec begint;
timespec endt;
std::string prev_bt = "";
public:
Profiler1(int l, const char *__file, int __line, const char *__func);
~Profiler1();
};
#endif // PROXYSQL_PROFILER
1 change: 1 addition & 0 deletions include/cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
#include <stdio.h>
#include <map>
#include <unordered_map>
#include "ProxySQL_Profiler.hpp"
2 changes: 2 additions & 0 deletions include/proxysql_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ class ProxySQL_Admin {
void stats___mysql_gtid_executed();
void stats___mysql_client_host_cache(bool reset);

void stats___profiling1(bool reset);

// Update prometheus metrics
void p_stats___memory_metrics();
void p_update_stmt_metrics();
Expand Down
6 changes: 6 additions & 0 deletions include/proxysql_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ class ProxySQL_Node_Address;
#define PROXYSQL_STRUCTS
#define QUERY_DIGEST_BUF 128


struct __SQP_query_parser_t {
char buf[QUERY_DIGEST_BUF];
uint64_t digest;
Expand Down Expand Up @@ -766,6 +767,10 @@ EXTERN global_variables glovars;
//#endif

#ifdef PROXYSQL_EXTERN
#ifndef GLOBAL_PROXYSQL_PROFILING
#define GLOBAL_PROXYSQL_PROFILING
thread_local std::string thread_bt = "";
#endif // GLOBAL_PROXYSQL_PROFILING
#ifndef GLOBAL_DEFINED_OPTS_ENTRIES
#define GLOBAL_DEFINED_OPTS_ENTRIES
ProxySQL_GlobalVariables GloVars {};
Expand Down Expand Up @@ -940,6 +945,7 @@ __thread unsigned int g_seed;

#endif /* GLOBAL_DEFINED_HOSTGROUP */
#else
extern thread_local std::string thread_bt;
extern ProxySQL_GlobalVariables GloVars;
extern MySQL_HostGroups_Manager *MyHGM;
extern __thread char *mysql_thread___default_schema;
Expand Down
3 changes: 2 additions & 1 deletion lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ default: libproxysql.a
.PHONY: default

_OBJ_CXX := ProxySQL_GloVars.oo network.oo debug.oo configfile.oo Query_Cache.oo SpookyV2.oo MySQL_Authentication.oo gen_utils.oo sqlite3db.oo mysql_connection.oo MySQL_HostGroups_Manager.oo mysql_data_stream.oo MySQL_Thread.oo MySQL_Session.oo MySQL_Protocol.oo mysql_backend.oo Query_Processor.oo ProxySQL_Admin.oo ProxySQL_Config.oo ProxySQL_Restapi.oo MySQL_Monitor.oo MySQL_Logger.oo thread.oo MySQL_PreparedStatement.oo ProxySQL_Cluster.oo ClickHouse_Authentication.oo ClickHouse_Server.oo ProxySQL_Statistics.oo Chart_bundle_js.oo ProxySQL_HTTP_Server.oo ProxySQL_RESTAPI_Server.oo font-awesome.min.css.oo main-bundle.min.css.oo set_parser.oo MySQL_Variables.oo c_tokenizer.oo proxysql_utils.oo proxysql_coredump.oo proxysql_sslkeylog.oo \
proxysql_find_charset.oo ProxySQL_Poll.oo
proxysql_find_charset.oo ProxySQL_Poll.oo \
ProxySQL_Profiler.oo
OBJ_CXX := $(patsubst %,$(ODIR)/%,$(_OBJ_CXX))
HEADERS := ../include/*.h ../include/*.hpp

Expand Down
Loading
Loading