8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 20:43:03 +01:00

Implement improvement CORE-2767 : Add ability to the trace plugin to configure traced services events on per-service name basis

This commit is contained in:
hvlad 2009-12-01 14:45:36 +00:00
parent 76fc6fbdd0
commit 950bcd8809
4 changed files with 90 additions and 7 deletions

View File

@ -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, <unknown, bug?>" NEWLINE, service->getServiceID());
temp.printf("\tService %p, <unknown, bug?>" 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);

View File

@ -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);

View File

@ -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
#
<services>
# 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

View File

@ -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)