1187
1189
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) {
1189
static size_t sum = 0;
1191
1192
GRABContext *ctx = (GRABContext*)user;
1192
1193
// pcilib_t *handle = ctx->handle;
1194
gettimeofday(&ctx->last_frame, NULL);
1197
// printf("raw: %zu\n", sum);
1196
if ((info)&&(info->seqnum != ctx->last_num)) {
1197
gettimeofday(&ctx->last_frame, NULL);
1198
if (!ctx->event_count) {
1199
memcpy(&ctx->first_frame, &ctx->last_frame, sizeof(struct timeval));
1203
ctx->missing_count += (info->seqnum - ctx->last_num) - 1;
1204
ctx->last_num = info->seqnum;
1198
1207
err = fastwriter_push_data(ctx->writer, size, data);
1200
1209
if (err == EWOULDBLOCK) Error("Storage is not able to handle the data stream, buffer overrun");
1240
void PrintTime(pcilib_timeout_t duration) {
1241
if (duration > 999999999999) printf("%4.1lf""d", 1.*duration/86400000000);
1242
else if (duration > 99999999999) printf("%4.1lf""h", 1.*duration/3600000000);
1243
else if (duration > 9999999999) printf("%4.2lf""h", 1.*duration/3600000000);
1244
else if (duration > 999999999) printf("%4.1lf""m", 1.*duration/60000000);
1245
else if (duration > 99999999) printf("%4.2lf""m", 1.*duration/60000000);
1246
else if (duration > 9999999) printf("%4.1lf""s", 1.*duration/1000000);
1247
else if (duration > 999999) printf("%4.2lf""s", 1.*duration/1000000);
1248
else if (duration > 999) printf("%3lu""ms", duration/1000);
1249
else printf("%3lu""us", duration);
1252
void PrintNumber(size_t num) {
1253
if (num > 999999999999999999) printf("%3lue", num/1000000000000000000);
1254
else if (num > 999999999999999) printf("%3lup", num/1000000000000000);
1255
else if (num > 999999999999) printf("%3lut", num/1000000000000);
1256
else if (num > 999999999) printf("%3lug", num/1000000000);
1257
else if (num > 999999) printf("%3lum", num/1000000);
1258
else if (num > 9999) printf("%3luk", num/1000);
1259
else printf("%4lu", num);
1262
void PrintSize(size_t num) {
1263
if (num >= 112589990684263) printf("%4.1lf PB", 1.*num/1125899906842624);
1264
else if (num >= 109951162778) printf("%4.1lf TB", 1.*num/1099511627776);
1265
else if (num >= 107374183) printf("%4.1lf GB", 1.*num/1073741824);
1266
else if (num >= 1048576) printf("%4lu MB", num/1048576);
1267
else if (num >= 1024) printf("%4lu KB", num/1024);
1268
else printf("%5lu B", num);
1271
void PrintPercent(size_t num, size_t total) {
1272
if (num >= total) printf(" 100");
1273
printf("%4.1lf", 100.*num/total);
1277
1249
void GrabStats(GRABContext *ctx, struct timeval *end_time) {
1279
1251
pcilib_timeout_t duration, fps_duration;
1280
1252
struct timeval cur;
1281
1253
double fps = 0, good_fps = 0;
1282
size_t total, good, pending;
1254
size_t total, good, pending = 0;
1284
1256
verbose = ctx->verbose;
1325
1300
PrintNumber(ctx->event_count);
1326
1301
printf(" FPS %5.0lf", fps);
1328
printf(", Stored: ");
1330
printf(" FPS %5.0lf", good_fps);
1303
if ((ctx->flags&PCILIB_EVENT_FLAG_RAW_DATA_ONLY) == 0) {
1304
printf(", Stored: ");
1306
printf(" FPS %5.0lf", good_fps);
1334
1311
if (verbose > 2) {
1337
printf(", Dropped: ");
1338
PrintNumber(ctx->storage_count);
1339
printf(", Broken: ");
1340
PrintNumber(ctx->broken_count);
1342
PrintNumber(ctx->incomplete_count);
1312
if (ctx->flags&PCILIB_EVENT_FLAG_RAW_DATA_ONLY) {
1313
printf("Captured: ");
1318
printf(", Dropped: ");
1319
PrintNumber(ctx->storage_count);
1320
printf(", Broken: ");
1321
PrintNumber(ctx->broken_count);
1323
PrintNumber(ctx->incomplete_count);
1343
1325
printf(", Lost: ");
1344
1326
PrintNumber(ctx->missing_count);
1345
1327
if (ctx->trigger_count) {
1352
1334
if (verbose > 1) {
1354
PrintPercent(good, total);
1355
printf("%% Dropped: ");
1356
PrintPercent(ctx->storage_count, total);
1357
printf("%% Broken: ");
1358
PrintPercent(ctx->broken_count, total);
1360
PrintPercent(ctx->incomplete_count, total);
1361
printf("%% Lost: ");
1335
if (ctx->flags&PCILIB_EVENT_FLAG_RAW_DATA_ONLY) {
1336
printf("Captured: ");
1337
PrintPercent(good, total);
1340
PrintPercent(good, total);
1341
printf("%% Dropped: ");
1342
PrintPercent(ctx->storage_count, total);
1343
printf("%% Broken: ");
1344
PrintPercent(ctx->broken_count, total);
1346
PrintPercent(ctx->incomplete_count, total);
1349
printf("%% Lost: ");
1362
1350
PrintPercent(ctx->missing_count, total);
1363
1351
if (ctx->trigger_count) {
1364
1352
printf("%% Pending: ");
1393
1381
printf(" of ");
1394
1382
PrintSize(st.buffer_size);
1395
1383
printf(" buffer (%6.2lf%% max)\n", 100.*st.buffer_max / st.buffer_size);
1397
// printf("Lost %6.2lf%% (% 8lu of % 8lu), %9.3lf GB at %8.3lf MB/s, buf:%6.2lf%%\n", 100.*(lost - last_lost) / (lost + frames - (last_lost + last_frames)), lost - last_lost, lost + frames - (last_lost + last_frames), 1. * (frames - last_frames) * width * height / 1024 / 1024 / 1024, 1. * (frames - last_frames) * width * height / (tv.tv_sec - last_written) / 1024 / 1024, max_fill);
1400
1386
void *Monitor(void *user) {
1726
1714
return (*n_uses)++;
1730
char *GetPrintSize(char *str, size_t size) {
1731
if (size >= 1073741824) sprintf(str, "%.1lf GB", 1.*size / 1073741824);
1732
else if (size >= 1048576) sprintf(str, "%.1lf MB", 1.*size / 1048576);
1733
else if (size >= 1024) sprintf(str, "%lu KB", size / 1024);
1734
else sprintf(str, "%lu B ", size);
1739
1717
int ListKMEM(pcilib_t *handle, const char *device) {
1741
1719
struct dirent *entry;