Skip to content

Instantly share code, notes, and snippets.

@benkaiser
Created November 6, 2014 02:39
Show Gist options
  • Select an option

  • Save benkaiser/fd3d5d4e664a219ae447 to your computer and use it in GitHub Desktop.

Select an option

Save benkaiser/fd3d5d4e664a219ae447 to your computer and use it in GitHub Desktop.
frame_counter
// constants
var MISSED_FRAMES = 10;
// application
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var timestamps = [];
rl.on('line', function(line){
if(line){
// it exists, add it on
var words = line.split(" ");
timestamps.push(+words[words.length - 1]);
} else {
// calculte
var duration = timestamps[timestamps.length - 1] - timestamps[0];
var frame_length = duration / timestamps.length;
var frame_rate = 1000 / frame_length;
console.log(frame_rate * MISSED_FRAMES);
// reset
timestamps = [];
}
});
@benkaiser

Copy link
Copy Markdown
Author

This was a quick script I chucked together to count the number of frames per second in an android app I was developing. It's static and doesn't show on the device, so it is of very limited usefulness, but it solved the task I wanted of getting rough estimates of the frames per second.

To use, simply run the app, paste in the adb input, with the timestamps as the last element, then press enter twice to see the calculated frames per second.

Here is some example usage:

$ node frame_counter.js
01-01 11:39:52.690    8100-8100/com.someapp I/System.out 946687192693
01-01 11:39:52.970    8100-8100/com.someapp I/System.out 946687192974
01-01 11:39:53.235    8100-8100/com.someapp I/System.out 946687193240
01-01 11:39:53.485    8100-8100/com.someapp I/System.out 946687193490
01-01 11:39:53.800    8100-8100/com.someapp I/System.out 946687193803
01-01 11:39:54.040    8100-8100/com.someapp I/System.out 946687194044
01-01 11:39:54.345    8100-8100/com.someapp I/System.out 946687194348
01-01 11:39:54.680    8100-8100/com.someapp I/System.out 946687194682
01-01 11:39:54.975    8100-8100/com.someapp I/System.out 946687194978
01-01 11:39:55.270    8100-8100/com.someapp I/System.out 946687195274
01-01 11:39:55.535    8100-8100/com.someapp I/System.out 946687195538
01-01 11:39:55.780    8100-8100/com.someapp I/System.out 946687195783
01-01 11:39:56.080    8100-8100/com.someapp I/System.out 946687196081
01-01 11:39:56.325    8100-8100/com.someapp I/System.out 946687196327
01-01 11:39:56.585    8100-8100/com.someapp I/System.out 946687196589
01-01 11:39:56.820    8100-8100/com.someapp I/System.out 946687196823
01-01 11:39:57.120    8100-8100/com.someapp I/System.out 946687197122
01-01 11:39:57.350    8100-8100/com.someapp I/System.out 946687197351
01-01 11:39:57.640    8100-8100/com.someapp I/System.out 946687197638
01-01 11:39:57.900    8100-8100/com.someapp I/System.out 946687197905
01-01 11:39:58.185    8100-8100/com.someapp I/System.out 946687198187
01-01 11:39:58.505    8100-8100/com.someapp I/System.out 946687198509
01-01 11:39:58.785    8100-8100/com.someapp I/System.out 946687198790
01-01 11:39:59.090    8100-8100/com.someapp I/System.out 946687199095

37.488284910965326

Customize the MISSED_FRAMES variables to skip frames (so that the sending to adb doesn't effect the performance too much. For my example, I was using 10 like so:

if(cnt++ % 10 == 0) {
    System.out.println(System.currentTimeMillis());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment