mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-06 06:43:21 +08:00
Add a new performance counter for measuring periodic/interval events.
This commit is contained in:
@@ -73,6 +73,20 @@ struct perf_ctr_elapsed {
|
|||||||
uint64_t time_most;
|
uint64_t time_most;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PC_INTERVAL counter.
|
||||||
|
*/
|
||||||
|
struct perf_ctr_interval {
|
||||||
|
struct perf_ctr_header hdr;
|
||||||
|
uint64_t event_count;
|
||||||
|
uint64_t time_event;
|
||||||
|
uint64_t time_first;
|
||||||
|
uint64_t time_last;
|
||||||
|
uint64_t time_least;
|
||||||
|
uint64_t time_most;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of all known counters.
|
* List of all known counters.
|
||||||
*/
|
*/
|
||||||
@@ -93,6 +107,10 @@ perf_alloc(enum perf_counter_type type, const char *name)
|
|||||||
ctr = (perf_counter_t)calloc(sizeof(struct perf_ctr_elapsed), 1);
|
ctr = (perf_counter_t)calloc(sizeof(struct perf_ctr_elapsed), 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PC_INTERVAL:
|
||||||
|
ctr = (perf_counter_t)calloc(sizeof(struct perf_ctr_interval), 1);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -127,6 +145,32 @@ perf_count(perf_counter_t handle)
|
|||||||
((struct perf_ctr_count *)handle)->event_count++;
|
((struct perf_ctr_count *)handle)->event_count++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PC_INTERVAL: {
|
||||||
|
struct perf_ctr_interval *pci = (struct perf_ctr_interval *)handle;
|
||||||
|
hrt_abstime now = hrt_absolute_time();
|
||||||
|
|
||||||
|
switch (pci->event_count) {
|
||||||
|
case 0:
|
||||||
|
pci->time_first = now;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
pci->time_least = now - pci->time_last;
|
||||||
|
pci->time_most = now - pci->time_last;
|
||||||
|
break;
|
||||||
|
default: {
|
||||||
|
hrt_abstime interval = now - pci->time_last;
|
||||||
|
if (interval < pci->time_least)
|
||||||
|
pci->time_least = interval;
|
||||||
|
if (interval > pci->time_most)
|
||||||
|
pci->time_most = interval;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pci->time_last = now;
|
||||||
|
pci->event_count++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -187,13 +231,29 @@ perf_print_counter(perf_counter_t handle)
|
|||||||
((struct perf_ctr_count *)handle)->event_count);
|
((struct perf_ctr_count *)handle)->event_count);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PC_ELAPSED:
|
case PC_ELAPSED: {
|
||||||
|
struct perf_ctr_elapsed *pce = (struct perf_ctr_elapsed *)handle;
|
||||||
|
|
||||||
printf("%s: %llu events, %lluus elapsed, min %lluus max %lluus\n",
|
printf("%s: %llu events, %lluus elapsed, min %lluus max %lluus\n",
|
||||||
handle->name,
|
handle->name,
|
||||||
((struct perf_ctr_elapsed *)handle)->event_count,
|
pce->event_count,
|
||||||
((struct perf_ctr_elapsed *)handle)->time_total,
|
pce->time_total,
|
||||||
((struct perf_ctr_elapsed *)handle)->time_least,
|
pce->time_least,
|
||||||
((struct perf_ctr_elapsed *)handle)->time_most);
|
pce->time_most);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case PC_INTERVAL: {
|
||||||
|
struct perf_ctr_interval *pci = (struct perf_ctr_interval *)handle;
|
||||||
|
|
||||||
|
printf("%s: %llu events, %llu avg, min %lluus max %lluus\n",
|
||||||
|
handle->name,
|
||||||
|
pci->event_count,
|
||||||
|
(pci->time_last - pci->time_first) / pci->event_count,
|
||||||
|
pci->time_least,
|
||||||
|
pci->time_most);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -44,7 +44,8 @@
|
|||||||
*/
|
*/
|
||||||
enum perf_counter_type {
|
enum perf_counter_type {
|
||||||
PC_COUNT, /**< count the number of times an event occurs */
|
PC_COUNT, /**< count the number of times an event occurs */
|
||||||
PC_ELAPSED /**< measure the time elapsed performing an event */
|
PC_ELAPSED, /**< measure the time elapsed performing an event */
|
||||||
|
PC_INTERVAL /**< measure the interval between instances of an event */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct perf_ctr_header;
|
struct perf_ctr_header;
|
||||||
|
|||||||
Reference in New Issue
Block a user