Example #1
0
void util_json_object_add_tstat (json_object *o, const char *name,
                                 tstat_t *ts, double scale)
{
    json_object *to = util_json_object_new_object ();

    util_json_object_add_int (to, "count", tstat_count (ts));
    util_json_object_add_double (to, "min", tstat_min (ts)*scale);
    util_json_object_add_double (to, "mean", tstat_mean (ts)*scale);
    util_json_object_add_double (to, "stddev", tstat_stddev (ts)*scale);
    util_json_object_add_double (to, "max", tstat_max (ts)*scale);

    json_object_object_add (o, name, to);
}
Example #2
0
int main (int argc, char *argv[])
{
    thd_t *thd;
    int i, rc;
    int ch;
    tstat_t ts;
    struct timespec t0;

    log_init (basename (argv[0]));

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'f':
                fopt = true;
                fence_nprocs = strtoul (optarg, NULL, 10);
                if (!fence_nprocs)
                    log_msg_exit ("fence value must be > 0");
                break;
            case 's':
                sopt = true;
                break;
            case 'n':
                nopt = true;
                nopt_divisor = strtoul (optarg, NULL, 10);
                if (!nopt_divisor)
                    log_msg_exit ("nopt value must be > 0");
                break;
            default:
                usage ();
        }
    }
    if (argc - optind != 3)
        usage ();

    nthreads = strtoul (argv[optind++], NULL, 10);
    if (!nthreads)
        log_msg_exit ("thread count must be > 0");
    count = strtoul (argv[optind++], NULL, 10);
    if (!count)
        log_msg_exit ("commit count must be > 0");
    prefix = argv[optind++];

    memset (&ts, 0, sizeof (ts));

    thd = xzmalloc (sizeof (*thd) * nthreads);

    if (sopt)
        monotime (&t0);

    for (i = 0; i < nthreads; i++) {
        thd[i].n = i;
        if (!(thd[i].perf = zlist_new ()))
            oom ();
        if ((rc = pthread_attr_init (&thd[i].attr)))
            log_errn (rc, "pthread_attr_init");
        if ((rc = pthread_create (&thd[i].t, &thd[i].attr, thread, &thd[i])))
            log_errn (rc, "pthread_create");
    }

    for (i = 0; i < nthreads; i++) {
        if ((rc = pthread_join (thd[i].t, NULL)))
            log_errn (rc, "pthread_join");
        if (sopt) {
            double *e;
            while ((e = zlist_pop (thd[i].perf))) {
                tstat_push (&ts, *e);
                free (e);
            }
        }
        zlist_destroy (&thd[i].perf);
    }

    if (sopt) {
        json_t *o;
        char *s;

        if (!(o = json_pack ("{s:{s:i s:f s:f s:f s:f} s:f}",
                             "put+commit times (sec)",
                                 "count", tstat_count (&ts),
                                 "min", tstat_min (&ts)*1E-3,
                                 "mean", tstat_mean (&ts)*1E-3,
                                 "stddev", tstat_stddev (&ts)*1E-3,
                                 "max", tstat_max (&ts)*1E-3,
                             "put+commit throughput (#/sec)",
                             (double)(count*nthreads)
                                    / (monotime_since (t0)*1E-3))))
            log_err_exit ("json_pack");
        if (!(s = json_dumps (o, JSON_INDENT(2))))
            log_err_exit ("json_dumps");
        printf ("%s\n", s);
        json_decref (o);
        free (s);
    }

    free (thd);

    log_fini ();

    return 0;
}