From 950bcd880915912ec966a2e733943a0cca64f716 Mon Sep 17 00:00:00 2001 From: hvlad Date: Tue, 1 Dec 2009 14:45:36 +0000 Subject: [PATCH] Implement improvement CORE-2767 : Add ability to the trace plugin to configure traced services events on per-service name basis --- src/utilities/ntrace/TracePluginImpl.cpp | 52 ++++++++++++++++++++++-- src/utilities/ntrace/TracePluginImpl.h | 3 ++ src/utilities/ntrace/fbtrace.conf | 38 ++++++++++++++++- src/utilities/ntrace/paramtable.h | 4 +- 4 files changed, 90 insertions(+), 7 deletions(-) diff --git a/src/utilities/ntrace/TracePluginImpl.cpp b/src/utilities/ntrace/TracePluginImpl.cpp index 44e39a1d5c..fd3577ab7c 100644 --- a/src/utilities/ntrace/TracePluginImpl.cpp +++ b/src/utilities/ntrace/TracePluginImpl.cpp @@ -411,7 +411,7 @@ void TracePluginImpl::logRecordStmt(const char* action, TraceConnection* connect void TracePluginImpl::logRecordServ(const char* action, TraceService* service) { - //const ntrace_service_t svc_id = service->getServiceID(); // Unused + const ntrace_service_t svc_id = service->getServiceID(); bool reg = false; while (true) @@ -421,7 +421,7 @@ void TracePluginImpl::logRecordServ(const char* action, TraceService* service) ReadLockGuard lock(servicesLock); ServicesTree::Accessor accessor(&services); - if (accessor.locate(service->getServiceID())) + if (accessor.locate(svc_id)) { record.insert(0, *accessor.current().description); break; @@ -431,7 +431,7 @@ void TracePluginImpl::logRecordServ(const char* action, TraceService* service) if (reg) { string temp; - temp.printf("\tService %p, " NEWLINE, service->getServiceID()); + temp.printf("\tService %p, " NEWLINE, svc_id); record.insert(0, temp); break; } @@ -1622,6 +1622,7 @@ void TracePluginImpl::register_service(TraceService* service) serv_data.description->printf("\t%s, (Service %p, %s, %s%s)" NEWLINE, service->getServiceMgr(), serv_data.id, username.c_str(), remote_address.c_str(), remote_process.c_str()); + serv_data.enabled = true; // Adjust the list of services { @@ -1630,6 +1631,45 @@ void TracePluginImpl::register_service(TraceService* service) } } + +bool TracePluginImpl::checkServiceFilter(TraceService* service, bool started) +{ + ReadLockGuard lock(servicesLock); + + ServiceData *data = NULL; + ServicesTree::Accessor accessor(&services); + if (accessor.locate(service->getServiceID())) + data = &accessor.current(); + + if (data && !started) + return data->enabled; + + const char* svcName = service->getServiceName(); + const int svcNameLen = strlen(svcName); + bool enabled = true; + + if (config.include_filter.hasData()) + { + include_matcher->reset(); + include_matcher->process((const UCHAR*) svcName, svcNameLen); + enabled = include_matcher->result(); + } + + if (enabled && config.exclude_filter.hasData()) + { + exclude_matcher->reset(); + exclude_matcher->process((const UCHAR*) svcName, svcNameLen); + enabled = !exclude_matcher->result(); + } + + if (data) { + data->enabled = enabled; + } + + return enabled; +} + + void TracePluginImpl::log_event_service_attach(TraceService* service, ntrace_result_t att_result) { @@ -1661,6 +1701,9 @@ void TracePluginImpl::log_event_service_start(TraceService* service, { if (config.log_services) { + if (!checkServiceFilter(service, true)) + return; + const char* event_type; switch (start_result) { @@ -1712,6 +1755,9 @@ void TracePluginImpl::log_event_service_query(TraceService* service, { if (config.log_services && config.log_service_query) { + if (!checkServiceFilter(service, false)) + return; + const char* tmp = service->getServiceName(); if (tmp && *tmp) { record.printf("\t\"%s\"" NEWLINE, tmp); diff --git a/src/utilities/ntrace/TracePluginImpl.h b/src/utilities/ntrace/TracePluginImpl.h index 5af7c439ef..e875223ed5 100644 --- a/src/utilities/ntrace/TracePluginImpl.h +++ b/src/utilities/ntrace/TracePluginImpl.h @@ -118,6 +118,7 @@ public: { ntrace_service_t id; Firebird::string* description; + bool enabled; // Deallocate memory used by objects hanging off this structure void deallocate_references() @@ -185,6 +186,8 @@ private: void register_sql_statement(TraceSQLStatement* statement); void register_blr_statement(TraceBLRStatement* statement); void register_service(TraceService* service); + + bool checkServiceFilter(TraceService* service, bool started); // Write message to text log file void logRecord(const char* action); diff --git a/src/utilities/ntrace/fbtrace.conf b/src/utilities/ntrace/fbtrace.conf index 252db2ffe1..d282a562b8 100644 --- a/src/utilities/ntrace/fbtrace.conf +++ b/src/utilities/ntrace/fbtrace.conf @@ -32,10 +32,12 @@ # SQL query filters. # - # Only SQL statements falling under given regular expression are reported in the log. + # Only SQL statements falling under given regular expression are reported + # in the log. #include_filter - # SQL statements falling under given regular expression are NOT reported in the log. + # SQL statements falling under given regular expression are NOT reported + # in the log. #exclude_filter @@ -122,6 +124,28 @@ # default services section # +# List of names of currently existing Firebirds services (to use with service +# filters below) : +# Backup Database +# Restore Database +# Repair Database +# Add User +# Delete User +# Modify User +# Display User +# Database Properties +# Database Stats +# Get Log File +# Incremental Backup Database +# Incremental Restore Database +# Start Trace Session +# Stop Trace Session +# Suspend Trace Session +# Resume Trace Session +# List Trace Sessions +# Set Domain Admins Mapping to RDB$ADMIN +# Drop Domain Admins Mapping to RDB$ADMIN +# # Do we trace services events or not enabled false @@ -133,6 +157,16 @@ # log's rotation max_log_size 0 + # Services filters. + # + # Only services which names falling under given regular expression are + # reported in the log. + #include_filter + + # Services which names falling under given regular expression are NOT + # reported in the log. + #exclude_filter + # Put service attach, detach and start records log_services false diff --git a/src/utilities/ntrace/paramtable.h b/src/utilities/ntrace/paramtable.h index 43551f1115..a3c37f040e 100644 --- a/src/utilities/ntrace/paramtable.h +++ b/src/utilities/ntrace/paramtable.h @@ -32,13 +32,13 @@ // DATABASE_PARAMS, SERVICE_PARAMS +STR_PARAMETER(include_filter, "") +STR_PARAMETER(exclude_filter, "") PATH_PARAMETER(log_filename, "") BOOL_PARAMETER(enabled, false) UINT_PARAMETER(max_log_size, 0) #ifdef DATABASE_PARAMS -STR_PARAMETER(include_filter, "") -STR_PARAMETER(exclude_filter, "") BOOL_PARAMETER(log_connections, false) UINT_PARAMETER(connection_id, 0) BOOL_PARAMETER(log_transactions, false)