Created
July 1, 2013 08:56
-
-
Save jvcleave/5899386 to your computer and use it in GitHub Desktop.
FPS Logger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include "ofMain.h" | |
| class FPSLogger | |
| { | |
| public: | |
| int numSamples; | |
| float frameSampleTotal; | |
| int fpsSampleRate; | |
| void update(ofEventArgs & a) | |
| { | |
| if (ofGetFrameNum() % fpsSampleRate == 0) | |
| { | |
| frameSampleTotal+=ofGetFrameRate(); | |
| numSamples++; | |
| } | |
| } | |
| void exit(ofEventArgs & a) | |
| { | |
| if (numSamples>0 && frameSampleTotal>0) | |
| { | |
| float averageFPS = frameSampleTotal/numSamples; | |
| ofBuffer buffer = ofToString(averageFPS); | |
| string fileName = ofToDataPath(ofGetTimestampString()+"_FPS.log", true); | |
| bool didWriteFile = ofBufferToFile(fileName, buffer); | |
| if(didWriteFile) | |
| { | |
| ofLogVerbose() << fileName << " write PASS"; | |
| }else | |
| { | |
| ofLogError() << fileName << " write FAIL"; | |
| } | |
| } | |
| ofRemoveListener(ofEvents().update, this, &FPSLogger::update); | |
| ofRemoveListener(ofEvents().exit, this, &FPSLogger::exit); | |
| } | |
| FPSLogger() | |
| { | |
| numSamples = 0; | |
| frameSampleTotal = 0.0f; | |
| fpsSampleRate = 5; | |
| ofAddListener(ofEvents().update, this, &FPSLogger::update); | |
| ofAddListener(ofEvents().exit, this, &FPSLogger::exit); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment