Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/jrd/Attachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,10 +632,12 @@ void Jrd::Attachment::signalShutdown(ISC_STATUS code)
void Jrd::Attachment::mergeStats(bool pageStatsOnly)
{
MutexLockGuard guard(att_database->dbb_stats_mutex, FB_FUNCTION);
att_database->dbb_stats.adjustPageStats(att_base_stats, att_stats);
if (!pageStatsOnly)

if (pageStatsOnly)
att_database->dbb_stats.adjustPageStats(att_base_stats, att_stats);
else
{
att_database->dbb_stats.adjust(att_base_stats, att_stats, true);
att_database->dbb_stats.adjust(att_base_stats, att_stats);
att_base_stats.assign(att_stats);
}
}
Expand Down
70 changes: 35 additions & 35 deletions src/jrd/Monitoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,36 +1422,36 @@ void Monitoring::putStatistics(SnapshotData::DumpRecord& record, const RuntimeSt
record.reset(rel_mon_io_stats);
record.storeGlobalId(f_mon_io_stat_id, id);
record.storeInteger(f_mon_io_stat_group, stat_group);
record.storeInteger(f_mon_io_page_reads, statistics.getValue(RuntimeStatistics::PAGE_READS));
record.storeInteger(f_mon_io_page_writes, statistics.getValue(RuntimeStatistics::PAGE_WRITES));
record.storeInteger(f_mon_io_page_fetches, statistics.getValue(RuntimeStatistics::PAGE_FETCHES));
record.storeInteger(f_mon_io_page_marks, statistics.getValue(RuntimeStatistics::PAGE_MARKS));
record.storeInteger(f_mon_io_page_reads, statistics[PageStatType::READS]);
record.storeInteger(f_mon_io_page_writes, statistics[PageStatType::WRITES]);
record.storeInteger(f_mon_io_page_fetches, statistics[PageStatType::FETCHES]);
record.storeInteger(f_mon_io_page_marks, statistics[PageStatType::MARKS]);
record.write();

// logical I/O statistics (global)
record.reset(rel_mon_rec_stats);
record.storeGlobalId(f_mon_rec_stat_id, id);
record.storeInteger(f_mon_rec_stat_group, stat_group);
record.storeInteger(f_mon_rec_seq_reads, statistics.getValue(RuntimeStatistics::RECORD_SEQ_READS));
record.storeInteger(f_mon_rec_idx_reads, statistics.getValue(RuntimeStatistics::RECORD_IDX_READS));
record.storeInteger(f_mon_rec_inserts, statistics.getValue(RuntimeStatistics::RECORD_INSERTS));
record.storeInteger(f_mon_rec_updates, statistics.getValue(RuntimeStatistics::RECORD_UPDATES));
record.storeInteger(f_mon_rec_deletes, statistics.getValue(RuntimeStatistics::RECORD_DELETES));
record.storeInteger(f_mon_rec_backouts, statistics.getValue(RuntimeStatistics::RECORD_BACKOUTS));
record.storeInteger(f_mon_rec_purges, statistics.getValue(RuntimeStatistics::RECORD_PURGES));
record.storeInteger(f_mon_rec_expunges, statistics.getValue(RuntimeStatistics::RECORD_EXPUNGES));
record.storeInteger(f_mon_rec_locks, statistics.getValue(RuntimeStatistics::RECORD_LOCKS));
record.storeInteger(f_mon_rec_waits, statistics.getValue(RuntimeStatistics::RECORD_WAITS));
record.storeInteger(f_mon_rec_conflicts, statistics.getValue(RuntimeStatistics::RECORD_CONFLICTS));
record.storeInteger(f_mon_rec_bkver_reads, statistics.getValue(RuntimeStatistics::RECORD_BACKVERSION_READS));
record.storeInteger(f_mon_rec_frg_reads, statistics.getValue(RuntimeStatistics::RECORD_FRAGMENT_READS));
record.storeInteger(f_mon_rec_rpt_reads, statistics.getValue(RuntimeStatistics::RECORD_RPT_READS));
record.storeInteger(f_mon_rec_imgc, statistics.getValue(RuntimeStatistics::RECORD_IMGC));
record.storeInteger(f_mon_rec_seq_reads, statistics[RecordStatType::SEQ_READS]);
record.storeInteger(f_mon_rec_idx_reads, statistics[RecordStatType::IDX_READS]);
record.storeInteger(f_mon_rec_inserts, statistics[RecordStatType::INSERTS]);
record.storeInteger(f_mon_rec_updates, statistics[RecordStatType::UPDATES]);
record.storeInteger(f_mon_rec_deletes, statistics[RecordStatType::DELETES]);
record.storeInteger(f_mon_rec_backouts, statistics[RecordStatType::BACKOUTS]);
record.storeInteger(f_mon_rec_purges, statistics[RecordStatType::PURGES]);
record.storeInteger(f_mon_rec_expunges, statistics[RecordStatType::EXPUNGES]);
record.storeInteger(f_mon_rec_locks, statistics[RecordStatType::LOCKS]);
record.storeInteger(f_mon_rec_waits, statistics[RecordStatType::WAITS]);
record.storeInteger(f_mon_rec_conflicts, statistics[RecordStatType::CONFLICTS]);
record.storeInteger(f_mon_rec_bkver_reads, statistics[RecordStatType::BACK_READS]);
record.storeInteger(f_mon_rec_frg_reads, statistics[RecordStatType::FRAGMENT_READS]);
record.storeInteger(f_mon_rec_rpt_reads, statistics[RecordStatType::RPT_READS]);
record.storeInteger(f_mon_rec_imgc, statistics[RecordStatType::IMGC]);
record.write();

// logical I/O statistics (table wise)

for (RuntimeStatistics::Iterator iter = statistics.begin(); iter != statistics.end(); ++iter)
for (auto iter(statistics.getRelCounters()); iter; ++iter)
{
const auto rec_stat_id = getGlobalId(fb_utils::genUniqueId());

Expand All @@ -1466,21 +1466,21 @@ void Monitoring::putStatistics(SnapshotData::DumpRecord& record, const RuntimeSt
record.reset(rel_mon_rec_stats);
record.storeGlobalId(f_mon_rec_stat_id, rec_stat_id);
record.storeInteger(f_mon_rec_stat_group, stat_group);
record.storeInteger(f_mon_rec_seq_reads, (*iter).getCounter(RuntimeStatistics::RECORD_SEQ_READS));
record.storeInteger(f_mon_rec_idx_reads, (*iter).getCounter(RuntimeStatistics::RECORD_IDX_READS));
record.storeInteger(f_mon_rec_inserts, (*iter).getCounter(RuntimeStatistics::RECORD_INSERTS));
record.storeInteger(f_mon_rec_updates, (*iter).getCounter(RuntimeStatistics::RECORD_UPDATES));
record.storeInteger(f_mon_rec_deletes, (*iter).getCounter(RuntimeStatistics::RECORD_DELETES));
record.storeInteger(f_mon_rec_backouts, (*iter).getCounter(RuntimeStatistics::RECORD_BACKOUTS));
record.storeInteger(f_mon_rec_purges, (*iter).getCounter(RuntimeStatistics::RECORD_PURGES));
record.storeInteger(f_mon_rec_expunges, (*iter).getCounter(RuntimeStatistics::RECORD_EXPUNGES));
record.storeInteger(f_mon_rec_locks, (*iter).getCounter(RuntimeStatistics::RECORD_LOCKS));
record.storeInteger(f_mon_rec_waits, (*iter).getCounter(RuntimeStatistics::RECORD_WAITS));
record.storeInteger(f_mon_rec_conflicts, (*iter).getCounter(RuntimeStatistics::RECORD_CONFLICTS));
record.storeInteger(f_mon_rec_bkver_reads, (*iter).getCounter(RuntimeStatistics::RECORD_BACKVERSION_READS));
record.storeInteger(f_mon_rec_frg_reads, (*iter).getCounter(RuntimeStatistics::RECORD_FRAGMENT_READS));
record.storeInteger(f_mon_rec_rpt_reads, (*iter).getCounter(RuntimeStatistics::RECORD_RPT_READS));
record.storeInteger(f_mon_rec_imgc, (*iter).getCounter(RuntimeStatistics::RECORD_IMGC));
record.storeInteger(f_mon_rec_seq_reads, (*iter)[RecordStatType::SEQ_READS]);
record.storeInteger(f_mon_rec_idx_reads, (*iter)[RecordStatType::IDX_READS]);
record.storeInteger(f_mon_rec_inserts, (*iter)[RecordStatType::INSERTS]);
record.storeInteger(f_mon_rec_updates, (*iter)[RecordStatType::UPDATES]);
record.storeInteger(f_mon_rec_deletes, (*iter)[RecordStatType::DELETES]);
record.storeInteger(f_mon_rec_backouts, (*iter)[RecordStatType::BACKOUTS]);
record.storeInteger(f_mon_rec_purges, (*iter)[RecordStatType::PURGES]);
record.storeInteger(f_mon_rec_expunges, (*iter)[RecordStatType::EXPUNGES]);
record.storeInteger(f_mon_rec_locks, (*iter)[RecordStatType::LOCKS]);
record.storeInteger(f_mon_rec_waits, (*iter)[RecordStatType::WAITS]);
record.storeInteger(f_mon_rec_conflicts, (*iter)[RecordStatType::CONFLICTS]);
record.storeInteger(f_mon_rec_bkver_reads, (*iter)[RecordStatType::BACK_READS]);
record.storeInteger(f_mon_rec_frg_reads, (*iter)[RecordStatType::FRAGMENT_READS]);
record.storeInteger(f_mon_rec_rpt_reads, (*iter)[RecordStatType::RPT_READS]);
record.storeInteger(f_mon_rec_imgc, (*iter)[RecordStatType::IMGC]);
record.write();
}
}
Expand Down
117 changes: 77 additions & 40 deletions src/jrd/RuntimeStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,47 +33,58 @@ namespace Jrd {

GlobalPtr<RuntimeStatistics> RuntimeStatistics::dummy;

void RuntimeStatistics::findAndBumpRelValue(const StatType index, SLONG relation_id, SINT64 delta)
void RuntimeStatistics::adjustRelStats(const RuntimeStatistics& baseStats, const RuntimeStatistics& newStats)
{
if (rel_counts.find(relation_id, rel_last_pos))
rel_counts[rel_last_pos].bumpCounter(index, delta);
else
{
RelationCounts counts(relation_id);
counts.bumpCounter(index, delta);
rel_counts.insert(rel_last_pos, counts);
}
}

void RuntimeStatistics::addRelCounts(const RelCounters& other, bool add)
{
if (other.isEmpty())
if (baseStats.relChgNumber == newStats.relChgNumber)
return;

RelCounters::const_iterator src(other.begin());
const RelCounters::const_iterator end(other.end());
relChgNumber++;

FB_SIZE_T pos;
rel_counts.find(src->getRelationId(), pos);
for (; src != end; ++src)
auto locate = [this](SLONG relId) -> FB_SIZE_T
{
const FB_SIZE_T cnt = rel_counts.getCount();
FB_SIZE_T pos;
if (!rel_counts.find(relId, pos))
rel_counts.insert(pos, RelationCounts(relId));
return pos;
};

while (pos < cnt && rel_counts[pos].getRelationId() < src->getRelationId())
pos++;
auto baseIter = baseStats.rel_counts.begin(), newIter = newStats.rel_counts.begin();
const auto baseEnd = baseStats.rel_counts.end(), newEnd = newStats.rel_counts.end();

if (pos >= cnt || rel_counts[pos].getRelationId() > src->getRelationId())
// The loop below assumes that newStats cannot miss relations existing in baseStats,
// this must be always the case as long as newStats is an incremented version of baseStats

while (newIter != newEnd || baseIter != baseEnd)
{
if (baseIter == baseEnd)
{
RelationCounts counts(src->getRelationId());
rel_counts.insert(pos, counts);
// Relation exists in newStats but missing in baseStats
const auto newRelId = newIter->getRelationId();
rel_counts[locate(newRelId)] += *newIter++;
}
else if (newIter != newEnd)
{
const auto baseRelId = baseIter->getRelationId();
const auto newRelId = newIter->getRelationId();

fb_assert(pos >= 0 && pos < rel_counts.getCount());

if (add)
rel_counts[pos] += *src;
if (newRelId == baseRelId)
{
// Relation exists in both newStats and baseStats
fb_assert(baseRelId == newRelId);
const auto pos = locate(baseRelId);
rel_counts[pos] -= *baseIter++;
rel_counts[pos] += *newIter++;
}
else if (newRelId < baseRelId)
{
// Relation exists in newStats but missing in baseStats
rel_counts[locate(newRelId)] += *newIter++;
}
else
fb_assert(false); // should never happen
}
else
rel_counts[pos] -= *src;
fb_assert(false); // should never happen
}
}

Expand All @@ -86,7 +97,7 @@ PerformanceInfo* RuntimeStatistics::computeDifference(Attachment* att,
// NOTE: we do not initialize dest.pin_time. This must be done by the caller

// Calculate database-level statistics
for (int i = 0; i < TOTAL_ITEMS; i++)
for (size_t i = 0; i < GLOBAL_ITEMS; i++)
values[i] = new_stat.values[i] - values[i];

dest.pin_counters = values;
Expand All @@ -99,16 +110,14 @@ PerformanceInfo* RuntimeStatistics::computeDifference(Attachment* att,
RelCounters::iterator base_cnts = rel_counts.begin();
bool base_found = (base_cnts != rel_counts.end());

RelCounters::const_iterator new_cnts = new_stat.rel_counts.begin();
const RelCounters::const_iterator end = new_stat.rel_counts.end();
for (; new_cnts != end; ++new_cnts)
for (const auto& new_cnts : new_stat.rel_counts)
{
const SLONG rel_id = new_cnts->getRelationId();
const SLONG rel_id = new_cnts.getRelationId();

if (base_found && base_cnts->getRelationId() == rel_id)
{
// Point TraceCounts to counts array from baseline object
if (base_cnts->setToDiff(*new_cnts))
if (base_cnts->setToDiff(new_cnts))
{
jrd_rel* const relation =
rel_id < static_cast<SLONG>(att->att_relations->count()) ?
Expand Down Expand Up @@ -142,7 +151,7 @@ PerformanceInfo* RuntimeStatistics::computeDifference(Attachment* att,
// Point TraceCounts to counts array from object with updated counters
TraceCounts traceCounts;
traceCounts.trc_relation_id = rel_id;
traceCounts.trc_counters = new_cnts->getCounterVector();
traceCounts.trc_counters = new_cnts.getCounterVector();

if (relation)
{
Expand All @@ -163,14 +172,42 @@ PerformanceInfo* RuntimeStatistics::computeDifference(Attachment* att,
return &dest;
}

RuntimeStatistics::Accumulator::Accumulator(thread_db* tdbb, const jrd_rel* relation, StatType type)
: m_tdbb(tdbb), m_type(type), m_id(relation->rel_id), m_counter(0)
void RuntimeStatistics::adjust(const RuntimeStatistics& baseStats, const RuntimeStatistics& newStats)
{
if (baseStats.allChgNumber == newStats.allChgNumber)
return;

allChgNumber++;
for (size_t i = 0; i < GLOBAL_ITEMS; ++i)
values[i] += newStats.values[i] - baseStats.values[i];

adjustRelStats(baseStats, newStats);
}

void RuntimeStatistics::adjustPageStats(RuntimeStatistics& baseStats, const RuntimeStatistics& newStats)
{
if (baseStats.allChgNumber == newStats.allChgNumber)
return;

allChgNumber++;
for (size_t i = 0; i < PAGE_TOTAL_ITEMS; ++i)
{
const SINT64 delta = newStats.values[i] - baseStats.values[i];

values[i] += delta;
baseStats.values[i] += delta;
}
}

RuntimeStatistics::Accumulator::Accumulator(thread_db* tdbb, const jrd_rel* relation,
const RecordStatType type)
: m_tdbb(tdbb), m_type(type), m_id(relation->rel_id)
{}

RuntimeStatistics::Accumulator::~Accumulator()
{
if (m_counter)
m_tdbb->bumpRelStats(m_type, m_id, m_counter);
m_tdbb->bumpStats(m_type, m_id, m_counter);
}

} // namespace
Loading
Loading