8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-31 12:43:02 +01:00
firebird-mirror/src/jrd/ntrace.h

392 lines
12 KiB
C
Raw Normal View History

/*
* PROGRAM: JRD Access Method
* MODULE: ntrace.h
* DESCRIPTION: Trace API header
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed AS IS,
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights
* and limitations under the License.
*
* The Original Code was created by Nickolay Samofatov
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2004 Nickolay Samofatov <nickolay@broadviewsoftware.com>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*
2009-02-01 23:10:12 +01:00
* 2008 Khorsun Vladyslav
*
*/
2009-02-01 23:10:12 +01:00
#ifndef FIREBIRD_NTRACE_H
#define FIREBIRD_NTRACE_H
2009-02-01 23:10:12 +01:00
// to define SINT64
#include "../jrd/common.h"
2009-11-27 09:34:34 +01:00
// Version of API, used for version fields in TracePlugin structure
2009-02-01 23:10:12 +01:00
#define NTRACE_VERSION 2
2009-02-01 23:10:12 +01:00
// plugin entry point
2009-04-03 12:49:07 +02:00
static const char* const NTRACE_ATTACH = "trace_create";
2009-11-27 09:34:34 +01:00
// Database objects
2009-02-01 23:10:12 +01:00
struct PerformanceInfo;
class TraceConnection
{
public:
virtual int getConnectionID() = 0;
virtual const char* getDatabaseName() = 0;
virtual int getProcessID() = 0;
virtual const char* getUserName() = 0;
virtual const char* getRoleName() = 0;
virtual const char* getCharSet() = 0;
2009-02-01 23:10:12 +01:00
virtual const char* getRemoteProtocol() = 0;
virtual const char* getRemoteAddress() = 0;
virtual int getRemoteProcessID() = 0;
virtual const char* getRemoteProcessName() = 0;
virtual ~TraceConnection() { }
2009-02-01 23:10:12 +01:00
};
2009-02-02 04:35:52 +01:00
enum ntrace_tra_isolation_t
{
2009-02-01 23:10:12 +01:00
tra_iso_consistency = 1,
tra_iso_concurrency,
tra_iso_read_committed_recver,
tra_iso_read_committed_norecver
2009-02-02 04:35:52 +01:00
};
2009-02-01 23:10:12 +01:00
class TraceTransaction
{
public:
virtual int getTransactionID() = 0;
virtual bool getReadOnly() = 0;
virtual int getWait() = 0;
virtual ntrace_tra_isolation_t getIsolation() = 0;
virtual PerformanceInfo* getPerf() = 0;
virtual ~TraceTransaction() { }
2009-02-01 23:10:12 +01:00
};
typedef int ntrace_relation_t;
class TraceParams
{
public:
virtual size_t getCount() = 0;
virtual const struct dsc* getParam(size_t idx) = 0;
virtual ~TraceParams() { }
2009-02-01 23:10:12 +01:00
};
class TraceStatement
{
public:
virtual int getStmtID() = 0;
virtual PerformanceInfo* getPerf() = 0;
virtual ~TraceStatement() { }
2009-02-01 23:10:12 +01:00
};
class TraceSQLStatement : public TraceStatement
{
public:
virtual const char* getText() = 0;
virtual const char* getPlan() = 0;
virtual TraceParams* getInputs() = 0;
virtual const char* getTextUTF8() = 0;
2009-02-01 23:10:12 +01:00
};
class TraceBLRStatement : public TraceStatement
{
public:
virtual const unsigned char* getData() = 0;
2009-02-01 23:10:12 +01:00
virtual size_t getDataLength() = 0;
virtual const char* getText() = 0;
};
class TraceDYNRequest
{
public:
virtual const unsigned char* getData() = 0;
2009-02-01 23:10:12 +01:00
virtual size_t getDataLength() = 0;
virtual const char* getText() = 0;
virtual ~TraceDYNRequest() { }
2009-02-01 23:10:12 +01:00
};
class TraceContextVariable
{
public:
2009-04-04 18:39:31 +02:00
virtual const char* getNameSpace() = 0;
2009-02-01 23:10:12 +01:00
virtual const char* getVarName() = 0;
virtual const char* getVarValue() = 0;
virtual ~TraceContextVariable() { }
2009-02-01 23:10:12 +01:00
};
class TraceProcedure
{
public:
virtual const char* getProcName() = 0;
virtual TraceParams* getInputs() = 0;
virtual PerformanceInfo* getPerf() = 0;
virtual ~TraceProcedure() { }
2009-02-01 23:10:12 +01:00
};
class TraceTrigger
{
public:
virtual const char* getTriggerName() = 0;
virtual const char* getRelationName() = 0;
virtual int getAction() = 0;
virtual int getWhich() = 0;
virtual PerformanceInfo* getPerf() = 0;
virtual ~TraceTrigger() { }
2009-02-01 23:10:12 +01:00
};
typedef void* ntrace_service_t;
2009-02-01 23:10:12 +01:00
class TraceService
{
public:
virtual ntrace_service_t getServiceID() = 0;
2009-02-01 23:10:12 +01:00
virtual const char* getServiceMgr() = 0;
virtual const char* getServiceName() = 0;
2009-02-01 23:10:12 +01:00
virtual int getProcessID() = 0;
virtual const char* getUserName() = 0;
virtual const char* getRoleName() = 0;
virtual const char* getRemoteProtocol() = 0;
virtual const char* getRemoteAddress() = 0;
virtual int getRemoteProcessID() = 0;
virtual const char* getRemoteProcessName() = 0;
virtual ~TraceService() { }
2009-02-01 23:10:12 +01:00
};
2009-11-27 09:34:34 +01:00
// Plugin-specific argument. Passed by the engine to each hook
typedef void* ntrace_object_t;
2009-11-27 09:34:34 +01:00
// Structure version
typedef int ntrace_version_t;
2009-11-27 09:34:34 +01:00
// Boolean type
typedef int ntrace_boolean_t;
2009-11-27 09:34:34 +01:00
// Performance counter
2009-02-01 23:10:12 +01:00
typedef SINT64 ntrace_counter_t;
2009-11-27 09:34:34 +01:00
// Used for arrays with binary data
typedef unsigned char ntrace_byte_t;
2009-02-01 23:10:12 +01:00
2009-11-27 09:34:34 +01:00
// Event completion: 0 - successful, 1 - unsuccessful, 2 - unauthorized access
2009-02-02 04:35:52 +01:00
enum ntrace_result_t
{
2009-02-01 23:10:12 +01:00
res_successful = 0,
res_failed = 1,
res_unauthorized = 2
2009-02-02 04:35:52 +01:00
};
2009-02-01 23:10:12 +01:00
2009-02-02 04:35:52 +01:00
enum ntrace_trigger_type_t
{
2009-02-01 23:10:12 +01:00
trg_all = 0,
trg_before = 1,
trg_after = 2
2009-02-02 04:35:52 +01:00
};
2009-02-01 23:10:12 +01:00
const int DBB_max_rel_count = 8; // must be the same as DBB_max_count from jrd.h
2009-11-27 09:34:34 +01:00
// Performance counters for entire database
2009-02-01 23:10:12 +01:00
enum {
DBB_fetches_count = 0,
DBB_reads_count,
DBB_marks_count,
DBB_writes_count,
DBB_max_dbb_count
};
2009-11-27 09:34:34 +01:00
// Performance counters for individual table
2009-02-02 04:35:52 +01:00
struct TraceCounts
{
2009-11-27 09:34:34 +01:00
ntrace_relation_t trc_relation_id; // Relation ID
const char* trc_relation_name; // Relation name
const ntrace_counter_t* trc_counters; // Pointer to allow easy addition of new counters
};
2009-11-27 09:34:34 +01:00
// Performance statistics for operation
2009-04-04 18:39:31 +02:00
struct PerformanceInfo
2008-12-22 10:00:05 +01:00
{
2009-11-27 09:34:34 +01:00
ntrace_counter_t pin_time; // Total operation time in milliseconds
ntrace_counter_t* pin_counters; // Pointer to allow easy addition of new counters
2009-02-01 23:10:12 +01:00
2009-11-27 09:34:34 +01:00
size_t pin_count; // Number of relations involved in analysis
struct TraceCounts* pin_tables; // Pointer to array with table stats
2009-02-01 23:10:12 +01:00
ntrace_counter_t pin_records_fetched; // records fetched from statement/procedure
};
2009-11-27 09:34:34 +01:00
// Get error string for hook failure that happened
2009-02-01 23:10:12 +01:00
typedef const char* (*ntrace_get_error_t)(const struct TracePlugin* tpl_plugin);
2009-11-27 09:34:34 +01:00
// Finalize plugin interface for this particular database
2009-02-01 23:10:12 +01:00
typedef ntrace_boolean_t (*ntrace_shutdown_t)(const struct TracePlugin* tpl_plugin);
2004-04-10 21:41:25 +02:00
2009-11-27 09:34:34 +01:00
// Create/close attachment
2009-02-01 23:10:12 +01:00
typedef ntrace_boolean_t (*ntrace_event_attach_t)(const struct TracePlugin* tpl_plugin,
TraceConnection* connection, ntrace_boolean_t create_db, ntrace_result_t att_result);
typedef ntrace_boolean_t (*ntrace_event_detach_t)(const struct TracePlugin* tpl_plugin,
TraceConnection* connection, ntrace_boolean_t drop_db);
2009-11-27 09:34:34 +01:00
// Start/end transaction
2009-02-01 23:10:12 +01:00
typedef ntrace_boolean_t (*ntrace_event_transaction_start_t)(const struct TracePlugin* tpl_plugin,
TraceConnection* connection, TraceTransaction* transaction,
size_t tpb_length, const ntrace_byte_t* tpb, ntrace_result_t tra_result);
typedef ntrace_boolean_t (*ntrace_event_transaction_end_t)(const struct TracePlugin* tpl_plugin,
TraceConnection* connection, TraceTransaction* transaction,
ntrace_boolean_t commit, ntrace_boolean_t retain_context, ntrace_result_t tra_result);
2009-11-27 09:34:34 +01:00
// Assignment to context variables
2009-02-01 23:10:12 +01:00
typedef ntrace_boolean_t (*ntrace_event_set_context_t)(const struct TracePlugin* tpl_plugin,
TraceConnection* connection, TraceTransaction* transaction, TraceContextVariable* variable);
2009-11-27 09:34:34 +01:00
// Stored procedure and triggers executing
2009-02-01 23:10:12 +01:00
typedef ntrace_boolean_t (*ntrace_event_proc_execute_t)(const struct TracePlugin* tpl_plugin,
TraceConnection* connection, TraceTransaction* transaction, TraceProcedure* procedure,
bool started, ntrace_result_t proc_result);
typedef ntrace_boolean_t (*ntrace_event_trigger_execute_t)(const struct TracePlugin* tpl_plugin,
2009-04-04 18:39:31 +02:00
TraceConnection* connection, TraceTransaction* transaction, TraceTrigger* trigger,
2009-02-01 23:10:12 +01:00
bool started, ntrace_result_t trig_result);
2009-11-27 09:34:34 +01:00
// DSQL statement lifecycle
2009-02-01 23:10:12 +01:00
typedef ntrace_boolean_t (*ntrace_event_dsql_prepare_t)(const struct TracePlugin* tpl_plugin,
TraceConnection* connection, TraceTransaction* transaction,
TraceSQLStatement* statement, ntrace_counter_t time_millis, ntrace_result_t req_result);
typedef ntrace_boolean_t (*ntrace_event_dsql_free_t)(const struct TracePlugin* tpl_plugin,
TraceConnection* connection, TraceSQLStatement* statement, unsigned short option);
typedef ntrace_boolean_t (*ntrace_event_dsql_execute_t)(const struct TracePlugin* tpl_plugin,
2009-04-04 18:39:31 +02:00
TraceConnection* connection, TraceTransaction* transaction, TraceSQLStatement* statement,
2009-02-01 23:10:12 +01:00
bool started, ntrace_result_t req_result);
2009-11-27 09:34:34 +01:00
// BLR requests
2009-02-01 23:10:12 +01:00
typedef ntrace_boolean_t (*ntrace_event_blr_compile_t)(const struct TracePlugin* tpl_plugin,
TraceConnection* connection, TraceTransaction* transaction,
TraceBLRStatement* statement, ntrace_counter_t time_millis, ntrace_result_t req_result);
typedef ntrace_boolean_t (*ntrace_event_blr_execute_t)(const struct TracePlugin* tpl_plugin,
TraceConnection* connection, TraceTransaction* transaction,
TraceBLRStatement* statement, ntrace_result_t req_result);
2009-11-27 09:34:34 +01:00
// DYN requests
2009-02-01 23:10:12 +01:00
typedef ntrace_boolean_t (*ntrace_event_dyn_execute_t)(const struct TracePlugin* tpl_plugin,
TraceConnection* connection, TraceTransaction* transaction,
TraceDYNRequest* request, ntrace_counter_t time_millis,
ntrace_result_t req_result);
2009-11-27 09:34:34 +01:00
// Using the services
2009-02-01 23:10:12 +01:00
typedef ntrace_boolean_t (*ntrace_event_service_attach_t)(const struct TracePlugin* tpl_plugin,
TraceService* service, ntrace_result_t att_result);
typedef ntrace_boolean_t (*ntrace_event_service_start_t)(const struct TracePlugin* tpl_plugin,
TraceService* service, size_t switches_length, const char* switches,
ntrace_result_t start_result);
typedef ntrace_boolean_t (*ntrace_event_service_query_t)(const struct TracePlugin* tpl_plugin,
TraceService* service, size_t send_item_length,
const ntrace_byte_t* send_items, size_t recv_item_length,
const ntrace_byte_t* recv_items, ntrace_result_t query_result);
typedef ntrace_boolean_t (*ntrace_event_service_detach_t)(const struct TracePlugin* tpl_plugin,
TraceService* service, ntrace_result_t detach_result);
2009-11-27 09:34:34 +01:00
// API of trace plugin. Used to deliver notifications for each database
2009-04-04 18:39:31 +02:00
struct TracePlugin
2008-12-22 10:00:05 +01:00
{
2009-11-27 09:34:34 +01:00
// API version
ntrace_version_t tpl_version;
2009-11-27 09:34:34 +01:00
// Driver-specific object pointer
ntrace_object_t tpl_object;
2009-11-27 09:34:34 +01:00
// Destroy plugin. Called when database is closed by the engine
2009-02-01 23:10:12 +01:00
ntrace_shutdown_t tpl_shutdown;
2004-04-10 21:41:25 +02:00
2009-11-27 09:34:34 +01:00
// Function to return error string for hook failure
ntrace_get_error_t tpl_get_error;
2004-04-10 21:41:25 +02:00
2009-11-27 09:34:34 +01:00
// Events supported
ntrace_event_attach_t tpl_event_attach;
ntrace_event_detach_t tpl_event_detach;
ntrace_event_transaction_start_t tpl_event_transaction_start;
ntrace_event_transaction_end_t tpl_event_transaction_end;
2009-02-01 23:10:12 +01:00
ntrace_event_proc_execute_t tpl_event_proc_execute;
ntrace_event_trigger_execute_t tpl_event_trigger_execute;
ntrace_event_set_context_t tpl_event_set_context;
ntrace_event_dsql_prepare_t tpl_event_dsql_prepare;
ntrace_event_dsql_free_t tpl_event_dsql_free;
2009-02-01 23:10:12 +01:00
ntrace_event_dsql_execute_t tpl_event_dsql_execute;
2009-02-01 23:10:12 +01:00
ntrace_event_blr_compile_t tpl_event_blr_compile;
ntrace_event_blr_execute_t tpl_event_blr_execute;
ntrace_event_dyn_execute_t tpl_event_dyn_execute;
ntrace_event_service_attach_t tpl_event_service_attach;
ntrace_event_service_start_t tpl_event_service_start;
ntrace_event_service_query_t tpl_event_service_query;
ntrace_event_service_detach_t tpl_event_service_detach;
2009-11-27 09:34:34 +01:00
// Some space for future extension of Trace API interface,
// must be zero-initialized by the plugin
2009-02-01 23:10:12 +01:00
void* reserved_for_interface[24];
2009-11-27 09:34:34 +01:00
// Some space which may be freely used by Trace API driver.
// If driver needs more space it may allocate and return larger TracePlugin structure.
2009-02-01 23:10:12 +01:00
void* reserved_for_driver[1];
};
class TraceLogWriter
{
public:
virtual size_t write(const void* buf, size_t size) = 0;
virtual void release() = 0;
virtual ~TraceLogWriter() { }
2009-02-01 23:10:12 +01:00
};
class TraceInitInfo
{
public:
virtual const char* getConfigText() = 0;
virtual int getTraceSessionID() = 0;
virtual const char* getTraceSessionName() = 0;
virtual const char* getFirebirdRootDirectory() = 0;
2009-02-01 23:10:12 +01:00
virtual const char* getDatabaseName() = 0;
virtual TraceConnection* getConnection() = 0;
virtual TraceLogWriter* getLogWriter() = 0;
virtual ~TraceInitInfo() { }
};
2009-11-27 09:34:34 +01:00
// Trace API plugin entrypoint type
2009-02-01 23:10:12 +01:00
typedef ntrace_boolean_t (*ntrace_attach_t)(const TraceInitInfo* initInfo, const TracePlugin** plugin);
2009-02-02 04:35:52 +01:00
#endif // FIREBIRD_NTRACE_H