2006-10-07 12:42:02 +02:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Dmitry Yemanov
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Dmitry Yemanov <dimitr@users.sf.net>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef JRD_RUNTIME_STATISTICS_H
|
|
|
|
#define JRD_RUNTIME_STATISTICS_H
|
|
|
|
|
|
|
|
#include "../common/classes/alloc.h"
|
2009-02-09 15:11:16 +01:00
|
|
|
#include "../common/classes/objects_array.h"
|
2009-02-01 23:10:12 +01:00
|
|
|
#include "../common/classes/init.h"
|
|
|
|
#include "../common/classes/tree.h"
|
2012-04-11 11:38:19 +02:00
|
|
|
|
|
|
|
struct TraceCounts; // declared in ntrace.h
|
|
|
|
struct PerformanceInfo; // declared in ntrace.h
|
2006-10-07 12:42:02 +02:00
|
|
|
|
|
|
|
namespace Jrd {
|
|
|
|
|
2009-02-09 15:11:16 +01:00
|
|
|
// hvlad: what to use for relation's counters - tree or sorted array ?
|
|
|
|
// #define REL_COUNTS_TREE
|
|
|
|
// #define REL_COUNTS_PTR
|
2009-02-01 23:10:12 +01:00
|
|
|
|
2011-05-09 12:15:19 +02:00
|
|
|
class Attachment;
|
2009-02-09 15:11:16 +01:00
|
|
|
class Database;
|
2009-02-01 23:10:12 +01:00
|
|
|
|
2012-04-11 11:38:19 +02:00
|
|
|
//
|
|
|
|
// Database record counters.
|
|
|
|
//
|
2012-04-23 02:48:28 +02:00
|
|
|
enum RelStatType
|
2012-04-11 11:38:19 +02:00
|
|
|
{
|
|
|
|
DBB_read_seq_count = 0,
|
|
|
|
DBB_read_idx_count,
|
|
|
|
DBB_update_count,
|
|
|
|
DBB_insert_count,
|
|
|
|
DBB_delete_count,
|
|
|
|
DBB_backout_count,
|
|
|
|
DBB_purge_count,
|
|
|
|
DBB_expunge_count,
|
2012-11-01 01:16:55 +01:00
|
|
|
DBB_lock_count,
|
2012-04-11 11:38:19 +02:00
|
|
|
DBB_max_count
|
|
|
|
};
|
|
|
|
|
2009-04-04 18:39:31 +02:00
|
|
|
// Performance counters for individual table
|
|
|
|
struct RelationCounts
|
2009-02-01 23:10:12 +01:00
|
|
|
{
|
2009-04-04 18:39:31 +02:00
|
|
|
SLONG rlc_relation_id; // Relation ID
|
2012-04-11 11:38:19 +02:00
|
|
|
SINT64 rlc_counter[DBB_max_count];
|
2009-02-01 23:10:12 +01:00
|
|
|
|
2009-02-09 15:11:16 +01:00
|
|
|
#ifdef REL_COUNTS_PTR
|
2009-04-26 12:24:44 +02:00
|
|
|
inline static const SLONG* generate(const void* /*sender*/, const RelationCounts* item)
|
2009-02-09 15:11:16 +01:00
|
|
|
{
|
|
|
|
return &item->rlc_relation_id;
|
|
|
|
}
|
|
|
|
#else
|
2009-04-26 12:24:44 +02:00
|
|
|
inline static const SLONG& generate(const void* /*sender*/, const RelationCounts& item)
|
2009-02-02 04:35:52 +01:00
|
|
|
{
|
|
|
|
return item.rlc_relation_id;
|
|
|
|
}
|
2009-04-04 18:39:31 +02:00
|
|
|
#endif
|
2009-02-01 23:10:12 +01:00
|
|
|
};
|
|
|
|
|
2009-02-09 15:11:16 +01:00
|
|
|
#if defined(REL_COUNTS_TREE)
|
2009-02-05 17:15:05 +01:00
|
|
|
typedef Firebird::BePlusTree<RelationCounts, SLONG, Firebird::MemoryPool, RelationCounts> RelCounters;
|
2009-02-09 15:11:16 +01:00
|
|
|
#elif defined(REL_COUNTS_PTR)
|
2009-04-04 18:39:31 +02:00
|
|
|
typedef Firebird::PointersArray<RelationCounts, Firebird::EmptyStorage<RelationCounts>,
|
2009-02-09 15:11:16 +01:00
|
|
|
SLONG, RelationCounts> RelCounters;
|
2009-02-05 17:15:05 +01:00
|
|
|
#else
|
2009-04-04 18:39:31 +02:00
|
|
|
typedef Firebird::SortedArray<RelationCounts, Firebird::EmptyStorage<RelationCounts>,
|
2009-02-09 15:11:16 +01:00
|
|
|
SLONG, RelationCounts> RelCounters;
|
2009-02-05 17:15:05 +01:00
|
|
|
#endif
|
2009-02-01 23:10:12 +01:00
|
|
|
|
2009-02-02 04:35:52 +01:00
|
|
|
typedef Firebird::HalfStaticArray<TraceCounts, 5> TraceCountsArray;
|
2006-10-07 12:42:02 +02:00
|
|
|
|
2007-12-03 16:46:39 +01:00
|
|
|
// Runtime statistics class
|
2006-10-07 12:42:02 +02:00
|
|
|
|
2012-03-15 10:29:33 +01:00
|
|
|
class RuntimeStatistics : protected Firebird::AutoStorage
|
2008-04-19 11:42:01 +02:00
|
|
|
{
|
2006-10-07 12:42:02 +02:00
|
|
|
public:
|
2007-12-03 16:46:39 +01:00
|
|
|
enum StatType {
|
2006-10-07 12:42:02 +02:00
|
|
|
PAGE_FETCHES = 0,
|
|
|
|
PAGE_READS,
|
|
|
|
PAGE_MARKS,
|
|
|
|
PAGE_WRITES,
|
|
|
|
FLUSHES,
|
|
|
|
RECORD_SEQ_READS,
|
|
|
|
RECORD_IDX_READS,
|
|
|
|
RECORD_INSERTS,
|
|
|
|
RECORD_UPDATES,
|
|
|
|
RECORD_DELETES,
|
|
|
|
RECORD_BACKOUTS,
|
|
|
|
RECORD_PURGES,
|
|
|
|
RECORD_EXPUNGES,
|
2012-11-01 01:16:55 +01:00
|
|
|
RECORD_LOCKS,
|
2006-10-07 12:42:02 +02:00
|
|
|
SORTS,
|
|
|
|
SORT_GETS,
|
|
|
|
SORT_PUTS,
|
|
|
|
STMT_PREPARES,
|
|
|
|
STMT_EXECUTES,
|
2007-11-30 01:35:44 +01:00
|
|
|
TOTAL_ITEMS // last
|
2006-10-07 12:42:02 +02:00
|
|
|
};
|
|
|
|
|
2012-03-15 10:29:33 +01:00
|
|
|
RuntimeStatistics()
|
|
|
|
: Firebird::AutoStorage(), rel_counts(getPool())
|
2007-11-29 11:26:23 +01:00
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
2006-10-07 12:42:02 +02:00
|
|
|
|
2012-03-15 10:29:33 +01:00
|
|
|
explicit RuntimeStatistics(MemoryPool& pool)
|
|
|
|
: Firebird::AutoStorage(pool), rel_counts(getPool())
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
2012-04-10 03:47:24 +02:00
|
|
|
RuntimeStatistics(const RuntimeStatistics& other)
|
2012-03-15 10:29:33 +01:00
|
|
|
: Firebird::AutoStorage(), rel_counts(getPool())
|
|
|
|
{
|
|
|
|
memcpy(values, other.values, sizeof(values));
|
|
|
|
rel_counts = other.rel_counts;
|
|
|
|
|
|
|
|
allChgNumber = other.allChgNumber;
|
|
|
|
relChgNumber = other.relChgNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
RuntimeStatistics(MemoryPool& pool, const RuntimeStatistics& other)
|
|
|
|
: Firebird::AutoStorage(pool), rel_counts(getPool())
|
2009-02-05 17:15:05 +01:00
|
|
|
{
|
|
|
|
memcpy(values, other.values, sizeof(values));
|
|
|
|
rel_counts = other.rel_counts;
|
|
|
|
|
|
|
|
allChgNumber = other.allChgNumber;
|
|
|
|
relChgNumber = other.relChgNumber;
|
|
|
|
}
|
2009-04-04 18:39:31 +02:00
|
|
|
|
2007-12-03 16:46:39 +01:00
|
|
|
~RuntimeStatistics() {}
|
2007-11-29 11:26:23 +01:00
|
|
|
|
2009-02-05 17:15:05 +01:00
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
memset(values, 0, sizeof values);
|
|
|
|
rel_counts.clear();
|
|
|
|
allChgNumber = 0;
|
|
|
|
relChgNumber = 0;
|
|
|
|
}
|
|
|
|
|
2007-12-03 16:46:39 +01:00
|
|
|
SINT64 getValue(const StatType index) const
|
2007-11-29 11:26:23 +01:00
|
|
|
{
|
2007-12-03 16:46:39 +01:00
|
|
|
return values[index];
|
2007-11-29 11:26:23 +01:00
|
|
|
}
|
2009-02-02 04:35:52 +01:00
|
|
|
|
2007-12-03 16:46:39 +01:00
|
|
|
void bumpValue(const StatType index)
|
2007-11-29 11:26:23 +01:00
|
|
|
{
|
2007-12-03 16:46:39 +01:00
|
|
|
++values[index];
|
2009-02-05 17:15:05 +01:00
|
|
|
++allChgNumber;
|
2007-11-29 11:26:23 +01:00
|
|
|
}
|
2009-02-02 04:35:52 +01:00
|
|
|
|
2012-11-01 01:16:55 +01:00
|
|
|
SINT64 getRelValue(const RelStatType index, SLONG relation_id) const
|
|
|
|
{
|
|
|
|
size_t pos;
|
|
|
|
return rel_counts.find(relation_id, pos) ? rel_counts[pos].rlc_counter[index] : 0;
|
|
|
|
}
|
|
|
|
|
2012-04-11 11:38:19 +02:00
|
|
|
void bumpRelValue(const RelStatType index, SLONG relation_id);
|
2007-11-29 11:26:23 +01:00
|
|
|
|
2009-02-02 04:35:52 +01:00
|
|
|
// Calculate difference between counts stored in this object and current
|
2009-02-01 23:10:12 +01:00
|
|
|
// counts of given request. Counts stored in object are destroyed.
|
2011-05-09 12:15:19 +02:00
|
|
|
PerformanceInfo* computeDifference(Attachment* att, const RuntimeStatistics& new_stat,
|
2009-02-02 04:35:52 +01:00
|
|
|
PerformanceInfo& dest, TraceCountsArray& temp);
|
2009-02-01 23:10:12 +01:00
|
|
|
|
2009-02-02 04:35:52 +01:00
|
|
|
// bool operator==(const RuntimeStatistics& other) const;
|
|
|
|
// bool operator!=(const RuntimeStatistics& other) const;
|
2008-11-06 17:04:20 +01:00
|
|
|
|
2009-02-05 17:15:05 +01:00
|
|
|
// add difference between newStats and baseStats to our counters
|
|
|
|
// newStats and baseStats must be "in-sync"
|
2009-02-07 16:20:34 +01:00
|
|
|
void adjust(const RuntimeStatistics& baseStats, const RuntimeStatistics& newStats)
|
2008-12-16 16:17:50 +01:00
|
|
|
{
|
2009-04-04 18:39:31 +02:00
|
|
|
if (baseStats.allChgNumber != newStats.allChgNumber)
|
2009-02-05 17:15:05 +01:00
|
|
|
{
|
|
|
|
allChgNumber++;
|
2009-04-04 18:39:31 +02:00
|
|
|
for (size_t i = 0; i < TOTAL_ITEMS; ++i)
|
2009-02-05 17:15:05 +01:00
|
|
|
{
|
|
|
|
values[i] += newStats.values[i] - baseStats.values[i];
|
|
|
|
}
|
|
|
|
|
2009-04-04 18:39:31 +02:00
|
|
|
if (baseStats.relChgNumber != newStats.relChgNumber)
|
2009-02-05 17:15:05 +01:00
|
|
|
{
|
|
|
|
relChgNumber++;
|
|
|
|
addRelCounts(newStats.rel_counts, true);
|
|
|
|
addRelCounts(baseStats.rel_counts, false);
|
|
|
|
}
|
|
|
|
}
|
2008-12-16 16:17:50 +01:00
|
|
|
|
|
|
|
}
|
2008-11-06 17:04:20 +01:00
|
|
|
|
2009-02-05 17:15:05 +01:00
|
|
|
// copy counters values from other instance
|
2009-02-08 12:23:46 +01:00
|
|
|
// after copying both instances are "in-sync" i.e. have the same
|
2009-02-05 17:15:05 +01:00
|
|
|
// allChgNumber and relChgNumber values
|
|
|
|
RuntimeStatistics& assign(const RuntimeStatistics& other)
|
2008-12-16 16:17:50 +01:00
|
|
|
{
|
2009-04-04 18:39:31 +02:00
|
|
|
if (allChgNumber != other.allChgNumber)
|
2009-02-05 17:15:05 +01:00
|
|
|
{
|
|
|
|
memcpy(values, other.values, sizeof(values));
|
|
|
|
allChgNumber = other.allChgNumber;
|
|
|
|
}
|
|
|
|
|
2009-04-04 18:39:31 +02:00
|
|
|
if (relChgNumber != other.relChgNumber)
|
2009-02-05 17:15:05 +01:00
|
|
|
{
|
|
|
|
rel_counts = other.rel_counts;
|
|
|
|
relChgNumber = other.relChgNumber;
|
|
|
|
}
|
2009-02-07 16:20:34 +01:00
|
|
|
|
2008-12-16 16:17:50 +01:00
|
|
|
return *this;
|
|
|
|
}
|
2008-11-06 17:04:20 +01:00
|
|
|
|
2007-12-03 16:46:39 +01:00
|
|
|
static RuntimeStatistics* getDummy()
|
2007-11-29 11:26:23 +01:00
|
|
|
{
|
2007-12-03 16:46:39 +01:00
|
|
|
return &dummy;
|
2007-11-29 11:26:23 +01:00
|
|
|
}
|
|
|
|
|
2012-11-01 01:16:55 +01:00
|
|
|
class Iterator
|
|
|
|
{
|
|
|
|
friend class RuntimeStatistics;
|
|
|
|
|
|
|
|
explicit Iterator(const RelationCounts* counts)
|
|
|
|
: m_counts(counts)
|
|
|
|
{}
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool operator==(const Iterator& other)
|
|
|
|
{
|
|
|
|
return (m_counts == other.m_counts);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const Iterator& other)
|
|
|
|
{
|
|
|
|
return (m_counts != other.m_counts);
|
|
|
|
}
|
|
|
|
|
|
|
|
Iterator& operator++()
|
|
|
|
{
|
|
|
|
m_counts++;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const RelationCounts& operator*() const
|
|
|
|
{
|
|
|
|
return *m_counts;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const RelationCounts* m_counts;
|
|
|
|
};
|
|
|
|
|
|
|
|
Iterator begin() const
|
|
|
|
{
|
|
|
|
return Iterator(rel_counts.begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
Iterator end() const
|
|
|
|
{
|
|
|
|
return Iterator(rel_counts.end());
|
|
|
|
}
|
|
|
|
|
2006-10-07 12:42:02 +02:00
|
|
|
private:
|
2009-02-05 17:15:05 +01:00
|
|
|
void addRelCounts(const RelCounters& other, bool add);
|
2009-02-01 23:10:12 +01:00
|
|
|
|
2007-12-03 16:46:39 +01:00
|
|
|
SINT64 values[TOTAL_ITEMS];
|
2009-02-05 17:15:05 +01:00
|
|
|
RelCounters rel_counts;
|
|
|
|
|
2009-02-07 13:30:25 +01:00
|
|
|
// These two numbers are used in adjust() and assign() methods as "generation"
|
|
|
|
// values in order to avoid costly operations when two instances of RuntimeStatistics
|
2009-04-04 18:39:31 +02:00
|
|
|
// contain equal counters values. This is intended to use *only* with the
|
2009-02-05 17:15:05 +01:00
|
|
|
// same pair of class instances, as in jrd_req.
|
2009-02-07 13:30:25 +01:00
|
|
|
ULONG allChgNumber; // incremented when any counter changes
|
|
|
|
ULONG relChgNumber; // incremented when relation counter changes
|
2008-11-06 17:04:20 +01:00
|
|
|
|
2007-12-03 16:46:39 +01:00
|
|
|
// This dummy RuntimeStatistics is used instead of missing elements in tdbb,
|
2009-02-07 13:30:25 +01:00
|
|
|
// helping us to avoid conditional checks in time-critical places of code.
|
2007-12-04 14:47:03 +01:00
|
|
|
// Values of it contain actually garbage - don't be surprised when debugging.
|
2009-02-01 23:10:12 +01:00
|
|
|
static Firebird::GlobalPtr<RuntimeStatistics> dummy;
|
2006-10-07 12:42:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif // JRD_RUNTIME_STATISTICS_H
|