From 097edb90b7826ad7557777cc102de2630f235141 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Fri, 9 Dec 2011 08:24:01 +0100 Subject: Gathering a bit of statistics --- cli.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++------------ tools.c | 4 ++++ tools.h | 1 + 3 files changed, 62 insertions(+), 12 deletions(-) diff --git a/cli.c b/cli.c index 8fe4901..e2c8615 100644 --- a/cli.c +++ b/cli.c @@ -1084,15 +1084,18 @@ typedef struct { int started; /**< Indicates that recording is started */ int run_flag; - + + struct timeval first_frame; struct timeval last_frame; size_t trigger_count; - size_t frame_count; + size_t event_count; size_t broken_count; + struct timeval start_time; struct timeval stop_time; } GRABContext; +#include "ipecamera/ipecamera.h" int GrabCallback(pcilib_event_id_t event_id, pcilib_event_info_t *info, void *user) { int err; void *data; @@ -1101,12 +1104,22 @@ int GrabCallback(pcilib_event_id_t event_id, pcilib_event_info_t *info, void *us GRABContext *ctx = (GRABContext*)user; pcilib_t *handle = ctx->handle; + ipecamera_event_info_t *ipe = (ipecamera_event_info_t*)info; + gettimeofday(&ctx->last_frame, NULL); + + if (!ctx->event_count) { + memcpy(&ctx->first_frame, &ctx->last_frame, sizeof(struct timeval)); + } ctx->event_pending = 0; - ctx->frame_count++; - + ctx->event_count++; + if (info->flags&PCILIB_EVENT_INFO_FLAG_BROKEN) ctx->broken_count++; + +// printf("%lu %lu\n", info->seqnum, info->offset); + +// printf("%lu %lx %lu\n", ipe->raw_size, info->flags, ctx->broken_count); /* FILE *o = ctx->output; @@ -1126,7 +1139,7 @@ int GrabCallback(pcilib_event_id_t event_id, pcilib_event_info_t *info, void *us pcilib_return_data(handle, ctx->event, data); */ - printf("data callback: %lu\n", event_id); +// printf("data callback: %lu\n", event_id); } int raw_data(pcilib_event_id_t event_id, pcilib_event_info_t *info, pcilib_event_flags_t flags, size_t size, void *data, void *user) { @@ -1166,6 +1179,33 @@ void *Trigger(void *user) { return NULL; } +void GrabStats(GRABContext *ctx, struct timeval *end_time) { + pcilib_timeout_t duration, fps_duration; + struct timeval cur; + double fps; + + if (!end_time) { + gettimeofday(&cur, NULL); + end_time = &cur; + } + + duration = pcilib_timediff(&ctx->start_time, end_time); + + if (ctx->event_count > 1) { + fps_duration = pcilib_timediff(&ctx->first_frame, &ctx->last_frame); + fps = (ctx->event_count - 1) / (1.*fps_duration/1000000); + } + + if (duration > 100000000) printf("Time: %9lu s", duration/1000000); + else if (duration > 10000000) printf("Time: %9.1lf s", 1.*duration/1000000); + else if (duration > 1000000) printf("Time: %9.2lf s", 1.*duration/1000000); + else if (duration > 1000) printf("Time: %9lu ms", duration/1000); + else printf("Time: %9lu us", duration); + + printf(", Triggers: %9lu, Frames: %9lu, Broken: %9u, Lost: %9u, FPS: %5.1lf\n", ctx->trigger_count, ctx->event_count, ctx->broken_count, 0, fps); + +} + void *Monitor(void *user) { struct timeval deadline; @@ -1211,7 +1251,7 @@ int TriggerAndGrab(pcilib_t *handle, GRAB_MODE grab_mode, const char *event, con pthread_attr_t attr; struct sched_param sched; - struct timeval start, end; + struct timeval end_time; pcilib_event_flags_t flags; ctx.handle = handle; @@ -1220,7 +1260,8 @@ int TriggerAndGrab(pcilib_t *handle, GRAB_MODE grab_mode, const char *event, con ctx.run_time = run_time; ctx.timeout = timeout; - ctx.frame_count = 0; + ctx.event_count = 0; + ctx.broken_count = 0; ctx.started = 0; ctx.trigger_thread_started = 0; @@ -1259,7 +1300,7 @@ int TriggerAndGrab(pcilib_t *handle, GRAB_MODE grab_mode, const char *event, con while (!ctx.trigger_thread_started) usleep(10); } - gettimeofday(&start, NULL); + gettimeofday(&ctx.start_time, NULL); if (grab_mode&GRAB_MODE_GRAB) { err = pcilib_start(handle, PCILIB_EVENTS_ALL, PCILIB_EVENT_FLAGS_DEFAULT); @@ -1269,18 +1310,18 @@ int TriggerAndGrab(pcilib_t *handle, GRAB_MODE grab_mode, const char *event, con ctx.started = 1; if (run_time) { - ctx.stop_time.tv_usec = start.tv_usec + run_time%1000000; + ctx.stop_time.tv_usec = ctx.start_time.tv_usec + run_time%1000000; if (ctx.stop_time.tv_usec > 999999) { ctx.stop_time.tv_usec -= 1000000; __sync_synchronize(); - ctx.stop_time.tv_sec = start.tv_sec + 1 + run_time / 1000000; + ctx.stop_time.tv_sec = ctx.start_time.tv_sec + 1 + run_time / 1000000; } else { __sync_synchronize(); - ctx.stop_time.tv_sec = start.tv_sec + run_time / 1000000; + ctx.stop_time.tv_sec = ctx.start_time.tv_sec + run_time / 1000000; } } - memcpy(&ctx.last_frame, &start, sizeof(struct timeval)); + memcpy(&ctx.last_frame, &ctx.start_time, sizeof(struct timeval)); if (pthread_create(&monitor_thread, NULL, Monitor, (void*)&ctx)) Error("Error spawning monitoring thread"); @@ -1299,6 +1340,8 @@ int TriggerAndGrab(pcilib_t *handle, GRAB_MODE grab_mode, const char *event, con pcilib_stop(handle, PCILIB_EVENT_FLAGS_DEFAULT); } + gettimeofday(&end_time, NULL); + /* err = pcilib_grab(handle, PCILIB_EVENTS_ALL, &size, &data, PCILIB_TIMEOUT_TRIGGER); if (err) { @@ -1312,6 +1355,8 @@ int TriggerAndGrab(pcilib_t *handle, GRAB_MODE grab_mode, const char *event, con pthread_join(trigger_thread, NULL); } + GrabStats(&ctx, &end_time); + // print information return 0; diff --git a/tools.c b/tools.c index 4874f7f..c673258 100644 --- a/tools.c +++ b/tools.c @@ -310,6 +310,10 @@ int pcilib_sleep_until_deadline(struct timeval *tv) { return 0; } +pcilib_timeout_t pcilib_timediff(struct timeval *tvs, struct timeval *tve) { + return ((tve->tv_sec - tvs->tv_sec)*1000000 + (tve->tv_usec - tvs->tv_usec)); +} + int pcilib_timecmp(struct timeval *tv1, struct timeval *tv2) { if (tv1->tv_sec > tv2->tv_sec) return 1; else if (tv1->tv_sec > tv2->tv_sec) return -1; diff --git a/tools.h b/tools.h index 8ab931d..009fd68 100644 --- a/tools.h +++ b/tools.h @@ -40,5 +40,6 @@ int pcilib_check_deadline(struct timeval *tve, pcilib_timeout_t timeout); pcilib_timeout_t pcilib_calc_time_to_deadline(struct timeval *tve); int pcilib_sleep_until_deadline(struct timeval *tv); int pcilib_timecmp(struct timeval *tv1, struct timeval *tv2); +pcilib_timeout_t pcilib_timediff(struct timeval *tve, struct timeval *tvs); #endif /* _PCITOOL_TOOS_H */ -- cgit v1.2.3