Skip to content

Commit

Permalink
Done CORE-1750.
Browse files Browse the repository at this point in the history
  • Loading branch information
dyemanov committed Feb 20, 2008
1 parent fc3bbe9 commit 2537653
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 22 deletions.
5 changes: 4 additions & 1 deletion src/include/gen/ids.h
Expand Up @@ -440,4 +440,7 @@
const USHORT f_mon_rec_purges = 8;
const USHORT f_mon_rec_expunges = 9;


const USHORT f_mon_ctx_var_att_id = 0;
const USHORT f_mon_ctx_var_tra_id = 1;
const USHORT f_mon_ctx_var_name = 2;
const USHORT f_mon_ctx_var_value = 3;
65 changes: 45 additions & 20 deletions src/jrd/DatabaseSnapshot.cpp
Expand Up @@ -413,6 +413,8 @@ DatabaseSnapshot::DatabaseSnapshot(thread_db* tdbb, MemoryPool& pool)
allocBuffer(tdbb, pool, rel_mon_io_stats);
RecordBuffer* const rec_stat_buffer =
allocBuffer(tdbb, pool, rel_mon_rec_stats);
RecordBuffer* const ctx_var_buffer =
allocBuffer(tdbb, pool, rel_mon_ctx_vars);

Database* const dbb = tdbb->getDatabase();
fb_assert(dbb);
Expand Down Expand Up @@ -512,6 +514,9 @@ DatabaseSnapshot::DatabaseSnapshot(thread_db* tdbb, MemoryPool& pool)
case rel_mon_rec_stats:
buffer = rec_stat_buffer;
break;
case rel_mon_ctx_vars:
buffer = ctx_var_buffer;
break;
default:
fb_assert(false);
}
Expand Down Expand Up @@ -831,13 +836,17 @@ ClumpletReader* DatabaseSnapshot::dumpData(thread_db* tdbb, bool broadcast)
if (broadcast || attachment == self_attachment)
{
putAttachment(attachment, *writer, dbb->generateId());
putContextVars(attachment->att_context_vars, *writer,
attachment->att_attachment_id, true);

// Transaction information

for (transaction = attachment->att_transactions;
transaction; transaction = transaction->tra_next)
{
putTransaction(transaction, *writer, dbb->generateId());
putContextVars(transaction->tra_context_vars, *writer,
transaction->tra_number, false);
}

// Request information
Expand Down Expand Up @@ -979,7 +988,7 @@ void DatabaseSnapshot::putDatabase(const Database* database,
writer.insertInt(f_mon_db_backup_state, temp);
// statistics
writer.insertBigInt(f_mon_db_stat_id, getGlobalId(stat_id));
putStatistics(&database->dbb_stats, writer, stat_id, stat_database);
putStatistics(database->dbb_stats, writer, stat_id, stat_database);
}


Expand Down Expand Up @@ -1038,7 +1047,7 @@ void DatabaseSnapshot::putAttachment(const Attachment* attachment,
writer.insertInt(f_mon_att_gc, temp);
// statistics
writer.insertBigInt(f_mon_att_stat_id, getGlobalId(stat_id));
putStatistics(&attachment->att_stats, writer, stat_id, stat_attachment);
putStatistics(attachment->att_stats, writer, stat_id, stat_attachment);
}


Expand Down Expand Up @@ -1093,7 +1102,7 @@ void DatabaseSnapshot::putTransaction(const jrd_tra* transaction,
writer.insertInt(f_mon_tra_auto_undo, temp);
// statistics
writer.insertBigInt(f_mon_tra_stat_id, getGlobalId(stat_id));
putStatistics(&transaction->tra_stats, writer, stat_id, stat_transaction);
putStatistics(transaction->tra_stats, writer, stat_id, stat_transaction);
}


Expand Down Expand Up @@ -1137,7 +1146,7 @@ void DatabaseSnapshot::putRequest(const jrd_req* request,
writer.insertString(f_mon_stmt_sql_text, request->req_sql_text);
// statistics
writer.insertBigInt(f_mon_stmt_stat_id, getGlobalId(stat_id));
putStatistics(&request->req_stats, writer, stat_id, stat_statement);
putStatistics(request->req_stats, writer, stat_id, stat_statement);
}


Expand Down Expand Up @@ -1193,16 +1202,14 @@ void DatabaseSnapshot::putCall(const jrd_req* request,
writer.insertInt(f_mon_call_src_column, request->req_src_column);
// statistics
writer.insertBigInt(f_mon_call_stat_id, getGlobalId(stat_id));
putStatistics(&request->req_stats, writer, stat_id, stat_call);
putStatistics(request->req_stats, writer, stat_id, stat_call);
}

void DatabaseSnapshot::putStatistics(const RuntimeStatistics* statistics,
void DatabaseSnapshot::putStatistics(const RuntimeStatistics& statistics,
Firebird::ClumpletWriter& writer,
int stat_id,
int stat_group)
{
fb_assert(statistics);

// statistics id
const SINT64 id = getGlobalId(stat_id);

Expand All @@ -1211,32 +1218,50 @@ void DatabaseSnapshot::putStatistics(const RuntimeStatistics* statistics,
writer.insertBigInt(f_mon_io_stat_id, id);
writer.insertInt(f_mon_io_stat_group, stat_group);
writer.insertBigInt(f_mon_io_page_reads,
statistics->getValue(RuntimeStatistics::PAGE_READS));
statistics.getValue(RuntimeStatistics::PAGE_READS));
writer.insertBigInt(f_mon_io_page_writes,
statistics->getValue(RuntimeStatistics::PAGE_WRITES));
statistics.getValue(RuntimeStatistics::PAGE_WRITES));
writer.insertBigInt(f_mon_io_page_fetches,
statistics->getValue(RuntimeStatistics::PAGE_FETCHES));
statistics.getValue(RuntimeStatistics::PAGE_FETCHES));
writer.insertBigInt(f_mon_io_page_marks,
statistics->getValue(RuntimeStatistics::PAGE_MARKS));
statistics.getValue(RuntimeStatistics::PAGE_MARKS));

