Skip to content

Commit 9304339

Browse files
committed
Add support of grouping page-level I/O counters per pagespace
1 parent df73f92 commit 9304339

File tree

6 files changed

+283
-266
lines changed

6 files changed

+283
-266
lines changed

src/jrd/Monitoring.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,36 +1451,39 @@ void Monitoring::putStatistics(SnapshotData::DumpRecord& record, const RuntimeSt
14511451

14521452
// logical I/O statistics (table wise)
14531453

1454-
for (auto iter(statistics.getRelCounters()); iter; ++iter)
1454+
for (const auto& counts : statistics.getRelationCounters())
14551455
{
1456+
if (counts.isEmpty())
1457+
continue;
1458+
14561459
const auto rec_stat_id = getGlobalId(fb_utils::genUniqueId());
14571460

14581461
record.reset(rel_mon_tab_stats);
14591462
record.storeGlobalId(f_mon_tab_stat_id, id);
14601463
record.storeInteger(f_mon_tab_stat_group, stat_group);
1461-
record.storeTableIdSchemaName(f_mon_tab_sch_name, (*iter).getRelationId());
1462-
record.storeTableIdObjectName(f_mon_tab_name, (*iter).getRelationId());
1464+
record.storeTableIdSchemaName(f_mon_tab_sch_name, counts.getGroupKey());
1465+
record.storeTableIdObjectName(f_mon_tab_name, counts.getGroupKey());
14631466
record.storeGlobalId(f_mon_tab_rec_stat_id, rec_stat_id);
14641467
record.write();
14651468

14661469
record.reset(rel_mon_rec_stats);
14671470
record.storeGlobalId(f_mon_rec_stat_id, rec_stat_id);
14681471
record.storeInteger(f_mon_rec_stat_group, stat_group);
1469-
record.storeInteger(f_mon_rec_seq_reads, (*iter)[RecordStatType::SEQ_READS]);
1470-
record.storeInteger(f_mon_rec_idx_reads, (*iter)[RecordStatType::IDX_READS]);
1471-
record.storeInteger(f_mon_rec_inserts, (*iter)[RecordStatType::INSERTS]);
1472-
record.storeInteger(f_mon_rec_updates, (*iter)[RecordStatType::UPDATES]);
1473-
record.storeInteger(f_mon_rec_deletes, (*iter)[RecordStatType::DELETES]);
1474-
record.storeInteger(f_mon_rec_backouts, (*iter)[RecordStatType::BACKOUTS]);
1475-
record.storeInteger(f_mon_rec_purges, (*iter)[RecordStatType::PURGES]);
1476-
record.storeInteger(f_mon_rec_expunges, (*iter)[RecordStatType::EXPUNGES]);
1477-
record.storeInteger(f_mon_rec_locks, (*iter)[RecordStatType::LOCKS]);
1478-
record.storeInteger(f_mon_rec_waits, (*iter)[RecordStatType::WAITS]);
1479-
record.storeInteger(f_mon_rec_conflicts, (*iter)[RecordStatType::CONFLICTS]);
1480-
record.storeInteger(f_mon_rec_bkver_reads, (*iter)[RecordStatType::BACK_READS]);
1481-
record.storeInteger(f_mon_rec_frg_reads, (*iter)[RecordStatType::FRAGMENT_READS]);
1482-
record.storeInteger(f_mon_rec_rpt_reads, (*iter)[RecordStatType::RPT_READS]);
1483-
record.storeInteger(f_mon_rec_imgc, (*iter)[RecordStatType::IMGC]);
1472+
record.storeInteger(f_mon_rec_seq_reads, counts[RecordStatType::SEQ_READS]);
1473+
record.storeInteger(f_mon_rec_idx_reads, counts[RecordStatType::IDX_READS]);
1474+
record.storeInteger(f_mon_rec_inserts, counts[RecordStatType::INSERTS]);
1475+
record.storeInteger(f_mon_rec_updates, counts[RecordStatType::UPDATES]);
1476+
record.storeInteger(f_mon_rec_deletes, counts[RecordStatType::DELETES]);
1477+
record.storeInteger(f_mon_rec_backouts, counts[RecordStatType::BACKOUTS]);
1478+
record.storeInteger(f_mon_rec_purges, counts[RecordStatType::PURGES]);
1479+
record.storeInteger(f_mon_rec_expunges, counts[RecordStatType::EXPUNGES]);
1480+
record.storeInteger(f_mon_rec_locks, counts[RecordStatType::LOCKS]);
1481+
record.storeInteger(f_mon_rec_waits, counts[RecordStatType::WAITS]);
1482+
record.storeInteger(f_mon_rec_conflicts, counts[RecordStatType::CONFLICTS]);
1483+
record.storeInteger(f_mon_rec_bkver_reads, counts[RecordStatType::BACK_READS]);
1484+
record.storeInteger(f_mon_rec_frg_reads, counts[RecordStatType::FRAGMENT_READS]);
1485+
record.storeInteger(f_mon_rec_rpt_reads, counts[RecordStatType::RPT_READS]);
1486+
record.storeInteger(f_mon_rec_imgc, counts[RecordStatType::IMGC]);
14841487
record.write();
14851488
}
14861489
}

