42 #include "sys/clock.h"
50 TIMETABLE_NONSTATIC(profile_timetable);
52 TIMETABLE_NONSTATIC(profile_begin_timetable);
53 TIMETABLE_NONSTATIC(profile_end_timetable);
54 TIMETABLE_AGGREGATE(profile_aggregate, PROFILE_AGGREGATE_SIZE);
56 static rtimer_clock_t episode_start_time;
57 static unsigned int invalid_episode_overflow, invalid_episode_toolong,
63 #define XXX_HACK_FINE_TICKS_PER_COARSE_TICK (2457600/(32678/8))
70 timetable_clear(&profile_begin_timetable);
71 timetable_clear(&profile_end_timetable);
75 profile_episode_start(
void)
77 struct timetable_timestamp *e;
78 timetable_clear(&profile_begin_timetable);
79 timetable_clear(&profile_end_timetable);
82 e = timetable_entry(&profile_begin_timetable,
83 PROFILE_TIMETABLE_SIZE - 1);
87 e = timetable_entry(&profile_end_timetable,
88 PROFILE_TIMETABLE_SIZE - 1);
95 profile_episode_end(
void)
97 struct timetable_timestamp *e;
98 rtimer_clock_t episode_end_time =
clock_time();
101 e = timetable_entry(&profile_begin_timetable,
102 PROFILE_TIMETABLE_SIZE - 1);
105 invalid_episode_overflow++;
106 max_queuelen = PROFILE_TIMETABLE_SIZE;
107 }
else if(episode_end_time - episode_start_time >
108 65536/XXX_HACK_FINE_TICKS_PER_COARSE_TICK) {
110 invalid_episode_toolong++;
113 if(timetable_ptr(&profile_begin_timetable) > max_queuelen) {
114 max_queuelen = timetable_ptr(&profile_begin_timetable);
125 static struct timetable_aggregate_entry *
126 find_aggregate(
struct timetable_aggregate *a,
130 for(i = 0; i < a->ptr; ++i) {
131 if(a->entries[i].id ==
id) {
132 return &a->entries[i];
138 a->entries[a->ptr].id =
NULL;
139 return &a->entries[a->ptr++];
143 profile_aggregate_print_detailed(
void)
146 struct timetable_aggregate *a = &profile_aggregate;
149 for(i = 0; i < a->ptr; ++i) {
150 printf(
"-- %s: %lu / %u = %lu\n", a->entries[i].id,
152 a->entries[i].episodes,
153 a->entries[i].time / a->entries[i].episodes);
156 printf(
"Memory for entries: %d * %d = %d\n",
157 (
int)
sizeof(
struct timetable_aggregate), a->ptr,
158 (
int)
sizeof(
struct timetable_aggregate) * a->ptr);
162 profile_aggregate_compute_detailed(
void)
167 struct timetable_aggregate *a = &profile_aggregate;
168 struct timetable *timetable = &profile_timetable;
169 struct timetable_aggregate_entry *
entry;
171 last = timetable_ptr(&profile_begin_timetable);
172 t = profile_begin_timetable.timestamps[0].time;
173 for(i = 0; i < last; ++i) {
175 entry = find_aggregate(a, profile_begin_timetable.timestamps[i].id);
179 }
else if(entry->id ==
NULL) {
181 entry->id = timetable->timestamps[i - 1].id;
182 entry->time = (
unsigned long)(timetable->timestamps[i].time - t -
187 entry->time += (
unsigned long)(timetable->timestamps[i].time - t -
191 t = timetable->timestamps[i].time;