-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfiling.c
79 lines (58 loc) · 1.76 KB
/
Profiling.c
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
#include "VGA.h"
#include "System.h"
#include "Profiling.h"
#include <string.h> //memset
int lastframe;
int startline;
/* usage:
* call profiling_startframe before your frame-calculating/drawing operation,
* then call profiling_endframe afterwards
*
* profiling_endframe takes a pointer to a framebuffer line to output a cpuload line.
* Usually the last line of your current frame.
*
* Display: dropped frames are symbolized as white bars.
* Cpuload in the current frame is shown as a bar scaling to the end.
* That bar is green on 0 dropped frames, yellow on 1, red otherwise.
*/
void profiling_startframe()
{
lastframe = VGAFrame;
startline = VGALine;
}
// WARNING! only works for 400lines 60Hz
void profiling_endframe(uint8_t *outputline)
{
const int linestotal = 525; // we assume 525 lines, which is 60Hz
int endline = VGALine;
int lines = endline - startline;
if(lines<0){
lines += linestotal;
}
//FIXME: correctly handle endlines >440
int frames = VGAFrame - lastframe; // frames dropped
uint8_t colour = 7<<2; // no frames "dropped": green
if(frames==1) colour = 7<<2 | 7<<5; // 1 frame: yellow
if(frames>=2) colour = 7<<5; // 2 frames: red
uint16_t width = (lines * (320 - frames*32)) / linestotal;
width += frames*32;
if(width>=320){
width = 319;
}
if(width<0){ width = 0; }
// draw lost frames as white segments
for(int j=0; j<frames; ++j){
for(int i=0; i<20; ++i){
outputline[j*32+i] = 0xff;
}
for(int i=20; i<32; ++i){
outputline[j*32+i] = 0x00;
}
}
for(int i=frames*32; i<width; ++i){
outputline[i] = colour;
}
for(int i=width; i<320; ++i){
outputline[i] = 0x00;
}
}