// logical I/O statistics
writer.insertByte(TAG_RECORD, rel_mon_rec_stats);
writer.insertBigInt(f_mon_rec_stat_id, id);
writer.insertInt(f_mon_rec_stat_group, stat_group);
writer.insertBigInt(f_mon_rec_seq_reads,
statistics->getValue(RuntimeStatistics::RECORD_SEQ_READS));
statistics.getValue(RuntimeStatistics::RECORD_SEQ_READS));
writer.insertBigInt(f_mon_rec_idx_reads,
statistics->getValue(RuntimeStatistics::RECORD_IDX_READS));
statistics.getValue(RuntimeStatistics::RECORD_IDX_READS));
writer.insertBigInt(f_mon_rec_inserts,
statistics->getValue(RuntimeStatistics::RECORD_INSERTS));
statistics.getValue(RuntimeStatistics::RECORD_INSERTS));
writer.insertBigInt(f_mon_rec_updates,
statistics->getValue(RuntimeStatistics::RECORD_UPDATES));
statistics.getValue(RuntimeStatistics::RECORD_UPDATES));
writer.insertBigInt(f_mon_rec_deletes,
statistics->getValue(RuntimeStatistics::RECORD_DELETES));
statistics.getValue(RuntimeStatistics::RECORD_DELETES));
writer.insertBigInt(f_mon_rec_backouts,
statistics->getValue(RuntimeStatistics::RECORD_BACKOUTS));
statistics.getValue(RuntimeStatistics::RECORD_BACKOUTS));
writer.insertBigInt(f_mon_rec_purges,
statistics->getValue(RuntimeStatistics::RECORD_PURGES));
statistics.getValue(RuntimeStatistics::RECORD_PURGES));
writer.insertBigInt(f_mon_rec_expunges,
statistics->getValue(RuntimeStatistics::RECORD_EXPUNGES));
statistics.getValue(RuntimeStatistics::RECORD_EXPUNGES));
}

