Conversion of nanoseconds to string.

This commit is contained in:
Bartosz Taudul 2017-09-18 22:11:38 +02:00
parent 05c8c1fa40
commit 9a38302d4a
2 changed files with 23 additions and 0 deletions

View File

@ -325,6 +325,28 @@ uint64_t View::GetLastTime() const
return last; return last;
} }
const char* View::TimeToString( uint64_t ns ) const
{
static char buf[64];
if( ns < 1000 )
{
sprintf( buf, "%i ns", ns );
}
else if( ns < 1000 * 1000 )
{
sprintf( buf, "%.2f us", ns / 1024.f );
}
else if( ns < 1000 * 1000 * 1000 )
{
sprintf( buf, "%.2f ms", ns / ( 1024.f * 1024 ) );
}
else
{
sprintf( buf, "%.2f s", ns / ( 1024.f * 1024 * 1024 ) );
}
return buf;
}
void View::Draw() void View::Draw()
{ {
s_instance->DrawImpl(); s_instance->DrawImpl();

View File

@ -50,6 +50,7 @@ private:
uint64_t GetFrameTime( size_t idx ) const; uint64_t GetFrameTime( size_t idx ) const;
uint64_t GetLastTime() const; uint64_t GetLastTime() const;
const char* TimeToString( uint64_t ns ) const;
void DrawImpl(); void DrawImpl();
void DrawFrames(); void DrawFrames();