Skip to content

Commit bcbc96d

Browse files
committed
Extend monitoring with per-tablespace I/O statistics
1 parent f42c605 commit bcbc96d

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

src/jrd/Monitoring.cpp

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ MonitoringSnapshot::MonitoringSnapshot(thread_db* tdbb, MemoryPool& pool)
466466
const auto ctx_var_buffer = allocBuffer(tdbb, pool, rel_mon_ctx_vars);
467467
const auto mem_usage_buffer = allocBuffer(tdbb, pool, rel_mon_mem_usage);
468468
const auto tab_stat_buffer = allocBuffer(tdbb, pool, rel_mon_tab_stats);
469+
const auto ts_stat_buffer = allocBuffer(tdbb, pool, rel_mon_ts_stats);
469470

470471
// Increment the global monitor generation
471472

@@ -601,6 +602,9 @@ MonitoringSnapshot::MonitoringSnapshot(thread_db* tdbb, MemoryPool& pool)
601602
case rel_mon_tab_stats:
602603
buffer = tab_stat_buffer;
603604
break;
605+
case rel_mon_ts_stats:
606+
buffer = ts_stat_buffer;
607+
break;
604608
default:
605609
fb_assert(false);
606610
}
@@ -862,6 +866,32 @@ void SnapshotData::putField(thread_db* tdbb, Record* record, const DumpField& fi
862866
from_desc.makeBoolean(&value);
863867
MOV_move(tdbb, &from_desc, &to_desc);
864868
}
869+
else if (field.type == VALUE_TABLESPACE_ID)
870+
{
871+
// special case: translate tablespace ID into name
872+
fb_assert(field.length == sizeof(ULONG));
873+
ULONG pageSpaceId;
874+
memcpy(&pageSpaceId, field.data, field.length);
875+
876+
MetaName name;
877+
878+
if (pageSpaceId == 0)
879+
name = TEMP_TABLESPACE_NAME;
880+
else if (pageSpaceId == DB_PAGE_SPACE)
881+
name = PRIMARY_TABLESPACE_NAME;
882+
else if (PageSpace::isTablespace(pageSpaceId))
883+
{
884+
if (const auto tablespace = MET_tablespace_id(tdbb, pageSpaceId))
885+
name = tablespace->name;
886+
}
887+
888+
if (name.hasData())
889+
{
890+
dsc from_desc;
891+
from_desc.makeText(name.length(), CS_METADATA, (UCHAR*) name.c_str());
892+
MOV_move(tdbb, &from_desc, &to_desc);
893+
}
894+
}
865895
else
866896
{
867897
fb_assert(false);
@@ -1449,7 +1479,33 @@ void Monitoring::putStatistics(SnapshotData::DumpRecord& record, const RuntimeSt
14491479
record.storeInteger(f_mon_rec_imgc, statistics[RecordStatType::IMGC]);
14501480
record.write();
14511481

1452-
// logical I/O statistics (table wise)
1482+
// physical I/O statistics (per tablespace)
1483+
1484+
for (const auto& counts : statistics.getPageCounters())
1485+
{
1486+
if (counts.isEmpty())
1487+
continue;
1488+
1489+
const auto io_stat_id = getGlobalId(fb_utils::genUniqueId());
1490+
1491+
record.reset(rel_mon_ts_stats);
1492+
record.storeGlobalId(f_mon_ts_stat_id, id);
1493+
record.storeInteger(f_mon_ts_stat_group, stat_group);
1494+
record.storeTablespaceId(f_mon_ts_name, counts.getGroupId());
1495+
record.storeGlobalId(f_mon_tab_io_stat_id, io_stat_id);
1496+
record.write();
1497+
1498+
record.reset(rel_mon_io_stats);
1499+
record.storeGlobalId(f_mon_io_stat_id, io_stat_id);
1500+
record.storeInteger(f_mon_io_stat_group, stat_group);
1501+
record.storeInteger(f_mon_io_page_reads, counts[PageStatType::READS]);
1502+
record.storeInteger(f_mon_io_page_writes, counts[PageStatType::WRITES]);
1503+
record.storeInteger(f_mon_io_page_fetches, counts[PageStatType::FETCHES]);
1504+
record.storeInteger(f_mon_io_page_marks, counts[PageStatType::MARKS]);
1505+
record.write();
1506+
}
1507+
1508+
// logical I/O statistics (per table)
14531509

14541510
for (const auto& counts : statistics.getTableCounters())
14551511
{

src/jrd/Monitoring.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class SnapshotData
6060
VALUE_STRING,
6161
VALUE_BOOLEAN,
6262
VALUE_TABLE_ID_SCHEMA_NAME,
63+
VALUE_TABLESPACE_ID,
6364
VALUE_LAST_MARKER // Should be last item
6465
};
6566

@@ -134,6 +135,11 @@ class SnapshotData
134135
storeField(field_id, VALUE_TABLE_ID_SCHEMA_NAME, sizeof(SLONG), &value);
135136
}
136137

138+
void storeTablespaceId(int field_id, ULONG value)
139+
{
140+
storeField(field_id, VALUE_TABLESPACE_ID, sizeof(ULONG), &value);
141+
}
142+
137143
void storeInteger(int field_id, SINT64 value)
138144
{
139145
storeField(field_id, VALUE_INTEGER, sizeof(SINT64), &value);

src/jrd/constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,5 +513,6 @@ inline constexpr USHORT MAX_ERROR_MSG_LENGTH = 1024 * METADATA_BYTES_PER_CHAR; /
513513

514514
// Tablespaces
515515
const char* const PRIMARY_TABLESPACE_NAME = "PRIMARY";
516+
const char* const TEMP_TABLESPACE_NAME = "TEMPORARY";
516517

517518
#endif // JRD_CONSTANTS_H

src/jrd/names.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,7 @@ NAME("RDB$TABLE_SCHEMA_NAME", nam_tab_sch_name)
499499
NAME("RDB$CONST_SCHEMA_NAME_UQ", nam_con_sch_name_uq)
500500
NAME("MON$SEARCH_PATH", nam_mon_search_path)
501501
NAME("RDB$TEXT_MAX", nam_text_max)
502+
503+
NAME("MON$TABLESPACE_STATS", nam_mon_ts_stats)
504+
NAME("MON$IO_STAT_ID", nam_mon_io_stat_id)
505+
NAME("MON$TABLESPACE_NAME", nam_mon_ts_name)

src/jrd/relations.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,3 +829,11 @@ RELATION(nam_tablespaces, rel_tablespaces, ODS_14_0, rel_persistent)
829829
FIELD(f_ts_offline, nam_ts_offline, fld_bool, 1, ODS_14_0)
830830
FIELD(f_ts_readonly, nam_ts_readonly, fld_bool, 1, ODS_14_0)
831831
END_RELATION
832+
833+
// Relation 57 (MON$TABLESPACE_STATS)
834+
RELATION(nam_mon_ts_stats, rel_mon_ts_stats, ODS_14_0, rel_virtual)
835+
FIELD(f_mon_ts_stat_id, nam_mon_stat_id, fld_stat_id, 0, ODS_14_0)
836+
FIELD(f_mon_ts_stat_group, nam_mon_stat_group, fld_stat_group, 0, ODS_14_0)
837+
FIELD(f_mon_ts_name, nam_mon_ts_name, fld_ts_name, 0, ODS_14_0)
838+
FIELD(f_mon_tab_io_stat_id, nam_mon_io_stat_id, fld_stat_id, 0, ODS_14_0)
839+
END_RELATION

src/jrd/trace/TraceObjects.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,19 @@ TraceRuntimeStats::TraceRuntimeStats(Attachment* attachment,
643643

644644
auto getTablespaceName = [&](unsigned id) -> Firebird::string
645645
{
646-
return ""; // TODO
646+
if (id == 0)
647+
return TEMP_TABLESPACE_NAME;
648+
649+
if (id == DB_PAGE_SPACE)
650+
return PRIMARY_TABLESPACE_NAME;
651+
652+
if (PageSpace::isTablespace(id))
653+
{
654+
if (const auto tablespace = attachment->getTablespace(id))
655+
return tablespace->name.c_str();
656+
}
657+
658+
return "";
647659
};
648660

649661
m_pageCounters.reset(&baseline->getPageCounters(), getTablespaceName);

0 commit comments

Comments
 (0)