71 lines
1.5 KiB
C++
71 lines
1.5 KiB
C++
/* -----------------------------------------------------------------------------
|
|
nEngine - GSFramework
|
|
Copyright 2001-2011 Emmanuel Julien. All Rights Reserved.
|
|
------------------------------------------------------------------------------*/
|
|
|
|
|
|
#ifndef __NPROFILER_TOOLS__
|
|
#define __NPROFILER_TOOLS__
|
|
|
|
|
|
#include "color/color.h"
|
|
#include "nstring/nstring.h"
|
|
|
|
|
|
/*!
|
|
@short Core profiler tools.
|
|
@author Emmanuel Julien (ejulien@nworks.fr)
|
|
*/
|
|
namespace GS {
|
|
namespace Render {
|
|
class Renderer;
|
|
class RasterFont;
|
|
}
|
|
namespace Core {
|
|
|
|
enum NumberFormat
|
|
{
|
|
Count,
|
|
MemorySize
|
|
};
|
|
|
|
template <class T> const Color &GetColorCode(const T &v, const T &warning, const T &alert)
|
|
{
|
|
if (v > alert)
|
|
return Color::Red;
|
|
if (v > warning)
|
|
return Color::Green;
|
|
return Color::White;
|
|
}
|
|
|
|
/// Format a value to string.
|
|
template <class T> String FormatNumber(const T &v, NumberFormat format = Count)
|
|
{
|
|
switch (format)
|
|
{
|
|
case Count:
|
|
if (v < 1000)
|
|
return String::Format("%d", (int)v);
|
|
else if (v < 1000000)
|
|
return String::Format("%.01fK", (float)v / 1000);
|
|
return String::Format("%.01fM", (float)v / 1000000);
|
|
|
|
case MemorySize:
|
|
if (v < 1000)
|
|
return String::Format("%dB", (int)v);
|
|
else if (v < 1000000)
|
|
return String::Format("%.01fKB", (float)v / 1000.f);
|
|
return String::Format("%.01fMB", (float)v / 1000000.f);
|
|
}
|
|
return String() << v;
|
|
}
|
|
|
|
/// Draw allocator profiler text.
|
|
void DrawAllocProfilerText(Render::Renderer &, Render::RasterFont *[2], float &x, float &y, float width = 0, float height = 0);
|
|
|
|
} // Core
|
|
} // GS
|
|
|
|
|
|
#endif // __NPROFILER_TOOLS__
|