Ignore:
Timestamp:
Aug 15, 2010, 6:56:09 PM (11 years ago)
Author:
sam
Message:

Implement the profiling system.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/debugfps.cpp

    r116 r122  
    1212#include "debugfps.h"
    1313#include "forge.h"
     14#include "profiler.h"
    1415
    1516/*
     
    2122    friend class DebugFps;
    2223
    23     static int const HISTORY = 30;
    24 
    2524private:
    26     float history[HISTORY];
    2725    Font *font;
    2826    int frame;
     
    3735    data = new DebugFpsData();
    3836
    39     for (int i = 0; i < DebugFpsData::HISTORY; i++)
    40         data->history[i] = 0.0f;
    4137    data->font = Forge::GetFont("gfx/font/ascii.png");
    4238    data->frame = 0;
     
    5248    Asset::TickGame(delta_time);
    5349
    54     data->history[data->frame % DebugFpsData::HISTORY] = delta_time;
    5550    data->frame++;
    5651
    57     float mean = 0.0f, max = 0.0f;
    58     for (int i = 0; i < DebugFpsData::HISTORY; i++)
    59     {
    60         mean += data->history[i];
    61         if (data->history[i] > max)
    62             max = data->history[i];
    63     }
    64     mean /= DebugFpsData::HISTORY;
     52    char buf[1024];
    6553
    66     char buf[1024];
    67     sprintf(buf, "%3.2f ms (%3.2f fps) -- max %3.2f ms -- #%i",
    68             1000.0f * mean, 1.0f / mean, 1000.0f * max, data->frame);
    69     data->font->Print(10, 10, buf);
    70     data->font->Print(11, 10, buf);
    71     data->font->Print(10, 11, buf);
     54    sprintf(buf, "%2.2f fps (%i)",
     55            1.0f / Profiler::GetMean(Profiler::STAT_TICK_FRAME), data->frame);
     56    data->font->PrintBold(10, 10, buf);
     57
     58    sprintf(buf, "Game   % 7.2f % 7.2f",
     59            1e3f * Profiler::GetMean(Profiler::STAT_TICK_GAME),
     60            1e3f * Profiler::GetMax(Profiler::STAT_TICK_GAME));
     61    data->font->PrintBold(10, 28, buf);
     62
     63    sprintf(buf, "Render % 7.2f % 7.2f",
     64            1e3f * Profiler::GetMean(Profiler::STAT_TICK_RENDER),
     65            1e3f * Profiler::GetMax(Profiler::STAT_TICK_RENDER));
     66    data->font->PrintBold(10, 46, buf);
     67
     68    sprintf(buf, "Blit   % 7.2f % 7.2f",
     69            1e3f * Profiler::GetMean(Profiler::STAT_TICK_BLIT),
     70            1e3f * Profiler::GetMax(Profiler::STAT_TICK_BLIT));
     71    data->font->PrintBold(10, 64, buf);
     72
     73    sprintf(buf, "Frame  % 7.2f % 7.2f",
     74            1e3f * Profiler::GetMean(Profiler::STAT_TICK_FRAME),
     75            1e3f * Profiler::GetMax(Profiler::STAT_TICK_FRAME));
     76    data->font->PrintBold(10, 82, buf);
    7277}
    7378
Note: See TracChangeset for help on using the changeset viewer.