src/jrd/RuntimeStatistics.cpp

Lines changed: 70 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -33,52 +33,75 @@ namespace Jrd {
3333

3434
GlobalPtr<RuntimeStatistics> RuntimeStatistics::dummy;
3535

36-
void RuntimeStatistics::adjustRelStats(const RuntimeStatistics& baseStats, const RuntimeStatistics& newStats)
36+
void RuntimeStatistics::adjust(const RuntimeStatistics& baseStats, const RuntimeStatistics& newStats)
3737
{
38-
if (baseStats.relChgNumber == newStats.relChgNumber)
38+
if (baseStats.allChgNumber == newStats.allChgNumber)
3939
return;
4040

41-
relChgNumber++;
41+
allChgNumber++;
42+
for (size_t i = 0; i < GLOBAL_ITEMS; ++i)
43+
values[i] += newStats.values[i] - baseStats.values[i];
44+
45+
if (baseStats.pageChgNumber != newStats.pageChgNumber)
46+
{
47+
pageChgNumber++;
48+
page_counts.adjust(baseStats.page_counts, newStats.page_counts);
49+
}
50+
51+
if (baseStats.relChgNumber != newStats.relChgNumber)
52+
{
53+
relChgNumber++;
54+
rel_counts.adjust(baseStats.rel_counts, newStats.rel_counts);
55+
}
56+
}
57+
58+
void RuntimeStatistics::adjustPageStats(RuntimeStatistics& baseStats, const RuntimeStatistics& newStats)
59+
{
60+
if (baseStats.allChgNumber == newStats.allChgNumber)
61+
return;
4262

43-
auto locate = [this](SLONG relId) -> FB_SIZE_T
63+
allChgNumber++;
64+
for (size_t i = 0; i < PAGE_TOTAL_ITEMS; ++i)
4465
{
45-
FB_SIZE_T pos;
46-
if (!rel_counts.find(relId, pos))
47-
rel_counts.insert(pos, RelationCounts(relId));
48-
return pos;
49-
};
66+
const SINT64 delta = newStats.values[i] - baseStats.values[i];
5067

51-
auto baseIter = baseStats.rel_counts.begin(), newIter = newStats.rel_counts.begin();
52-
const auto baseEnd = baseStats.rel_counts.end(), newEnd = newStats.rel_counts.end();
68+
values[i] += delta;
69+
baseStats.values[i] += delta;
70+
}
71+
}
72+
73+
template <class Counts, typename Key>
74+
void RuntimeStatistics::GroupedCountsArray<Counts, Key>::adjust(const GroupedCountsArray& baseStats, const GroupedCountsArray& newStats)
75+
{
76+
auto baseIter = baseStats.m_counts.begin(), newIter = newStats.m_counts.begin();
77+
const auto baseEnd = baseStats.m_counts.end(), newEnd = newStats.m_counts.end();
5378

54-
// The loop below assumes that newStats cannot miss relations existing in baseStats,
79+
// The loop below assumes that newStats cannot miss objects existing in baseStats,
5580
// this must be always the case as long as newStats is an incremented version of baseStats
5681

5782
while (newIter != newEnd || baseIter != baseEnd)
5883
{
5984
if (baseIter == baseEnd)
6085
{
61-
// Relation exists in newStats but missing in baseStats
62-
const auto newRelId = newIter->getRelationId();
63-
rel_counts[locate(newRelId)] += *newIter++;
86+
// Object exists in newStats but missing in baseStats
87+
const auto newKey = newIter->getGroupKey();
88+
(*this)[newKey] += *newIter++;
6489
}
6590
else if (newIter != newEnd)
6691
{
67-
const auto baseRelId = baseIter->getRelationId();
68-
const auto newRelId = newIter->getRelationId();
92+
const auto baseKey = baseIter->getGroupKey();
93+
const auto newKey = newIter->getGroupKey();
6994

70-
if (newRelId == baseRelId)
95+
if (newKey == baseKey)
7196
{
72-
// Relation exists in both newStats and baseStats
73-
fb_assert(baseRelId == newRelId);
74-
const auto pos = locate(baseRelId);
75-
rel_counts[pos] -= *baseIter++;
76-
rel_counts[pos] += *newIter++;
97+
// Object exists in both newStats and baseStats
98+
(*this)[newKey] += *newIter++;
99+
(*this)[newKey] -= *baseIter++;
77100
}
78-
else if (newRelId < baseRelId)
101+
else if (newKey < baseKey)
79102
{
80-
// Relation exists in newStats but missing in baseStats
81-
rel_counts[locate(newRelId)] += *newIter++;
103+
// Object exists in newStats but missing in baseStats
104+
(*this)[newKey] += *newIter++;
82105
}
83106
else
84107
fb_assert(false); // should never happen
@@ -89,116 +112,55 @@ void RuntimeStatistics::adjustRelStats(const RuntimeStatistics& baseStats, const
89112
}
90113

91114
PerformanceInfo* RuntimeStatistics::computeDifference(Attachment* att,
92-
const RuntimeStatistics& new_stat,
115+
const RuntimeStatistics& newStats,
93116
PerformanceInfo& dest,
94-
TraceCountsArray& temp,
117+
TraceCountsArray& relStatsTemp,
95118
ObjectsArray<string>& tempNames)
96119
{
97120
// NOTE: we do not initialize dest.pin_time. This must be done by the caller
98121

99122
// Calculate database-level statistics
100-
for (size_t i = 0; i < GLOBAL_ITEMS; i++)
101-
values[i] = new_stat.values[i] - values[i];
102123

103-
dest.pin_counters = values;
124+
for (size_t i = 0; i < GLOBAL_ITEMS; i++)
125+
values[i] = newStats.values[i] - values[i];
104126

105127
// Calculate relation-level statistics
106-
temp.clear();
107-
tempNames.clear();
108128

109-
// This loop assumes that base array is smaller than new one
110-
RelCounters::iterator base_cnts = rel_counts.begin();
111-
bool base_found = (base_cnts != rel_counts.end());
129+
relStatsTemp.clear();
112130

113-
for (const auto& new_cnts : new_stat.rel_counts)
131+
for (const auto& newCounts : newStats.rel_counts)
114132
{
115-
const SLONG rel_id = new_cnts.getRelationId();
133+
const auto relationId = newCounts.getGroupKey();
134+
auto& counts = rel_counts[relationId];
116135

117-
if (base_found && base_cnts->getRelationId() == rel_id)
136+
if (counts.setToDiff(newCounts))
118137
{
119-
// Point TraceCounts to counts array from baseline object
120-
if (base_cnts->setToDiff(new_cnts))
121-
{
122-
jrd_rel* const relation =
123-
rel_id < static_cast<SLONG>(att->att_relations->count()) ?
124-
(*att->att_relations)[rel_id] : NULL;
125-
126-
TraceCounts traceCounts;
127-
traceCounts.trc_relation_id = rel_id;
128-
traceCounts.trc_counters = base_cnts->getCounterVector();
138+
const char* relationName = nullptr;
129139

130-
if (relation)
140+
if (relationId < static_cast<SLONG>(att->att_relations->count()))
141+
{
142+
if (const auto relation = (*att->att_relations)[relationId])
131143
{
132144
auto& tempName = tempNames.add();
133145
tempName = relation->rel_name.toQuotedString();
134-
traceCounts.trc_relation_name = tempName.c_str();
146+
relationName = tempName.c_str();
135147
}
136-
else
137-
traceCounts.trc_relation_name = nullptr;
138-
139-
temp.add(traceCounts);
140148
}
141149

142-
++base_cnts;
143-
base_found = (base_cnts != rel_counts.end());
144-
}
145-
else
146-
{
147-
jrd_rel* const relation =
148-
rel_id < static_cast<SLONG>(att->att_relations->count()) ?
149-
(*att->att_relations)[rel_id] : NULL;
150-
151-
// Point TraceCounts to counts array from object with updated counters
152150
TraceCounts traceCounts;
153-
traceCounts.trc_relation_id = rel_id;
154-
traceCounts.trc_counters = new_cnts.getCounterVector();
155-
156-
if (relation)
157-
{
158-
auto& tempName = tempNames.add();
159-
tempName = relation->rel_name.toQuotedString();
160-
traceCounts.trc_relation_name = tempName.c_str();
161-
}
162-
else
163-
traceCounts.trc_relation_name = nullptr;
164-
165-
temp.add(traceCounts);
151+
traceCounts.trc_relation_id = relationId;
152+
traceCounts.trc_relation_name = relationName;
153+
traceCounts.trc_counters = counts.getCounterVector();
154+
relStatsTemp.add(traceCounts);
166155
}
167-
};
156+
}
168157

169-
dest.pin_count = temp.getCount();
170-
dest.pin_tables = temp.begin();
158+
dest.pin_count = relStatsTemp.getCount();
159+
dest.pin_tables = relStatsTemp.begin();
171160

172161
return &dest;
173162
}
174163

175-
void RuntimeStatistics::adjust(const RuntimeStatistics& baseStats, const RuntimeStatistics& newStats)
176-
{
177-
if (baseStats.allChgNumber == newStats.allChgNumber)
178-
return;
179-
180-
allChgNumber++;
181-
for (size_t i = 0; i < GLOBAL_ITEMS; ++i)
182-
values[i] += newStats.values[i] - baseStats.values[i];
183-
184-
adjustRelStats(baseStats, newStats);
185-
}
186-
187-
void RuntimeStatistics::adjustPageStats(RuntimeStatistics& baseStats, const RuntimeStatistics& newStats)
188-
{
189-
if (baseStats.allChgNumber == newStats.allChgNumber)
190-
return;
191-
192-
allChgNumber++;
193-
for (size_t i = 0; i < PAGE_TOTAL_ITEMS; ++i)
194-
{
195-
const SINT64 delta = newStats.values[i] - baseStats.values[i];
196-
197-
values[i] += delta;
198-
baseStats.values[i] += delta;
199-
}
200-
}
201-
202164
RuntimeStatistics::Accumulator::Accumulator(thread_db* tdbb, const jrd_rel* relation,
203165
const RecordStatType type)
204166
: m_tdbb(tdbb), m_type(type), m_id(relation->rel_id)

0 commit comments

Comments
 (0)