8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 22:03:03 +01:00

Improvement CORE-3656 : Support for sweep information in Trace API.

Fixed case when sweep cleaned up relation with all records deleted but corresponding event was missed in trace log.
This commit is contained in:
hvlad 2012-09-04 08:50:54 +00:00
parent 218a462784
commit 8dc7b564ca
3 changed files with 65 additions and 23 deletions

View File

@ -1845,7 +1845,7 @@ void TRA_sweep(thread_db* tdbb)
CCH_RELEASE(tdbb, &window); CCH_RELEASE(tdbb, &window);
traceSweep.report(process_state_finished); traceSweep.finish();
} }
TRA_commit(tdbb, transaction, false); TRA_commit(tdbb, transaction, false);
@ -3671,7 +3671,54 @@ TraceSweepEvent::~TraceSweepEvent()
} }
void TraceSweepEvent::report(ntrace_process_state_t state, jrd_rel* relation) void TraceSweepEvent::beginSweepRelation(jrd_rel* relation)
{
if (!m_need_trace)
return;
if (relation && relation->rel_name.isEmpty())
{
// don't accumulate per-relation stats for metadata query below
MET_lookup_relation_id(m_tdbb, relation->rel_id, false);
}
m_relation_clock = fb_utils::query_performance_counter();
m_request.req_stats.reset();
}
void TraceSweepEvent::endSweepRelation(jrd_rel* relation)
{
if (!m_need_trace)
return;
// don't report empty relation
if (m_request.req_stats.getValue(RuntimeStatistics::RECORD_SEQ_READS) == 0 &&
m_request.req_stats.getValue(RuntimeStatistics::RECORD_BACKOUTS) == 0 &&
m_request.req_stats.getValue(RuntimeStatistics::RECORD_PURGES) == 0 &&
m_request.req_stats.getValue(RuntimeStatistics::RECORD_EXPUNGES) == 0)
{
return;
}
// we need to compare stats against zero base
m_request.req_base_stats.reset();
Database* dbb = m_tdbb->getDatabase();
TraceRuntimeStats stats(dbb, &m_request.req_base_stats, &m_request.req_stats,
fb_utils::query_performance_counter() - m_relation_clock,
0);
m_sweep_info.setPerf(stats.getPerf());
Attachment* att = m_tdbb->getAttachment();
TraceConnectionImpl conn(att);
TraceManager* trace_mgr = att->att_trace_manager;
trace_mgr->event_sweep(&conn, &m_sweep_info, process_state_progress);
}
void TraceSweepEvent::report(ntrace_process_state_t state)
{ {
Attachment* att = m_tdbb->getAttachment(); Attachment* att = m_tdbb->getAttachment();
@ -3695,26 +3742,13 @@ void TraceSweepEvent::report(ntrace_process_state_t state, jrd_rel* relation)
TraceConnectionImpl conn(att); TraceConnectionImpl conn(att);
if (relation && relation->rel_name.isEmpty())
{
// don't accumulate per-relation stats for metadata query below
m_tdbb->setRequest(NULL);
MET_lookup_relation_id(m_tdbb, relation->rel_id, false);
m_tdbb->setRequest(&m_request);
}
// we need to compare stats against zero base // we need to compare stats against zero base
m_request.req_base_stats.reset(); m_request.req_base_stats.reset();
TraceRuntimeStats stats(dbb, &m_request.req_base_stats, TraceRuntimeStats stats(dbb, &m_request.req_base_stats, &att->att_stats,
state == process_state_progress ? &m_request.req_stats : &att->att_stats, fb_utils::query_performance_counter() - m_start_clock,
fb_utils::query_performance_counter() - (state == process_state_progress ?
m_relation_clock : m_start_clock),
0); 0);
m_request.req_stats.reset();
m_relation_clock = fb_utils::query_performance_counter();
m_sweep_info.setPerf(stats.getPerf()); m_sweep_info.setPerf(stats.getPerf());
trace_mgr->event_sweep(&conn, &m_sweep_info, state); trace_mgr->event_sweep(&conn, &m_sweep_info, state);

View File

@ -480,9 +480,17 @@ public:
m_sweep_info.update(header); m_sweep_info.update(header);
} }
void report(ntrace_process_state_t state, jrd_rel* relation = 0); void beginSweepRelation(jrd_rel* relation);
void endSweepRelation(jrd_rel* relation);
void finish()
{
report(process_state_finished);
}
private: private:
void report(ntrace_process_state_t state);
bool m_need_trace; bool m_need_trace;
thread_db* m_tdbb; thread_db* m_tdbb;
TraceSweepImpl m_sweep_info; TraceSweepImpl m_sweep_info;
@ -491,6 +499,7 @@ private:
jrd_req m_request; jrd_req m_request;
}; };
} // namespace Jrd } // namespace Jrd
#endif // JRD_TRACE_JRD_HELPERS_H #endif // JRD_TRACE_JRD_HELPERS_H

View File

@ -2926,7 +2926,6 @@ bool VIO_sweep(thread_db* tdbb, jrd_tra* transaction, TraceSweepEvent* traceSwee
for (size_t i = 1; (vector = dbb->dbb_relations) && i < vector->count(); i++) for (size_t i = 1; (vector = dbb->dbb_relations) && i < vector->count(); i++)
{ {
bool haveRecs = false;
if ((relation = (*vector)[i]) && !(relation->rel_flags & (REL_deleted | REL_deleting)) && if ((relation = (*vector)[i]) && !(relation->rel_flags & (REL_deleted | REL_deleting)) &&
relation->getPages(tdbb)->rel_pages) relation->getPages(tdbb)->rel_pages)
{ {
@ -2934,6 +2933,9 @@ bool VIO_sweep(thread_db* tdbb, jrd_tra* transaction, TraceSweepEvent* traceSwee
rpb.rpb_number.setValue(BOF_NUMBER); rpb.rpb_number.setValue(BOF_NUMBER);
rpb.rpb_org_scans = relation->rel_scan_count++; rpb.rpb_org_scans = relation->rel_scan_count++;
++relation->rel_sweep_count; ++relation->rel_sweep_count;
traceSweep->beginSweepRelation(relation);
#ifdef GARBAGE_THREAD #ifdef GARBAGE_THREAD
if (relation->rel_garbage) { if (relation->rel_garbage) {
relation->rel_garbage->clear(); relation->rel_garbage->clear();
@ -2955,12 +2957,9 @@ bool VIO_sweep(thread_db* tdbb, jrd_tra* transaction, TraceSweepEvent* traceSwee
#ifdef SUPERSERVER #ifdef SUPERSERVER
transaction->tra_oldest_active = dbb->dbb_oldest_snapshot; transaction->tra_oldest_active = dbb->dbb_oldest_snapshot;
#endif #endif
haveRecs = true;
} }
if (haveRecs) { traceSweep->endSweepRelation(relation);
traceSweep->report(process_state_progress, relation);
}
--relation->rel_sweep_count; --relation->rel_sweep_count;
--relation->rel_scan_count; --relation->rel_scan_count;