This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PROF.H
executable file
·80 lines (58 loc) · 1.69 KB
/
PROF.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//classes for profiling
#ifndef _PROF_
#define _PROF_
#include "uutimer.h"
unsigned gettime(); //gets the current time in milliseconds
//maintains a count of events
class profcounter
{
protected:
unsigned cnt; //current count
unsigned lastcnt;
float rate; //rate of increase/sec
float divisor;
public:
void clear() {cnt=0; lastcnt=0;}
profcounter(float _divisor):divisor(_divisor) {clear();}
profcounter():divisor(1.0) {clear();}
inline void inc() {cnt++;} //increment counter
inline void add(unsigned num) {cnt+=num;} //increment counter by num
void update(float dt) //update rate over dt (dt is in secs)
{rate=((float)(cnt-lastcnt))/dt/divisor; lastcnt=cnt;}
float getrate() {return rate;}
unsigned getcnt() {return cnt;}
void draw(char *desc,int x,int y);
};
//times the duration of events
class proftimer:public profcounter
{
unsigned entertime;
public:
proftimer():profcounter(10.0) {}
//enters/leaves a section
inline void enter() {entertime=gettime();}
inline void leave() {add(gettime()-entertime);}
void draw(char *desc,int x,int y);
void drawmeter(char *desc,int x,int y,byte c);
};
//profcounters used in this app
struct anesprofile
{
uutimer updatetimer;
profcounter tiles; //tiles drawn per second
profcounter cycles; //cycles per second
profcounter frames; //frames per second
profcounter vframes; //vframes per second
proftimer cpu_timer;
proftimer nesdraw_timer;
proftimer gui_timer;
proftimer input_timer;
proftimer pageflip_timer;
proftimer pageclear_timer;
proftimer sound_timer;
anesprofile();
void update();
void draw(int x,int y);
};
extern anesprofile pf;
#endif