Skip to content

Instantly share code, notes, and snippets.

@jvcleave
Created July 1, 2013 08:56
Show Gist options
  • Select an option

  • Save jvcleave/5899386 to your computer and use it in GitHub Desktop.

Select an option

Save jvcleave/5899386 to your computer and use it in GitHub Desktop.
FPS Logger
#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