Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset acb9aa7 in mainline


Ignore:
Timestamp:
2017-12-22T14:43:40Z (4 years ago)
Author:
Petr Mánek <petr.manek@…>
Branches:
lfn, master
Children:
59958992
Parents:
e23b87b
git-author:
Petr Mánek <petr.manek@…> (2017-12-22 14:42:15)
git-committer:
Petr Mánek <petr.manek@…> (2017-12-22 14:43:40)
Message:

tmon: format data size

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tmon/burst_tests.c

    re23b87b racb9aa7  
    104104}
    105105
     106typedef struct tmon_unit {
     107        char prefix;
     108        uint64_t factor;
     109} tmon_unit_t;
     110
     111static const tmon_unit_t units[] = {
     112        { .prefix = 'E', .factor = 1ul << 60 },
     113        { .prefix = 'P', .factor = 1ul << 50 },
     114        { .prefix = 'T', .factor = 1ul << 40 },
     115        { .prefix = 'G', .factor = 1ul << 30 },
     116        { .prefix = 'M', .factor = 1ul << 20 },
     117        { .prefix = 'k', .factor = 1ul << 10 },
     118        { /* NULL-terminated */ }
     119};
     120
     121static char * format_size(double size, const char *fmt)
     122{
     123        int i;
     124        for (i = 0; units[i].prefix; ++i) {
     125                if (units[i].factor <= size)
     126                        break;
     127        }
     128
     129        char prefix[2] = { '\0', '\0' };
     130        double factor = 1;
     131
     132        if (units[i].prefix) {
     133                prefix[0] = units[i].prefix;
     134                factor = units[i].factor;
     135        }
     136
     137        const double div_size = size / factor;
     138        char *out = NULL;
     139        asprintf(&out, fmt, div_size, prefix);
     140
     141        return out;
     142}
     143
    106144static void print_params(const tmon_burst_test_params_t *params)
    107145{
    108146        printf(INDENT "Number of cycles: %d\n", params->cycles);
    109         printf(INDENT "Data size: %ld B\n", params->size);
     147
     148        char *str_size = format_size(params->size, "%0.3f %sB");
     149        printf(INDENT "Data size: %s\n", str_size);
     150        free(str_size);
    110151}
    111152
     
    118159
    119160        const size_t total_size = params->size * params->cycles;
    120         printf(INDENT "Total size: %ld B\n", total_size);
     161        char *str_total_size = format_size(total_size, "%0.3f %sB");
     162        printf(INDENT "Total size: %s\n", str_total_size);
     163        free(str_total_size);
    121164
    122165        const double speed = 1000.0 * (double) total_size / (double) duration;
    123         printf(INDENT "Average speed: %0.3f B/s\n", speed);
     166        char *str_speed = format_size(speed, "%0.3f %sB/s");
     167        printf(INDENT "Average speed: %s\n", str_speed);
     168        free(str_speed);
    124169}
    125170
Note: See TracChangeset for help on using the changeset viewer.