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

Added MON$CALL_STACK plus some minor monitoring-related changes.

This commit is contained in:
dimitr 2007-03-05 07:50:23 +00:00
parent d902a022cb
commit d31f946fba
8 changed files with 144 additions and 51 deletions

View File

@ -355,5 +355,14 @@ enum fids {
f_mon_stmt_tra_id,
f_mon_stmt_state,
f_mon_stmt_timestamp,
f_mon_stmt_sql_text
f_mon_stmt_sql_text,
f_mon_call_id = 0,
f_mon_call_stmt_id,
f_mon_call_caller_id,
f_mon_call_name,
f_mon_call_type,
f_mon_call_timestamp,
f_mon_call_src_line,
f_mon_call_src_column
};

View File

@ -379,6 +379,8 @@ DatabaseSnapshot::DatabaseSnapshot(thread_db* tdbb, MemoryPool& pool, jrd_tra* t
allocBuffer(tdbb, pool, rel_mon_transactions);
RecordBuffer* stmt_buffer =
allocBuffer(tdbb, pool, rel_mon_statements);
RecordBuffer* call_buffer =
allocBuffer(tdbb, pool, rel_mon_calls);
Database* dbb = tdbb->tdbb_database;
fb_assert(dbb);
@ -449,6 +451,9 @@ DatabaseSnapshot::DatabaseSnapshot(thread_db* tdbb, MemoryPool& pool, jrd_tra* t
case rel_mon_statements:
buffer = stmt_buffer;
break;
case rel_mon_calls:
buffer = call_buffer;
break;
default:
fb_assert(false);
}
@ -686,6 +691,19 @@ const char* DatabaseSnapshot::checkNull(int rid, int fid, const char* source, si
break;
}
break;
case rel_mon_calls:
switch (fid) {
case f_mon_call_caller_id:
case f_mon_call_type:
case f_mon_call_src_line:
case f_mon_call_src_column:
return (*(SLONG*) source) ? source : NULL;
case f_mon_call_name:
return length ? source : NULL;
default:
break;
}
break;
default:
break;
}
@ -754,6 +772,22 @@ ClumpletReader* DatabaseSnapshot::dumpData(thread_db* tdbb, bool locksmith)
putRequest(request, *writer);
}
}
// Call stack information
for (jrd_tra* transaction = attachment->att_transactions;
transaction; transaction = transaction->tra_next)
{
for (jrd_req* request = transaction->tra_requests;
request; request = request->req_tra_next)
{
if (!(request->req_flags & (req_internal | req_sys_trigger)) &&
request->req_caller)
{
putCall(request, *writer);
}
}
}
}
if (locksmith)
@ -861,14 +895,14 @@ void DatabaseSnapshot::putAttachment(Attachment* attachment,
writer.insertByte(TAG_RECORD, rel_mon_attachments);
int temp = att_s_idle;
int temp = mon_state_idle;
for (jrd_tra* transaction_itr = attachment->att_transactions;
transaction_itr; transaction_itr = transaction_itr->tra_next)
{
if (transaction_itr->tra_requests)
{
temp = att_s_active;
temp = mon_state_active;
break;
}
}
@ -922,7 +956,7 @@ void DatabaseSnapshot::putTransaction(jrd_tra* new_transaction,
writer.insertInt(f_mon_tra_att_id,
new_transaction->tra_attachment->att_attachment_id);
// state
temp = new_transaction->tra_requests ? tra_s_active : tra_s_idle;
temp = new_transaction->tra_requests ? mon_state_active : mon_state_idle;
writer.insertInt(f_mon_tra_state, temp);
// timestamp
writer.insertBytes(f_mon_tra_timestamp,
@ -965,8 +999,6 @@ void DatabaseSnapshot::putRequest(jrd_req* request,
writer.insertByte(TAG_RECORD, rel_mon_statements);
int temp;
// request id
writer.insertInt(f_mon_stmt_id, request->req_id);
// attachment id
@ -977,24 +1009,77 @@ void DatabaseSnapshot::putRequest(jrd_req* request,
else {
writer.insertInt(f_mon_stmt_att_id, 0);
}
// transaction id
if (request->req_transaction) {
writer.insertInt(f_mon_stmt_tra_id,
request->req_transaction->tra_number);
// state, transaction ID, timestamp
if (request->req_flags & req_active) {
writer.insertInt(f_mon_stmt_state, mon_state_active);
const int tra_id = request->req_transaction ?
request->req_transaction->tra_number : 0;
writer.insertInt(f_mon_stmt_tra_id, tra_id);
writer.insertBytes(f_mon_stmt_timestamp,
(UCHAR*) &request->req_timestamp.value(),
sizeof(ISC_TIMESTAMP));
}
else {
writer.insertInt(f_mon_stmt_state, mon_state_idle);
writer.insertInt(f_mon_stmt_tra_id, 0);
ISC_TIMESTAMP empty = {0, 0};
writer.insertBytes(f_mon_stmt_timestamp,
(UCHAR*) &empty,
sizeof(ISC_TIMESTAMP));
}
// timestamp
writer.insertBytes(f_mon_stmt_timestamp,
(UCHAR*) &request->req_timestamp.value(),
sizeof(ISC_TIMESTAMP));
// state
if (request->req_flags & req_active)
temp = stmt_s_active;
else
temp = stmt_s_idle;
writer.insertInt(f_mon_stmt_state, temp);
// sql text
writer.insertString(f_mon_stmt_sql_text, request->req_sql_text);
}
void DatabaseSnapshot::putCall(jrd_req* request,
ClumpletWriter& writer)
{
fb_assert(request);
jrd_req* statement = request->req_caller;
while (statement->req_caller)
statement = statement->req_caller;
fb_assert(statement);
writer.insertByte(TAG_RECORD, rel_mon_calls);
// call id
writer.insertInt(f_mon_call_id, request->req_id);
// statement id
writer.insertInt(f_mon_call_stmt_id,
statement->req_id);
// caller id
if (statement == request->req_caller) {
writer.insertInt(f_mon_call_caller_id, 0);
}
else {
writer.insertInt(f_mon_call_caller_id,
request->req_caller->req_id);
}
// object name/type
if (request->req_procedure) {
writer.insertString(f_mon_call_name,
request->req_procedure->prc_name.c_str());
writer.insertInt(f_mon_call_type, obj_procedure);
}
else if (!request->req_trg_name.isEmpty()) {
writer.insertString(f_mon_call_name,
request->req_trg_name.c_str());
writer.insertInt(f_mon_call_type, obj_trigger);
}
else {
// we should never be here...
fb_assert(false);
// ... but just in case it happened...
writer.insertString(f_mon_call_name, "");
writer.insertInt(f_mon_call_type, 0);
}
// timestamp
writer.insertBytes(f_mon_call_timestamp,
(UCHAR*) &request->req_timestamp.value(),
sizeof(ISC_TIMESTAMP));
// source line/column
writer.insertInt(f_mon_call_src_line, request->req_src_line);
writer.insertInt(f_mon_call_src_column, request->req_src_column);
}

View File

@ -99,6 +99,7 @@ private:
static void putAttachment(Attachment*, Firebird::ClumpletWriter&);
static void putTransaction(jrd_tra*, Firebird::ClumpletWriter&);
static void putRequest(jrd_req*, Firebird::ClumpletWriter&);
static void putCall(jrd_req*, Firebird::ClumpletWriter&);
static Firebird::Mutex initMutex;
static SharedMemory* dump;

View File

@ -190,21 +190,9 @@ enum prm_mech_t {
// states
enum att_state_t {
att_s_idle = 0,
att_s_active = 1,
att_s_killed = 2
};
enum tra_state_t {
tra_s_idle = 0,
tra_s_active = 1
};
enum stmt_state_t {
stmt_s_idle = 0,
stmt_s_active = 1,
stmt_s_killed = 2
enum mon_state_t {
mon_state_idle = 0,
mon_state_active = 1
};
// shutdown modes

View File

@ -125,6 +125,7 @@
FIELD(fld_att_id , nam_att_id , dtype_long , sizeof(SLONG) , 0 , 0, NULL)
FIELD(fld_stmt_id , nam_stmt_id , dtype_long , sizeof(SLONG) , 0 , 0, NULL)
FIELD(fld_call_id , nam_call_id , dtype_long , sizeof(SLONG) , 0 , 0, NULL)
FIELD(fld_pid , nam_pid , dtype_long , sizeof(SLONG) , 0 , 0, NULL)
FIELD(fld_state , nam_state , dtype_short , sizeof(SSHORT), 0 , 0, NULL)
@ -144,3 +145,4 @@
FIELD(fld_debug_info , nam_debug_info , dtype_blob , BLOB_SIZE , isc_blob_debug_info , 0, NULL)
FIELD(fld_prm_mechanism , nam_prm_mechanism , dtype_short , sizeof(SSHORT), 0 , 0, NULL)
FIELD(fld_src_info , nam_src_info , dtype_long , sizeof(SLONG) , 0 , 0, NULL)

View File

@ -214,6 +214,7 @@ NAME("RDB$VIEW_RELATIONS", nam_v_relations)
NAME("RDB$VIEW_SOURCE", nam_v_source)
NAME("RDB$ATTACHMENT_ID", nam_att_id)
NAME("RDB$CALL_ID", nam_call_id)
NAME("RDB$COUNTER", nam_counter)
NAME("RDB$ISOLATION_MODE", nam_iso_mode)
NAME("RDB$LOCK_TIMEOUT", nam_lock_timeout)
@ -231,13 +232,15 @@ NAME("RDB$SWEEP_INTERVAL", nam_sweep_int)
NAME("RDB$DEBUG_INFO", nam_debug_info)
NAME("RDB$PARAMETER_MECHANISM", nam_prm_mechanism)
NAME("RDB$SOURCE_INFO", nam_src_info)
NAME("MON$ATTACHMENTS", nam_mon_attachments)
NAME("MON$ATTACHMENT_ID", nam_mon_att_id)
NAME("MON$ATTACHMENT_NAME", nam_mon_att_name)
NAME("MON$ATTACHMENT_STATE", nam_mon_att_state)
NAME("MON$AUTO_COMMIT", nam_mon_auto_commit)
NAME("MON$AUTO_UNDO", nam_mon_auto_undo)
NAME("MON$CALL_ID", nam_mon_call_id)
NAME("MON$CALL_STACK", nam_mon_calls)
NAME("MON$CALLER_ID", nam_mon_caller_id)
NAME("MON$CHARACTER_SET_ID", nam_mon_charset_id)
NAME("MON$CREATION_DATE", nam_mon_created)
@ -251,6 +254,8 @@ NAME("MON$NEXT_TRANSACTION", nam_mon_nt)
NAME("MON$PAGE_SIZE", nam_mon_page_size)
NAME("MON$READ_ONLY", nam_mon_read_only)
NAME("MON$RESERVE_SPACE", nam_mon_res_space)
NAME("MON$OBJECT_NAME", nam_mon_obj_name)
NAME("MON$OBJECT_TYPE", nam_mon_obj_type)
NAME("MON$ODS_MAJOR", nam_mon_ods_major)
NAME("MON$ODS_MINOR", nam_mon_ods_minor)
NAME("MON$OLDEST_ACTIVE", nam_mon_oat)
@ -265,16 +270,17 @@ NAME("MON$REMOTE_PROTOCOL", nam_mon_remote_proto)
NAME("MON$ROLE", nam_mon_role)
NAME("MON$SERVER_PID", nam_mon_server_pid)
NAME("MON$SHUTDOWN_MODE", nam_mon_shut_mode)
NAME("MON$SOURCE_LINE", nam_mon_src_line)
NAME("MON$SOURCE_COLUMN", nam_mon_src_column)
NAME("MON$SQL_TEXT", nam_mon_sql_text)
NAME("MON$SQL_DIALECT", nam_mon_dialect)
NAME("MON$STATE", nam_mon_state)
NAME("MON$STATEMENTS", nam_mon_statements)
NAME("MON$STATEMENT_ID", nam_mon_stmt_id)
NAME("MON$STATEMENT_STATE", nam_mon_stmt_state)
NAME("MON$SWEEP_INTERVAL", nam_mon_sweep_int)
NAME("MON$SYSTEM_FLAG", nam_mon_sys_flag)
NAME("MON$TIMESTAMP", nam_mon_timestamp)
NAME("MON$TOP_TRANSACTION", nam_mon_top)
NAME("MON$TRANSACTIONS", nam_mon_transactions)
NAME("MON$TRANSACTION_ID", nam_mon_tra_id)
NAME("MON$TRANSACTION_STATE", nam_mon_tra_state)
NAME("MON$USER", nam_mon_user)

View File

@ -367,7 +367,7 @@ END_RELATION
RELATION(nam_mon_attachments, rel_mon_attachments, ODS_11_1, rel_virtual)
FIELD(f_mon_att_id, nam_mon_att_id, fld_att_id, 0, 0, 0, 0)
FIELD(f_mon_att_server_pid, nam_mon_server_pid, fld_pid, 0, 0, 0, 0)
FIELD(f_mon_att_state, nam_mon_att_state, fld_state, 0, 0, 0, 0)
FIELD(f_mon_att_state, nam_mon_state, fld_state, 0, 0, 0, 0)
FIELD(f_mon_att_name, nam_mon_att_name, fld_file_name, 0, 0, 0, 0)
FIELD(f_mon_att_user, nam_mon_user, fld_user, 0, 0, 0, 0)
FIELD(f_mon_att_role, nam_mon_role, fld_user, 0, 0, 0, 0)
@ -381,7 +381,7 @@ END_RELATION
RELATION(nam_mon_transactions, rel_mon_transactions, ODS_11_1, rel_virtual)
FIELD(f_mon_tra_id, nam_mon_tra_id, fld_trans_id, 0, 0, 0, 0)
FIELD(f_mon_tra_att_id, nam_mon_att_id, fld_att_id, 0, 0, 0, 0)
FIELD(f_mon_tra_state, nam_mon_tra_state, fld_state, 0, 0, 0, 0)
FIELD(f_mon_tra_state, nam_mon_state, fld_state, 0, 0, 0, 0)
FIELD(f_mon_tra_timestamp, nam_mon_timestamp, fld_time, 0, 0, 0, 0)
FIELD(f_mon_tra_top, nam_mon_top, fld_trans_id, 0, 0, 0, 0)
FIELD(f_mon_tra_oit, nam_mon_oit, fld_trans_id, 0, 0, 0, 0)
@ -396,7 +396,17 @@ RELATION(nam_mon_statements, rel_mon_statements, ODS_11_1, rel_virtual)
FIELD(f_mon_stmt_id, nam_mon_stmt_id, fld_stmt_id, 0, 0, 0, 0)
FIELD(f_mon_stmt_att_id, nam_mon_att_id, fld_att_id, 0, 0, 0, 0)
FIELD(f_mon_stmt_tra_id, nam_mon_tra_id, fld_trans_id, 0, 0, 0, 0)
FIELD(f_mon_stmt_state, nam_mon_stmt_state, fld_state, 0, 0, 0, 0)
FIELD(f_mon_stmt_state, nam_mon_state, fld_state, 0, 0, 0, 0)
FIELD(f_mon_stmt_timestamp, nam_mon_timestamp, fld_time, 0, 0, 0, 0)
FIELD(f_mon_stmt_sql_text, nam_mon_sql_text, fld_source, 0, 0, 0, 0)
END_RELATION
RELATION(nam_mon_calls, rel_mon_calls, ODS_11_1, rel_virtual)
FIELD(f_mon_call_id, nam_mon_call_id, fld_call_id, 0, 0, 0, 0)
FIELD(f_mon_call_stmt_id, nam_mon_stmt_id, fld_stmt_id, 0, 0, 0, 0)
FIELD(f_mon_call_caller_id, nam_mon_caller_id, fld_call_id, 0, 0, 0, 0)
FIELD(f_mon_call_name, nam_mon_obj_name, fld_gnr_name, 0, 0, 0, 0)
FIELD(f_mon_call_type, nam_mon_obj_type, fld_obj_type, 0, 0, 0, 0)
FIELD(f_mon_call_timestamp, nam_mon_timestamp, fld_time, 0, 0, 0, 0)
FIELD(f_mon_call_src_line, nam_mon_src_line, fld_src_info, 0, 0, 0, 0)
FIELD(f_mon_call_src_column, nam_mon_src_column, fld_src_info, 0, 0, 0, 0)
END_RELATION

View File

@ -112,16 +112,8 @@ TYPE ("EXECUTABLE", prc_executable, nam_prc_type)
TYPE("NORMAL", prm_mech_normal, nam_prm_mechanism)
TYPE("TYPE OF", prm_mech_type_of, nam_prm_mechanism)
TYPE ("IDLE", att_s_idle, nam_mon_att_state)
TYPE ("ACTIVE", att_s_active, nam_mon_att_state)
TYPE ("KILLED", att_s_killed, nam_mon_att_state)
TYPE ("IDLE", tra_s_idle, nam_mon_tra_state)
TYPE ("ACTIVE", tra_s_active, nam_mon_tra_state)
TYPE ("IDLE", stmt_s_idle, nam_mon_stmt_state)
TYPE ("ACTIVE", stmt_s_active, nam_mon_stmt_state)
TYPE ("KILLED", stmt_s_killed, nam_mon_stmt_state)
TYPE ("IDLE", mon_state_idle, nam_mon_state)
TYPE ("ACTIVE", mon_state_active, nam_mon_state)
TYPE ("ONLINE", shut_mode_online, nam_mon_shut_mode)
TYPE ("MULTI_USER_SHUTDOWN", shut_mode_multi, nam_mon_shut_mode)