8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-30 19:23:03 +01:00
firebird-mirror/src/jrd/trace/TraceManager.h

229 lines
6.8 KiB
C
Raw Normal View History

2009-02-01 23:07:35 +01:00
/*
* PROGRAM: JRD Access Method
* MODULE: TraceManager.h
* DESCRIPTION: Trace API manager
*
* 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): ______________________________________.
*
* 2008 Khorsun Vladyslav
*/
#ifndef JRD_TRACEMANAGER_H
#define JRD_TRACEMANAGER_H
#include <time.h>
#include "../../jrd/ntrace.h"
#include "../../common/classes/array.h"
#include "../../common/classes/fb_string.h"
#include "../../common/classes/init.h"
#include "../../common/classes/locks.h"
#include "../../common/classes/ImplementHelper.h"
2009-02-01 23:07:35 +01:00
#include "../../jrd/trace/TraceConfigStorage.h"
#include "../../jrd/trace/TraceSession.h"
namespace Jrd {
class Database;
class Attachment;
class jrd_tra;
class Service;
2009-02-02 15:46:24 +01:00
class TraceManager
{
2009-02-01 23:07:35 +01:00
public:
/* Initializes plugins. */
explicit TraceManager(Attachment* in_att);
explicit TraceManager(Service* in_svc);
explicit TraceManager(const char* in_filename);
2009-02-01 23:07:35 +01:00
/* Finalize plugins. Called when database is closed by the engine */
~TraceManager();
static ConfigStorage* getStorage()
{ return storageInstance.getStorage(); }
2009-02-01 23:07:35 +01:00
static size_t pluginsCount()
{ return factories->getCount(); }
2009-04-04 18:39:31 +02:00
void event_attach(TraceConnection* connection, bool create_db,
2009-02-01 23:07:35 +01:00
ntrace_result_t att_result);
void event_detach(TraceConnection* connection, bool drop_db);
/* Start/end transaction */
2009-04-04 18:39:31 +02:00
void event_transaction_start(TraceConnection* connection, TraceTransaction* transaction,
2009-02-01 23:07:35 +01:00
size_t tpb_length, const ntrace_byte_t* tpb, ntrace_result_t tra_result);
2009-04-04 18:39:31 +02:00
void event_transaction_end(TraceConnection* connection, TraceTransaction* transaction,
2009-02-01 23:07:35 +01:00
bool commit, bool retain_context, ntrace_result_t tra_result);
2009-04-04 18:39:31 +02:00
void event_set_context(TraceConnection* connection,
2009-02-01 23:07:35 +01:00
TraceTransaction* transaction, TraceContextVariable* variable);
2009-04-04 18:39:31 +02:00
void event_proc_execute(TraceConnection* connection, TraceTransaction* transaction,
2009-02-01 23:07:35 +01:00
TraceProcedure* procedure, bool started, ntrace_result_t proc_result);
void event_trigger_execute(TraceConnection* connection, TraceTransaction* transaction,
TraceTrigger* trigger, bool started, ntrace_result_t trig_result);
void event_blr_compile(TraceConnection* connection,
2009-04-04 18:39:31 +02:00
TraceTransaction* transaction, TraceBLRStatement* statement,
2009-02-01 23:07:35 +01:00
ntrace_counter_t time_millis, ntrace_result_t req_result);
2009-04-04 18:39:31 +02:00
void event_blr_execute(TraceConnection* connection,
TraceTransaction* transaction, TraceBLRStatement* statement,
2009-02-01 23:07:35 +01:00
ntrace_result_t req_result);
void event_dyn_execute(TraceConnection* connection,
2009-04-04 18:39:31 +02:00
TraceTransaction* transaction, TraceDYNRequest* request,
2009-02-01 23:07:35 +01:00
ntrace_counter_t time_millis, ntrace_result_t req_result);
2009-04-04 18:39:31 +02:00
2009-02-01 23:07:35 +01:00
void event_service_attach(TraceService* service, ntrace_result_t att_result);
void event_service_start(TraceService* service,
size_t switches_length, const char* switches,
ntrace_result_t start_result);
void event_service_query(TraceService* service,
2009-04-04 18:39:31 +02:00
size_t send_item_length, const ntrace_byte_t* send_items,
2009-02-01 23:07:35 +01:00
size_t recv_item_length, const ntrace_byte_t* recv_items,
ntrace_result_t query_result);
void event_service_detach(TraceService* service, ntrace_result_t detach_result);
typedef ntrace_mask_t NotificationNeeds;
2009-02-01 23:07:35 +01:00
inline bool needs(TraceEvent e)
2009-02-01 23:07:35 +01:00
{
if (changeNumber != getStorage()->getChangeNumber())
2009-02-01 23:07:35 +01:00
update_sessions();
return trace_needs & (CONST64(1) << e);
2009-02-01 23:07:35 +01:00
}
/* DSQL-friendly routines to call Trace API hooks.
Needed because DSQL cannot include JRD for the current engine */
2009-02-02 15:46:24 +01:00
static bool need_dsql_prepare(Attachment* att);
static bool need_dsql_free(Attachment* att);
static bool need_dsql_execute(Attachment* att);
2009-02-01 23:07:35 +01:00
2009-04-04 18:39:31 +02:00
static void event_dsql_prepare(Attachment* att, jrd_tra* transaction, TraceSQLStatement* statement,
2009-02-01 23:07:35 +01:00
ntrace_counter_t time_millis, ntrace_result_t req_result);
2009-04-04 18:39:31 +02:00
static void event_dsql_free(Attachment* att, TraceSQLStatement* statement,
2009-02-01 23:07:35 +01:00
unsigned short option);
2009-04-04 18:39:31 +02:00
static void event_dsql_execute(Attachment* att, jrd_tra* transaction, TraceSQLStatement* statement,
2009-02-01 23:07:35 +01:00
bool started, ntrace_result_t req_result);
static void shutdown();
2009-02-01 23:07:35 +01:00
private:
Attachment* attachment;
2009-02-02 15:46:24 +01:00
Service* service;
2009-02-01 23:07:35 +01:00
const char* filename;
NotificationNeeds trace_needs;
// This structure should be POD-like to be stored in Array
struct FactoryInfo
2009-02-01 23:07:35 +01:00
{
FactoryInfo() : factory(NULL)
2009-02-01 23:07:35 +01:00
{
memset(name, 0, sizeof(name));
2009-02-01 23:07:35 +01:00
}
TraceFactory* factory;
char name[MAXPATHLEN];
};
2011-01-16 03:16:15 +01:00
class Factories : public Firebird::Array<FactoryInfo>
{
public:
2011-04-02 06:45:26 +02:00
explicit Factories(Firebird::MemoryPool& p)
: Firebird::Array<FactoryInfo>(p)
{ }
2011-01-16 03:16:15 +01:00
~Factories()
{
Firebird::PluginManagerInterfacePtr pi;
2011-01-16 03:16:15 +01:00
for (unsigned int i = 0; i < getCount(); ++i)
pi->releasePlugin(getElement(i).factory);
}
2009-02-01 23:07:35 +01:00
};
2011-01-16 03:16:15 +01:00
static Factories* factories;
static Firebird::GlobalPtr<Firebird::Mutex> init_factories_mtx;
static volatile bool init_factories;
2009-02-01 23:07:35 +01:00
2009-04-04 18:39:31 +02:00
struct SessionInfo
2009-02-01 23:07:35 +01:00
{
FactoryInfo* factory_info;
TracePlugin* plugin;
2009-02-02 15:46:24 +01:00
ULONG ses_id;
2009-02-01 23:07:35 +01:00
2009-02-02 15:46:24 +01:00
static ULONG generate(const void*, const SessionInfo& item)
2009-02-01 23:07:35 +01:00
{ return item.ses_id; }
};
class Sessions : public Firebird::SortedArray<SessionInfo, Firebird::EmptyStorage<SessionInfo>, ULONG, SessionInfo>
{
public:
2011-04-02 06:45:26 +02:00
explicit Sessions(MemoryPool& p)
: Firebird::SortedArray<SessionInfo, Firebird::EmptyStorage<SessionInfo>, ULONG, SessionInfo>(p)
{ }
~Sessions()
{
for (unsigned int i = 0; i < getCount(); ++i)
{
getElement(i).plugin->release();
}
}
};
Sessions trace_sessions;
2009-02-01 23:07:35 +01:00
void init();
void load_plugins();
2009-02-01 23:07:35 +01:00
void update_sessions();
void update_session(const Firebird::TraceSession& session);
bool check_result(TracePlugin* plugin, const char* module, const char* function, bool result);
2009-02-01 23:07:35 +01:00
/* DSQL statement lifecycle. To be moved to public and used directly when DSQL becomes a part of JRD */
2009-04-04 18:39:31 +02:00
void event_dsql_prepare(TraceConnection* connection, TraceTransaction* transaction,
TraceSQLStatement* statement,
2009-02-01 23:07:35 +01:00
ntrace_counter_t time_millis, ntrace_result_t req_result);
void event_dsql_free(TraceConnection* connection,
TraceSQLStatement* statement, unsigned short option);
2009-04-04 18:39:31 +02:00
void event_dsql_execute(TraceConnection* connection, TraceTransaction* transaction,
TraceSQLStatement* statement,
2009-02-01 23:07:35 +01:00
bool started, ntrace_result_t req_result);
static StorageInstance storageInstance;
ULONG changeNumber;
2009-02-01 23:07:35 +01:00
};
}
#endif