afProfiler.cpp
资源名称:AirForce.rar [点击查看]
上传用户:kaiguan
上传日期:2007-10-28
资源大小:1074k
文件大小:2k
源码类别:
其他游戏
开发平台:
Visual C++
- #include "afProfiler.h"
- afList<afProfiler::ProfileInfo> afProfiler::timerList;
- LARGE_INTEGER afProfiler::globalBeginTime;
- afProfiler::afProfiler(const char* nName)
- {
- ProfileInfo pi;
- pi.name = nName;
- pi.time.QuadPart = 0;
- if(timerList.getSize()==0)
- afProfiler::globalBegin();
- listIndex = timerList.addTail(pi);
- }
- afProfiler::~afProfiler()
- {
- }
- /*void
- afProfiler::beginSection()
- {
- QueryPerformanceCounter(&beginTime);
- }
- void
- afProfiler::endSection()
- {
- LARGE_INTEGER& time = timerList.getAt(listIndex).time;
- LARGE_INTEGER tmpTime;
- QueryPerformanceCounter(&tmpTime);
- time.QuadPart += tmpTime.QuadPart - beginTime.QuadPart;
- }*/
- bool afProfiler::globalBegin()
- {
- if(timerList.getSize()!=0)
- return false;
- ProfileInfo pi;
- pi.name = "Overall";
- pi.time.QuadPart = 0;
- timerList.addTail(pi);
- QueryPerformanceCounter(&globalBeginTime);
- return true;
- }
- bool
- afProfiler::globalEnd()
- {
- if(timerList.getSize()==0)
- return false;
- ProfileInfo& pi = timerList.getAt(0);
- LARGE_INTEGER time;
- if(pi.name != "Overall")
- return false;
- pi.name = "Overall DONE";
- QueryPerformanceCounter(&time);
- pi.time.QuadPart = time.QuadPart - globalBeginTime.QuadPart;
- return true;
- }
- void afProfiler::logResult()
- {
- afLog::info("==============================================================");
- afLog::info("");
- afLog::info(" profiling results:");
- afLog::info("");
- if(timerList.getSize()==0)
- {
- afLog::info(" nothing profiled");
- afLog::info("");
- afLog::info("==============================================================");
- return;
- }
- ProfileInfo& globalPi = timerList.getAt(0);
- LARGE_INTEGER freq;
- afString str;
- if(globalPi.name!="Overall DONE" && !afProfiler::globalEnd())
- {
- afLog::error("calling afProfiler::globalEnd() failed");
- afLog::info("");
- afLog::info("==============================================================");
- return;
- }
- QueryPerformanceFrequency(&freq);
- afLog::info(" overall time: %.2f seconds", (double)globalPi.time.QuadPart / (double)freq.QuadPart);
- for(int i=1; i<timerList.getSize(); i++)
- {
- ProfileInfo& pi = timerList.getAt(i);
- double v = 100.0*(double)pi.time.QuadPart / (double)globalPi.time.QuadPart;
- str.set("%s %.2f", (v<10.0 ? " " : ""), v);
- afLog::info(str + "%%%% : " + pi.name);
- }
- afLog::info("");
- afLog::info("==============================================================");
- }