void DatabaseSnapshot::putContextVars(Firebird::StringMap& variables,
Firebird::ClumpletWriter& writer,
int object_id, bool is_attachment)
{
for (bool found = variables.getFirst(); found; found = variables.getNext())
{
writer.insertByte(TAG_RECORD, rel_mon_ctx_vars);

if (is_attachment)
writer.insertInt(f_mon_ctx_var_att_id, object_id);
else
writer.insertInt(f_mon_ctx_var_tra_id, object_id);

writer.insertString(f_mon_ctx_var_name, variables.current()->first);
writer.insertString(f_mon_ctx_var_value, variables.current()->second);
}
}
3 changes: 2 additions & 1 deletion src/jrd/DatabaseSnapshot.h
Expand Up @@ -125,7 +125,8 @@ class DatabaseSnapshot {
static void putTransaction(const jrd_tra*, Firebird::ClumpletWriter&, int);
static void putRequest(const jrd_req*, Firebird::ClumpletWriter&, int);
static void putCall(const jrd_req*, Firebird::ClumpletWriter&, int);
static void putStatistics(const RuntimeStatistics*, Firebird::ClumpletWriter&, int, int);
static void putStatistics(const RuntimeStatistics&, Firebird::ClumpletWriter&, int, int);
static void putContextVars(Firebird::StringMap&, Firebird::ClumpletWriter&, int, bool);

static Firebird::GlobalPtr<Firebird::Mutex> initMutex;
static SharedMemory* dump;
Expand Down
3 changes: 3 additions & 0 deletions src/jrd/fields.h
Expand Up @@ -149,3 +149,6 @@
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)

FIELD(fld_ctx_var_name , nam_ctx_var_name , dtype_varying , 80 , 0 , 0, NULL)
FIELD(fld_ctx_var_value , nam_ctx_var_value , dtype_varying , 255 , 0 , 0, NULL)
5 changes: 5 additions & 0 deletions src/jrd/names.h
Expand Up @@ -48,6 +48,8 @@ NAME("RDB$CONSTRAINT_NAME", nam_con_name)
NAME("RDB$CONSTRAINT_TYPE", nam_con_type)
NAME("RDB$CONST_NAME_UQ", nam_con_uq)
NAME("RDB$CONTEXT_NAME", nam_context)
NAME("RDB$CONTEXT_VAR_NAME", nam_ctx_var_name)
NAME("RDB$CONTEXT_VAR_VALUE", nam_ctx_var_value)
NAME("RDB$DATABASE", nam_database)
NAME("RDB$DBKEY_LENGTH", nam_key_length)
NAME("RDB$DEFAULT_CLASS", nam_def_class)
Expand Down Expand Up @@ -247,6 +249,7 @@ 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$CONTEXT_VARIABLES", nam_mon_ctx_vars)
NAME("MON$CREATION_DATE", nam_mon_created)
NAME("MON$DATABASE", nam_mon_database)
NAME("MON$DATABASE_NAME", nam_mon_db_name)
Expand Down Expand Up @@ -305,3 +308,5 @@ NAME("MON$TOP_TRANSACTION", nam_mon_top)
NAME("MON$TRANSACTIONS", nam_mon_transactions)
NAME("MON$TRANSACTION_ID", nam_mon_tra_id)
NAME("MON$USER", nam_mon_user)
NAME("MON$VARIABLE_NAME", nam_mon_var_name)
NAME("MON$VARIABLE_VALUE", nam_mon_var_value)
6 changes: 6 additions & 0 deletions src/jrd/relations.h
Expand Up @@ -439,3 +439,9 @@ RELATION(nam_mon_rec_stats, rel_mon_rec_stats, ODS_11_1, rel_virtual)
FIELD(f_mon_rec_purges, nam_mon_rec_purges, fld_counter, 0, 0, 0, 0)
FIELD(f_mon_rec_expunges, nam_mon_rec_expunges, fld_counter, 0, 0, 0, 0)
END_RELATION
RELATION(nam_mon_ctx_vars, rel_mon_ctx_vars, ODS_11_2, rel_virtual)
FIELD(f_mon_ctx_vars_att_id, nam_mon_att_id, fld_att_id, 0, 0, 0, 0)
FIELD(f_mon_ctx_vars_tra_id, nam_mon_tra_id, fld_trans_id, 0, 0, 0, 0)
FIELD(f_mon_ctx_vars_name, nam_mon_var_name, fld_ctx_var_name, 0, 0, 0, 0)
FIELD(f_mon_ctx_vars_value, nam_mon_var_value, fld_ctx_var_value, 0, 0, 0, 0)
END_RELATION

0 comments on commit 2537653

Please sign in to comment.