diff --git a/src/include/gen/ids.h b/src/include/gen/ids.h index 227104857a..8e770f1683 100644 --- a/src/include/gen/ids.h +++ b/src/include/gen/ids.h @@ -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; diff --git a/src/jrd/DatabaseSnapshot.cpp b/src/jrd/DatabaseSnapshot.cpp index 06c5368ea8..25b27055f7 100644 --- a/src/jrd/DatabaseSnapshot.cpp +++ b/src/jrd/DatabaseSnapshot.cpp @@ -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); @@ -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); } @@ -831,6 +836,8 @@ 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 @@ -838,6 +845,8 @@ ClumpletReader* DatabaseSnapshot::dumpData(thread_db* tdbb, bool broadcast) transaction; transaction = transaction->tra_next) { putTransaction(transaction, *writer, dbb->generateId()); + putContextVars(transaction->tra_context_vars, *writer, + transaction->tra_number, false); } // Request information @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); @@ -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); + } } diff --git a/src/jrd/DatabaseSnapshot.h b/src/jrd/DatabaseSnapshot.h index 51d3f3dacd..74497fe407 100644 --- a/src/jrd/DatabaseSnapshot.h +++ b/src/jrd/DatabaseSnapshot.h @@ -125,7 +125,8 @@ private: 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 initMutex; static SharedMemory* dump; diff --git a/src/jrd/fields.h b/src/jrd/fields.h index d01a3770c7..b8a0ffec4f 100644 --- a/src/jrd/fields.h +++ b/src/jrd/fields.h @@ -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) diff --git a/src/jrd/names.h b/src/jrd/names.h index 86b2519042..5d2175772b 100644 --- a/src/jrd/names.h +++ b/src/jrd/names.h @@ -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) @@ -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) @@ -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) diff --git a/src/jrd/relations.h b/src/jrd/relations.h index 271088b648..f3688bd6a4 100644 --- a/src/jrd/relations.h +++ b/src/jrd/relations.h @@ -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