/alps/pcitool

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to cli.c

  • Committer: Suren A. Chilingaryan
  • Date: 2011-12-13 21:21:24 UTC
  • Revision ID: csa@dside.dyndns.org-20111213212124-ja6i09tkd03m359l
Do event counting when rawcallback is used to stream the data

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <fastwriter.h>
26
26
 
27
27
#include "pcitool/sysinfo.h"
 
28
#include "pcitool/formaters.h"
28
29
 
29
30
//#include "pci.h"
30
31
#include "tools.h"
44
45
#define BLOCK_SEPARATOR_WIDTH 2
45
46
#define BLOCK_SIZE 8
46
47
#define BENCHMARK_ITERATIONS 128
47
 
#define STATUS_MESSAGE_INTERVAL 5       /* seconds */
 
48
#define STATUS_MESSAGE_INTERVAL 1//5    /* seconds */
48
49
 
49
50
 
50
51
#define isnumber pcilib_isnumber
1107
1108
    size_t run_time;
1108
1109
    size_t trigger_time;    
1109
1110
    size_t max_triggers;
 
1111
    pcilib_event_flags_t flags;
1110
1112
    
1111
1113
    volatile int event_pending;                 /**< Used to detect that we have read previously triggered event */
1112
1114
    volatile int trigger_thread_started;        /**< Indicates that trigger thread is ready and we can't procced to start event recording */
1186
1188
 
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) {
1188
1190
    int err;
1189
 
    static size_t sum = 0;
1190
1191
 
1191
1192
    GRABContext *ctx = (GRABContext*)user;
1192
1193
//    pcilib_t *handle = ctx->handle;
1193
1194
 
1194
 
    gettimeofday(&ctx->last_frame, NULL);
1195
 
 
1196
 
    sum += size;
1197
 
//    printf("raw: %zu\n", sum);
 
1195
 
 
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));
 
1200
        }
 
1201
 
 
1202
        ctx->event_count++;
 
1203
        ctx->missing_count += (info->seqnum - ctx->last_num) - 1;
 
1204
        ctx->last_num = info->seqnum;
 
1205
    }
 
1206
 
1198
1207
    err = fastwriter_push_data(ctx->writer, size, data);
1199
1208
    if (err) {
1200
1209
        if (err == EWOULDBLOCK) Error("Storage is not able to handle the data stream, buffer overrun");
1237
1246
    return NULL;
1238
1247
}
1239
1248
 
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);
1250
 
}
1251
 
 
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);
1260
 
}
1261
 
 
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);
1269
 
}
1270
 
 
1271
 
void PrintPercent(size_t num, size_t total) {
1272
 
    if (num >= total) printf(" 100");
1273
 
    printf("%4.1lf", 100.*num/total);
1274
 
    
1275
 
}
1276
 
 
1277
1249
void GrabStats(GRABContext *ctx, struct timeval *end_time) {
1278
1250
    int verbose;
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;
1283
1255
 
1284
1256
    verbose = ctx->verbose;
1285
1257
    
1291
1263
        gettimeofday(&cur, NULL);
1292
1264
        end_time = &cur;
1293
1265
    }
1294
 
        
 
1266
 
 
1267
    if ((ctx->event_count + ctx->missing_count) == 0) 
 
1268
        return;
 
1269
    
1295
1270
    duration = pcilib_timediff(&ctx->start_time, end_time);
1296
1271
    fps_duration = pcilib_timediff(&ctx->first_frame, &ctx->last_frame);
1297
1272
    
1325
1300
    PrintNumber(ctx->event_count);
1326
1301
    printf(" FPS %5.0lf", fps);
1327
1302
 
1328
 
    printf(", Stored: ");
1329
 
    PrintNumber(good);
1330
 
    printf(" FPS %5.0lf", good_fps);
 
1303
    if ((ctx->flags&PCILIB_EVENT_FLAG_RAW_DATA_ONLY) == 0) {
 
1304
        printf(", Stored: ");
 
1305
        PrintNumber(good);
 
1306
        printf(" FPS %5.0lf", good_fps);
 
1307
    }
1331
1308
 
1332
1309
    printf("\n");    
1333
1310
 
1334
1311
    if (verbose > 2) {
1335
 
        printf("Good: ");
1336
 
        PrintNumber(good);
1337
 
        printf(", Dropped: ");
1338
 
        PrintNumber(ctx->storage_count);
1339
 
        printf(", Broken: ");
1340
 
        PrintNumber(ctx->broken_count);
1341
 
        printf(", Bad: ");
1342
 
        PrintNumber(ctx->incomplete_count);
 
1312
        if (ctx->flags&PCILIB_EVENT_FLAG_RAW_DATA_ONLY) {
 
1313
            printf("Captured: ");
 
1314
            PrintNumber(good);
 
1315
        } else {
 
1316
            printf("Good: ");
 
1317
            PrintNumber(good);
 
1318
            printf(", Dropped: ");
 
1319
            PrintNumber(ctx->storage_count);
 
1320
            printf(", Broken: ");
 
1321
            PrintNumber(ctx->broken_count);
 
1322
            printf(", Bad: ");
 
1323
            PrintNumber(ctx->incomplete_count);
 
1324
        }
1343
1325
        printf(", Lost: ");
1344
1326
        PrintNumber(ctx->missing_count);
1345
1327
        if (ctx->trigger_count) {
1350
1332
    }
1351
1333
 
1352
1334
    if (verbose > 1) {
1353
 
        printf("Good: ");
1354
 
        PrintPercent(good, total);
1355
 
        printf("%% Dropped: ");
1356
 
        PrintPercent(ctx->storage_count, total);
1357
 
        printf("%% Broken: ");
1358
 
        PrintPercent(ctx->broken_count, total);
1359
 
        printf("%% Bad: ");
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);
 
1338
        } else {
 
1339
            printf("Good: ");
 
1340
            PrintPercent(good, total);
 
1341
            printf("%% Dropped: ");
 
1342
            PrintPercent(ctx->storage_count, total);
 
1343
            printf("%% Broken: ");
 
1344
            PrintPercent(ctx->broken_count, total);
 
1345
            printf("%% Bad: ");
 
1346
            PrintPercent(ctx->incomplete_count, total);
 
1347
        }
 
1348
 
 
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);
1396
 
    
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);
1398
1384
}
1399
1385
 
1400
1386
void *Monitor(void *user) {
1534
1520
    } else {
1535
1521
        flags |= PCILIB_EVENT_FLAG_PREPROCESS;
1536
1522
    }
 
1523
    
 
1524
    ctx.flags = flags;
1537
1525
 
1538
1526
//    printf("Limits: %lu %lu %lu\n", num, run_time, timeout);
1539
1527
    pcilib_configure_autostop(handle, num, run_time);
1726
1714
    return (*n_uses)++;
1727
1715
}
1728
1716
 
1729
 
 
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);
1735
 
    
1736
 
    return str;
1737
 
}
1738
 
 
1739
1717
int ListKMEM(pcilib_t *handle, const char *device) {
1740
1718
    DIR *dir;
1741
1719
    struct dirent *entry;