forked from mirrors/0ad
Remove profiler 2 spike/aggregated regions
This code is unused and was never actually useful. Fixes #6620.
This commit is contained in:
+2
-131
@@ -47,7 +47,6 @@ const size_t CProfiler2::MAX_ATTRIBUTE_LENGTH = 256;
|
||||
|
||||
// TODO: what's a good size?
|
||||
const size_t CProfiler2::BUFFER_SIZE = 4 * 1024 * 1024;
|
||||
const size_t CProfiler2::HOLD_BUFFER_SIZE = 128 * 1024;
|
||||
|
||||
// A human-recognisable pattern (for debugging) followed by random bytes (for uniqueness)
|
||||
const u8 CProfiler2::RESYNC_MAGIC[8] = {0x11, 0x22, 0x33, 0x44, 0xf4, 0x93, 0xbe, 0x15};
|
||||
@@ -313,7 +312,7 @@ void CProfiler2::RemoveThreadStorage(ThreadStorage* storage)
|
||||
}
|
||||
|
||||
CProfiler2::ThreadStorage::ThreadStorage(CProfiler2& profiler, const std::string& name) :
|
||||
m_Profiler(profiler), m_Name(name), m_BufferPos0(0), m_BufferPos1(0), m_LastTime(timer_Time()), m_HeldDepth(0)
|
||||
m_Profiler(profiler), m_Name(name), m_BufferPos0(0), m_BufferPos1(0), m_LastTime(timer_Time())
|
||||
{
|
||||
m_Buffer = new u8[BUFFER_SIZE];
|
||||
memset(m_Buffer, ITEM_NOP, BUFFER_SIZE);
|
||||
@@ -326,11 +325,6 @@ CProfiler2::ThreadStorage::~ThreadStorage()
|
||||
|
||||
void CProfiler2::ThreadStorage::Write(EItem type, const void* item, u32 itemSize)
|
||||
{
|
||||
if (m_HeldDepth > 0)
|
||||
{
|
||||
WriteHold(type, item, itemSize);
|
||||
return;
|
||||
}
|
||||
// See m_BufferPos0 etc for comments on synchronisation
|
||||
|
||||
u32 size = 1 + itemSize;
|
||||
@@ -360,19 +354,6 @@ void CProfiler2::ThreadStorage::Write(EItem type, const void* item, u32 itemSize
|
||||
m_BufferPos1 = start + size;
|
||||
}
|
||||
|
||||
void CProfiler2::ThreadStorage::WriteHold(EItem type, const void* item, u32 itemSize)
|
||||
{
|
||||
u32 size = 1 + itemSize;
|
||||
|
||||
if (m_HoldBuffers[m_HeldDepth - 1].pos + size > CProfiler2::HOLD_BUFFER_SIZE)
|
||||
return; // we held on too much data, ignore the rest
|
||||
|
||||
m_HoldBuffers[m_HeldDepth - 1].buffer[m_HoldBuffers[m_HeldDepth - 1].pos] = (u8)type;
|
||||
memcpy(&m_HoldBuffers[m_HeldDepth - 1].buffer[m_HoldBuffers[m_HeldDepth - 1].pos + 1], item, itemSize);
|
||||
|
||||
m_HoldBuffers[m_HeldDepth - 1].pos += size;
|
||||
}
|
||||
|
||||
std::string CProfiler2::ThreadStorage::GetBuffer()
|
||||
{
|
||||
// Called from an arbitrary thread (not the one writing to the buffer).
|
||||
@@ -416,24 +397,6 @@ void CProfiler2::ThreadStorage::RecordAttribute(const char* fmt, va_list argp)
|
||||
Write(ITEM_ATTRIBUTE, buffer, 4 + len);
|
||||
}
|
||||
|
||||
size_t CProfiler2::ThreadStorage::HoldLevel()
|
||||
{
|
||||
return m_HeldDepth;
|
||||
}
|
||||
|
||||
u8 CProfiler2::ThreadStorage::HoldType()
|
||||
{
|
||||
ENSURE(m_HeldDepth > 0);
|
||||
return m_HoldBuffers[m_HeldDepth - 1].type;
|
||||
}
|
||||
|
||||
void CProfiler2::ThreadStorage::PutOnHold(u8 newType)
|
||||
{
|
||||
m_HeldDepth++;
|
||||
m_HoldBuffers[m_HeldDepth - 1].clear();
|
||||
m_HoldBuffers[m_HeldDepth - 1].setType(newType);
|
||||
}
|
||||
|
||||
// this flattens the stack, use it sensibly
|
||||
void rewriteBuffer(u8* buffer, u32& bufferSize)
|
||||
{
|
||||
@@ -618,7 +581,7 @@ void rewriteBuffer(u8* buffer, u32& bufferSize)
|
||||
if (time_attrib != time_per_attribute.end())
|
||||
basic += " " + CStr::FromInt(1000000*time_attrib->second) + "us";
|
||||
|
||||
u32 length = basic.size();
|
||||
u32 length = static_cast<u32>(basic.size());
|
||||
memcpy(buffer + writePos, &length, sizeof(length));
|
||||
writePos += sizeof(length);
|
||||
memcpy(buffer + writePos, basic.c_str(), length);
|
||||
@@ -675,56 +638,6 @@ void rewriteBuffer(u8* buffer, u32& bufferSize)
|
||||
bufferSize = writePos;
|
||||
}
|
||||
|
||||
void CProfiler2::ThreadStorage::HoldToBuffer(bool condensed)
|
||||
{
|
||||
ENSURE(m_HeldDepth);
|
||||
if (condensed)
|
||||
{
|
||||
// rewrite the buffer to show aggregated data
|
||||
rewriteBuffer(m_HoldBuffers[m_HeldDepth - 1].buffer, m_HoldBuffers[m_HeldDepth - 1].pos);
|
||||
}
|
||||
|
||||
if (m_HeldDepth > 1)
|
||||
{
|
||||
// copy onto buffer below
|
||||
HoldBuffer& copied = m_HoldBuffers[m_HeldDepth - 1];
|
||||
HoldBuffer& target = m_HoldBuffers[m_HeldDepth - 2];
|
||||
if (target.pos + copied.pos > HOLD_BUFFER_SIZE)
|
||||
return; // too much data, too bad
|
||||
|
||||
memcpy(&target.buffer[target.pos], copied.buffer, copied.pos);
|
||||
|
||||
target.pos += copied.pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 size = m_HoldBuffers[m_HeldDepth - 1].pos;
|
||||
u32 start = m_BufferPos0;
|
||||
if (start + size > BUFFER_SIZE)
|
||||
{
|
||||
m_BufferPos0 = size;
|
||||
COMPILER_FENCE;
|
||||
memset(m_Buffer + start, 0, BUFFER_SIZE - start);
|
||||
start = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_BufferPos0 = start + size;
|
||||
COMPILER_FENCE; // must write m_BufferPos0 before m_Buffer
|
||||
}
|
||||
memcpy(&m_Buffer[start], m_HoldBuffers[m_HeldDepth - 1].buffer, size);
|
||||
COMPILER_FENCE; // must write m_BufferPos1 after m_Buffer
|
||||
m_BufferPos1 = start + size;
|
||||
}
|
||||
m_HeldDepth--;
|
||||
}
|
||||
void CProfiler2::ThreadStorage::ThrowawayHoldBuffer()
|
||||
{
|
||||
if (!m_HeldDepth)
|
||||
return;
|
||||
m_HeldDepth--;
|
||||
}
|
||||
|
||||
void CProfiler2::ConstructJSONOverview(std::ostream& stream)
|
||||
{
|
||||
TIMER(L"profile2 overview");
|
||||
@@ -955,45 +868,3 @@ void CProfiler2::SaveToFile()
|
||||
}
|
||||
stream << "\n]});\n";
|
||||
}
|
||||
|
||||
CProfile2SpikeRegion::CProfile2SpikeRegion(const char* name, double spikeLimit) :
|
||||
m_Name(name), m_Limit(spikeLimit), m_PushedHold(true)
|
||||
{
|
||||
if (g_Profiler2.HoldLevel() < 8 && (g_Profiler2.HoldLevel() == 0 || g_Profiler2.HoldType() != CProfiler2::ThreadStorage::BUFFER_AGGREGATE))
|
||||
g_Profiler2.HoldMessages(CProfiler2::ThreadStorage::BUFFER_SPIKE);
|
||||
else
|
||||
m_PushedHold = false;
|
||||
COMPILER_FENCE;
|
||||
g_Profiler2.RecordRegionEnter(m_Name);
|
||||
m_StartTime = g_Profiler2.GetTime();
|
||||
}
|
||||
CProfile2SpikeRegion::~CProfile2SpikeRegion()
|
||||
{
|
||||
double time = g_Profiler2.GetTime();
|
||||
g_Profiler2.RecordRegionLeave();
|
||||
bool shouldWrite = time - m_StartTime > m_Limit;
|
||||
|
||||
if (m_PushedHold)
|
||||
g_Profiler2.StopHoldingMessages(shouldWrite);
|
||||
}
|
||||
|
||||
CProfile2AggregatedRegion::CProfile2AggregatedRegion(const char* name, double spikeLimit) :
|
||||
m_Name(name), m_Limit(spikeLimit), m_PushedHold(true)
|
||||
{
|
||||
if (g_Profiler2.HoldLevel() < 8 && (g_Profiler2.HoldLevel() == 0 || g_Profiler2.HoldType() != CProfiler2::ThreadStorage::BUFFER_AGGREGATE))
|
||||
g_Profiler2.HoldMessages(CProfiler2::ThreadStorage::BUFFER_AGGREGATE);
|
||||
else
|
||||
m_PushedHold = false;
|
||||
COMPILER_FENCE;
|
||||
g_Profiler2.RecordRegionEnter(m_Name);
|
||||
m_StartTime = g_Profiler2.GetTime();
|
||||
}
|
||||
CProfile2AggregatedRegion::~CProfile2AggregatedRegion()
|
||||
{
|
||||
double time = g_Profiler2.GetTime();
|
||||
g_Profiler2.RecordRegionLeave();
|
||||
bool shouldWrite = time - m_StartTime > m_Limit;
|
||||
|
||||
if (m_PushedHold)
|
||||
g_Profiler2.StopHoldingMessages(shouldWrite, true);
|
||||
}
|
||||
|
||||
@@ -96,8 +96,6 @@ class CProfiler2GPU;
|
||||
class CProfiler2
|
||||
{
|
||||
friend class CProfiler2GPUARB;
|
||||
friend class CProfile2SpikeRegion;
|
||||
friend class CProfile2AggregatedRegion;
|
||||
public:
|
||||
// Items stored in the buffers:
|
||||
|
||||
@@ -141,8 +139,6 @@ private:
|
||||
ThreadStorage(CProfiler2& profiler, const std::string& name);
|
||||
~ThreadStorage();
|
||||
|
||||
enum { BUFFER_NORMAL, BUFFER_SPIKE, BUFFER_AGGREGATE };
|
||||
|
||||
void RecordSyncMarker(double t)
|
||||
{
|
||||
// Store the magic string followed by the absolute time
|
||||
@@ -185,12 +181,6 @@ private:
|
||||
va_end(argp);
|
||||
}
|
||||
|
||||
size_t HoldLevel();
|
||||
u8 HoldType();
|
||||
void PutOnHold(u8 type);
|
||||
void HoldToBuffer(bool condensed);
|
||||
void ThrowawayHoldBuffer();
|
||||
|
||||
CProfiler2& GetProfiler()
|
||||
{
|
||||
return m_Profiler;
|
||||
@@ -223,36 +213,6 @@ private:
|
||||
|
||||
u8* m_Buffer;
|
||||
|
||||
struct HoldBuffer
|
||||
{
|
||||
friend class ThreadStorage;
|
||||
public:
|
||||
HoldBuffer()
|
||||
{
|
||||
buffer = new u8[HOLD_BUFFER_SIZE];
|
||||
memset(buffer, ITEM_NOP, HOLD_BUFFER_SIZE);
|
||||
pos = 0;
|
||||
}
|
||||
~HoldBuffer()
|
||||
{
|
||||
delete[] buffer;
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
pos = 0;
|
||||
}
|
||||
void setType(u8 newType)
|
||||
{
|
||||
type = newType;
|
||||
}
|
||||
u8* buffer;
|
||||
u32 pos;
|
||||
u8 type;
|
||||
};
|
||||
|
||||
HoldBuffer m_HoldBuffers[8];
|
||||
size_t m_HeldDepth;
|
||||
|
||||
// To allow hopefully-safe reading of the buffer from a separate thread,
|
||||
// without any expensive synchronisation in the recording thread,
|
||||
// two copies of the current buffer write position are stored.
|
||||
@@ -372,32 +332,6 @@ public:
|
||||
void RecordGPURegionEnter(const char* id);
|
||||
void RecordGPURegionLeave(const char* id);
|
||||
|
||||
/**
|
||||
* Hold onto messages until a call to release or write the held messages.
|
||||
*/
|
||||
size_t HoldLevel()
|
||||
{
|
||||
return GetThreadStorage().HoldLevel();
|
||||
}
|
||||
|
||||
u8 HoldType()
|
||||
{
|
||||
return GetThreadStorage().HoldType();
|
||||
}
|
||||
|
||||
void HoldMessages(u8 type)
|
||||
{
|
||||
GetThreadStorage().PutOnHold(type);
|
||||
}
|
||||
|
||||
void StopHoldingMessages(bool writeToBuffer, bool condensed = false)
|
||||
{
|
||||
if (writeToBuffer)
|
||||
GetThreadStorage().HoldToBuffer(condensed);
|
||||
else
|
||||
GetThreadStorage().ThrowawayHoldBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call in any thread to produce a JSON representation of the general
|
||||
* state of the application.
|
||||
@@ -478,36 +412,6 @@ protected:
|
||||
const char* m_Name;
|
||||
};
|
||||
|
||||
/**
|
||||
* Scope-based enter/leave helper.
|
||||
*/
|
||||
class CProfile2SpikeRegion
|
||||
{
|
||||
public:
|
||||
CProfile2SpikeRegion(const char* name, double spikeLimit);
|
||||
~CProfile2SpikeRegion();
|
||||
private:
|
||||
const char* m_Name;
|
||||
double m_Limit;
|
||||
double m_StartTime;
|
||||
bool m_PushedHold;
|
||||
};
|
||||
|
||||
/**
|
||||
* Scope-based enter/leave helper.
|
||||
*/
|
||||
class CProfile2AggregatedRegion
|
||||
{
|
||||
public:
|
||||
CProfile2AggregatedRegion(const char* name, double spikeLimit);
|
||||
~CProfile2AggregatedRegion();
|
||||
private:
|
||||
const char* m_Name;
|
||||
double m_Limit;
|
||||
double m_StartTime;
|
||||
bool m_PushedHold;
|
||||
};
|
||||
|
||||
/**
|
||||
* Scope-based GPU enter/leave helper.
|
||||
*/
|
||||
@@ -535,10 +439,6 @@ private:
|
||||
*/
|
||||
#define PROFILE2(region) CProfile2Region profile2__(region)
|
||||
|
||||
#define PROFILE2_IFSPIKE(region, limit) CProfile2SpikeRegion profile2__(region, limit)
|
||||
|
||||
#define PROFILE2_AGGREGATED(region, limit) CProfile2AggregatedRegion profile2__(region, limit)
|
||||
|
||||
#define PROFILE2_GPU(region) CProfile2GPURegion profile2gpu__(region)
|
||||
|
||||
/**
|
||||
|
||||
@@ -1018,8 +1018,6 @@ const CComponentManager::InterfaceListUnordered& CComponentManager::GetEntitiesW
|
||||
|
||||
void CComponentManager::PostMessage(entity_id_t ent, const CMessage& msg)
|
||||
{
|
||||
PROFILE2_IFSPIKE("Post Message", 0.0005);
|
||||
PROFILE2_ATTR("%s", msg.GetScriptHandlerName());
|
||||
// Send the message to components of ent, that subscribed locally to this message
|
||||
std::map<MessageTypeId, std::vector<ComponentTypeId> >::const_iterator it;
|
||||
it = m_LocalMessageSubscriptions.find(msg.GetType());
|
||||
@@ -1070,8 +1068,6 @@ void CComponentManager::BroadcastMessage(const CMessage& msg)
|
||||
|
||||
void CComponentManager::SendGlobalMessage(entity_id_t ent, const CMessage& msg)
|
||||
{
|
||||
PROFILE2_IFSPIKE("SendGlobalMessage", 0.001);
|
||||
PROFILE2_ATTR("%s", msg.GetScriptHandlerName());
|
||||
// (Common functionality for PostMessage and BroadcastMessage)
|
||||
|
||||
// Send the message to components of all entities that subscribed globally to this message
|
||||
|
||||
Reference in New Issue
Block a user