48 unsigned short episodes;
52 #define DETAILED_AGGREGATES 0
54 #define MAX_CATEGORIES 32
57 static struct aggregate aggregates[LIST_LEN];
59 static int aggregates_list_ptr = 0;
62 static struct aggregate *
63 find_aggregate_category(
const uint16_t cat)
71 for(i = 0; i < aggregates_list_ptr; ++i) {
72 acat = (aggregates[i].ptr[0] << 8) + aggregates[i].ptr[1];
78 return &aggregates[i];
86 aggregates[aggregates_list_ptr].ptr =
NULL;
87 return &aggregates[aggregates_list_ptr++];
90 #if DETAILED_AGGREGATES
91 static struct aggregate *
92 find_aggregate(
const unsigned char *ptr)
95 for(i = 0; i < aggregates_list_ptr; ++i) {
96 if(aggregates[i].ptr == ptr) {
97 return &aggregates[i];
104 return &aggregates[aggregates_list_ptr++];
109 profile_aggregates_print(
void)
113 #if DETAILED_AGGREGATES
114 for(i = 0; i < aggregates_list_ptr; ++i) {
115 printf(
"-- %s: %lu / %u = %lu\n", aggregates[i].ptr,
116 aggregates[i].cycles,
117 aggregates[i].episodes,
118 aggregates[i].cycles / aggregates[i].episodes);
121 for(i = 0; i < aggregates_list_ptr; ++i) {
122 printf(
"-- %c%c: %lu / %u = %lu\n",
123 aggregates[i].ptr[0], aggregates[i].ptr[1],
124 aggregates[i].cycles,
125 aggregates[i].episodes,
126 aggregates[i].cycles / aggregates[i].episodes);
130 printf(
"Memory for aggregates: %d * %d = %d\n",
131 (
int)
sizeof(
struct aggregate), aggregates_list_ptr,
132 (
int)
sizeof(
struct aggregate) * aggregates_list_ptr);
135 #if DETAILED_AGGREGATES
137 detailed_profile_aggregates_compute(
void)
145 t = profile_timestamps[0].time;
147 for(i = 1; i < PROFILE_TIMESTAMP_PTR; ++i) {
149 a = find_aggregate(profile_timestamps[i - 1].ptr);
152 printf(
"profile_aggregates_compute: list full\n");
153 }
else if(a->ptr ==
NULL) {
154 a->ptr = profile_timestamps[i - 1].ptr;
155 a->cycles = (
unsigned long)(profile_timestamps[i].time - t);
158 a->cycles += (
unsigned long)(profile_timestamps[i].time - t);
161 t = profile_timestamps[i].time;
176 category_profile_aggregates_compute(
void)
180 uint16_t categories[MAX_CATEGORIES];
181 int categories_ptr = 0;
186 t = profile_timestamps[0].time;
188 for(i = 1; i < PROFILE_TIMESTAMP_PTR; ++i) {
194 cat = (profile_timestamps[i - 1].ptr[0] << 8) +
195 (profile_timestamps[i - 1].ptr[1] & 0xff);
196 a = find_aggregate_category(cat);
199 printf(
"profile_aggregates_compute: list full\n");
200 }
else if(a->ptr ==
NULL) {
201 a->ptr = profile_timestamps[i - 1].ptr;
202 a->cycles = (
unsigned long)(profile_timestamps[i].time - t - profile_timestamp_time);
206 a->cycles += (
unsigned long)(profile_timestamps[i].time - t - profile_timestamp_time);
215 for(j = 0; j < categories_ptr; ++j) {
216 if(categories[j] == cat) {
220 if(j == categories_ptr) {
226 t = profile_timestamps[i].time;
240 profile_aggregates_compute(
void)
242 #if DETAILED_AGGREGATES
243 detailed_profile_aggregates_compute();
245 category_profile_aggregates_compute();