This repository was archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerfMon.cpp
More file actions
87 lines (79 loc) · 1.57 KB
/
PerfMon.cpp
File metadata and controls
87 lines (79 loc) · 1.57 KB
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
81
82
83
84
85
86
87
/*
Created: 4/22/2019 8:20:48 PM
Author: Jonathan Weber
Description: Library for monitoring
*/
#include "PerfMon.h"
PerfMon::PerfMon(Debug* debugport, uint32_t newReportTime)
{
itsPort = debugport;
reportTime = newReportTime;
}
PerfMon::~PerfMon()
{
}
void PerfMon::Reset()
{
FPSCheckTimer.reset();
frames = 0;
}
void PerfMon::handler()
{
static unsigned long lastMicros;
static unsigned long longestMicros;
if (FPSCheckTimer.passed(reportTime))
{
char FPSprefix = ' ';
char LONGprefix;
float LongPrefixDivider = 1;
float fps = FPSCheckTimer.getTime(); //temporary assignment to check non-zero condition
if (fps == 0)
{
fps == 1;
}
fps = (float)frames / fps; //We will use real time instead of ideal time here. Good for lower frame rates.
FPSCheckTimer.reset();
fps *= 1000; //The above is frames per millisecond
if (fps >= 1000)
{
if (fps >= 1000000)
{
FPSprefix = 'M';
fps /= 1000000.0;
}
else
{
FPSprefix = 'k';
fps /= 1000.0;
}
}
if (longestMicros < 1000000)
{
if (longestMicros < 1000) // microseconds
{
LONGprefix = 'u';
}
else //milliseconds
{
LONGprefix = 'm';
LongPrefixDivider = 1000;
}
}
else
{
LongPrefixDivider = 1000000;
}
itsPort->Message(DM_TIMING, String(fps, 1) + FPSprefix + "FPS (Longest: " + String((double)longestMicros / LongPrefixDivider, 1) + LONGprefix + "s) ");
longestMicros = 0;
frames = 0;
}
else
{
frames++;
if ((micros() - lastMicros) > longestMicros)
{
longestMicros = micros() - lastMicros;
}
lastMicros = micros();
}
}