forked from dhansel/Altair8800
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.cpp
117 lines (94 loc) · 2.38 KB
/
profile.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <Arduino.h>
#include "profile.h"
#include "disassembler.h"
#include "host.h"
#ifndef PROF_DISPLAY_INTERVAL
#define PROF_DISPLAY_INTERVAL 500000
#endif
#if USE_PROFILING>0
unsigned long prof_timer, prof_cycle_counter, prof_counter;
#if USE_PROFILING_DETAIL>0
unsigned long prof_detail_counter, prof_opcode_count[256];
void prof_reset_details()
{
prof_detail_counter = 0;
for(int i=0; i<256; i++) prof_opcode_count[i]=0;
}
void prof_print_details()
{
int i;
byte dummymem[3] = {0, 0, 0};
unsigned long total;
byte maxIdx;
float totalpct = 0.0;
total = 0;
for(i=0; i<256; i++) total += prof_opcode_count[i];
int num = 0;
while( totalpct<.99 )
{
maxIdx = 0;
for(i=1; i<256; i++)
if( prof_opcode_count[i] > prof_opcode_count[maxIdx] )
maxIdx = i;
if( prof_opcode_count[maxIdx]==0 )
break;
else
{
float pct = ((float) (prof_opcode_count[maxIdx])) / ((float) total);
totalpct += pct;
dummymem[0] = maxIdx;
Serial.print(prof_opcode_count[maxIdx]);
Serial.print(F(" = "));
Serial.print(pct * 100.0);
Serial.print(F("% = "));
Serial.print(totalpct * 100.0);
Serial.print(F("% : "));
disassemble(dummymem, 0);
Serial.print('\n');
prof_opcode_count[maxIdx] = 0;
}
}
}
#endif
void prof_reset()
{
#if USE_THROTTLE>0
// if using throttling then we call prof_check only every 10000
// instructions, so scale the counter accordingly
prof_counter = PROF_DISPLAY_INTERVAL / 10000;
#else
prof_counter = PROF_DISPLAY_INTERVAL;
#endif
prof_cycle_counter = 0;
prof_timer = micros();
}
void prof_print()
{
unsigned long now = micros();
unsigned long d = now - prof_timer;
float mhz = ((float) prof_cycle_counter) / ((float) d);
Serial.print(F("Performance: "));
Serial.print(prof_cycle_counter);
Serial.print(F(" cycles in "));
Serial.print(((float) d)/1000.0);
Serial.print(F(" msec = "));
Serial.print(mhz);
Serial.print(F(" MHz = "));
Serial.print(int(mhz/0.02+.5));
Serial.println(F("%"));
prof_reset();
#if USE_PROFILING_DETAIL>0
if( ++prof_detail_counter == 10 )
{
prof_print_details();
prof_reset_details();
}
#endif
prof_cycle_counter = 0;
prof_timer = now;
}
#else
#if USE_THROTTLE>0
#error USE_THROTTLE requires USE_PROFILING
#endif
#endif