Changeset a35b458 in mainline for uspace/dist/src/c/demos/top


Ignore:
Timestamp:
2018-03-02T20:10:49Z (8 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

Location:
uspace/dist/src/c/demos/top
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/dist/src/c/demos/top/screen.c

    r3061bc1 ra35b458  
    9898{
    9999        screen_style_normal();
    100        
     100
    101101        if (clear) {
    102102                console_flush(console);
    103103                console_clear(console);
    104104        }
    105        
     105
    106106        screen_moveto(0, 0);
    107107}
     
    112112        sysarg_t rows;
    113113        screen_get_size(&cols, &rows);
    114        
     114
    115115        sysarg_t c;
    116116        sysarg_t r;
    117117        screen_get_pos(&c, &r);
    118        
     118
    119119        sysarg_t i;
    120120        for (i = c + 1; i < cols; i++)
    121121                puts(" ");
    122        
     122
    123123        if (r + 1 < rows)
    124124                puts("\n");
     
    128128{
    129129        console = console_init(stdin, stdout);
    130        
     130
    131131        console_flush(console);
    132132        console_cursor_visibility(console, false);
    133        
     133
    134134        screen_restart(true);
    135135}
     
    141141
    142142        screen_restart(true);
    143        
     143
    144144        console_flush(console);
    145145        console_cursor_visibility(console, true);
     
    149149{
    150150        printf("%3" PRIu64 ".", ffloat.upper / ffloat.lower);
    151        
     151
    152152        unsigned int i;
    153153        uint64_t rest = (ffloat.upper % ffloat.lower) * 10;
     
    156156                rest = (rest % ffloat.lower) * 10;
    157157        }
    158        
     158
    159159        printf("%%");
    160160}
     
    165165        sysarg_t rows;
    166166        screen_get_size(&cols, &rows);
    167        
     167
    168168        sysarg_t c;
    169169        sysarg_t r;
    170170        screen_get_pos(&c, &r);
    171        
     171
    172172        if (c < cols) {
    173173                int pos = cols - c - 1;
     
    183183            data->hours, data->minutes, data->seconds,
    184184            data->udays, data->uhours, data->uminutes, data->useconds);
    185        
     185
    186186        size_t i;
    187187        for (i = 0; i < data->load_count; i++) {
     
    189189                stats_print_load_fragment(data->load[i], 2);
    190190        }
    191        
     191
    192192        screen_newline();
    193193}
     
    208208        size_t other = 0;
    209209        size_t invalid = 0;
    210        
     210
    211211        size_t i;
    212212        for (i = 0; i < data->threads_count; i++) {
    213213                total++;
    214                
     214
    215215                switch (data->threads[i].state) {
    216216                case Running:
     
    234234                }
    235235        }
    236        
     236
    237237        printf("threads: %zu total, %zu running, %zu ready, "
    238238            "%zu sleeping, %zu lingering, %zu other, %zu invalid",
     
    250250                        char busy_suffix;
    251251                        char idle_suffix;
    252                        
     252
    253253                        order_suffix(data->cpus[i].busy_cycles, &busy, &busy_suffix);
    254254                        order_suffix(data->cpus[i].idle_cycles, &idle, &idle_suffix);
    255                        
     255
    256256                        printf("cpu%u (%4" PRIu16 " MHz): busy cycles: "
    257257                            "%" PRIu64 "%c, idle cycles: %" PRIu64 "%c",
     
    264264                } else
    265265                        printf("cpu%u inactive", data->cpus[i].id);
    266                
     266
    267267                screen_newline();
    268268        }
     
    279279        const char *used_suffix;
    280280        const char *free_suffix;
    281        
     281
    282282        bin_order_suffix(data->physmem->total, &total, &total_suffix, false);
    283283        bin_order_suffix(data->physmem->unavail, &unavail, &unavail_suffix, false);
    284284        bin_order_suffix(data->physmem->used, &used, &used_suffix, false);
    285285        bin_order_suffix(data->physmem->free, &free, &free_suffix, false);
    286        
     286
    287287        printf("memory: %" PRIu64 "%s total, %" PRIu64 "%s unavail, %"
    288288            PRIu64 "%s used, %" PRIu64 "%s free", total, total_suffix,
     
    304304        sysarg_t rows;
    305305        screen_get_size(&cols, &rows);
    306        
    307         screen_newline();
    308        
     306
     307        screen_newline();
     308
    309309        printf("Operation modes:");
    310310        screen_newline();
    311        
     311
    312312        printf(" t .. tasks statistics");
    313313        screen_newline();
    314        
     314
    315315        printf(" i .. IPC statistics");
    316316        screen_newline();
    317        
     317
    318318        printf(" e .. exceptions statistics");
    319319        screen_newline();
    320        
     320
    321321        printf("      a .. toggle display of all/hot exceptions");
    322322        screen_newline();
     
    329329        printf("Other keys:");
    330330        screen_newline();
    331        
     331
    332332        printf(" s .. choose column to sort by");
    333333        screen_newline();
    334        
     334
    335335        printf(" r .. toggle reversed sorting");
    336336        screen_newline();
    337        
     337
    338338        printf(" q .. quit");
    339339        screen_newline();
    340        
     340
    341341        sysarg_t col;
    342342        sysarg_t row;
    343343        screen_get_pos(&col, &row);
    344        
     344
    345345        while (row < rows) {
    346346                screen_newline();
     
    379379        sysarg_t rows;
    380380        screen_get_size(&cols, &rows);
    381        
     381
    382382        sysarg_t col;
    383383        sysarg_t row;
    384384        screen_get_pos(&col, &row);
    385        
     385
    386386        size_t i;
    387387        for (i = 0; (i < table->num_fields) && (row < rows); i++) {
     
    440440                }
    441441        }
    442        
     442
    443443        while (row < rows) {
    444444                screen_newline();
     
    452452        sysarg_t rows;
    453453        screen_get_size(&cols, &rows);
    454        
     454
    455455        sysarg_t col;
    456456        sysarg_t row;
     
    463463                row++;
    464464        }
    465        
     465
    466466        while (row < rows) {
    467467                screen_newline();
     
    493493        print_physmem_info(data);
    494494        print_warning();
    495        
     495
    496496        switch (screen_mode) {
    497497        case SCREEN_TABLE:
     
    506506                print_help();
    507507        }
    508        
     508
    509509        console_flush(console);
    510510}
     
    526526        vsnprintf(warning_text, warning_text_size, fmt, args);
    527527        va_end(args);
    528        
     528
    529529        warning_timeleft = 2 * USEC_COUNT;
    530530
     
    542542         * Reset timeleft whenever it is not positive.
    543543         */
    544        
     544
    545545        if (timeleft <= 0)
    546546                timeleft = sec * USEC_COUNT;
    547        
     547
    548548        /*
    549549         * Wait to see if there is any input. If so, take it and
     
    552552         * make timeleft zero and return -1.
    553553         */
    554        
     554
    555555        wchar_t c = 0;
    556        
     556
    557557        while (c == 0) {
    558558                cons_event_t event;
    559                
     559
    560560                warning_timeleft -= timeleft;
    561561                if (!console_get_event_timeout(console, &event, &timeleft)) {
     
    564564                }
    565565                warning_timeleft += timeleft;
    566                
     566
    567567                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS)
    568568                        c = event.ev.key.c;
    569569        }
    570        
     570
    571571        return (int) c;
    572572}
  • uspace/dist/src/c/demos/top/top.c

    r3061bc1 ra35b458  
    152152        target->table.num_fields = 0;
    153153        target->table.fields = NULL;
    154        
     154
    155155        /* Get current time */
    156156        struct timeval time;
    157157        gettimeofday(&time, NULL);
    158        
     158
    159159        target->hours = (time.tv_sec % DAY) / HOUR;
    160160        target->minutes = (time.tv_sec % HOUR) / MINUTE;
    161161        target->seconds = time.tv_sec % MINUTE;
    162        
     162
    163163        /* Get uptime */
    164164        struct timeval uptime;
    165165        getuptime(&uptime);
    166        
     166
    167167        target->udays = uptime.tv_sec / DAY;
    168168        target->uhours = (uptime.tv_sec % DAY) / HOUR;
    169169        target->uminutes = (uptime.tv_sec % HOUR) / MINUTE;
    170170        target->useconds = uptime.tv_sec % MINUTE;
    171        
     171
    172172        /* Get load */
    173173        target->load = stats_get_load(&(target->load_count));
    174174        if (target->load == NULL)
    175175                return "Cannot get system load";
    176        
     176
    177177        /* Get CPUs */
    178178        target->cpus = stats_get_cpus(&(target->cpus_count));
    179179        if (target->cpus == NULL)
    180180                return "Cannot get CPUs";
    181        
     181
    182182        target->cpus_perc =
    183183            (perc_cpu_t *) calloc(target->cpus_count, sizeof(perc_cpu_t));
    184184        if (target->cpus_perc == NULL)
    185185                return "Not enough memory for CPU utilization";
    186        
     186
    187187        /* Get tasks */
    188188        target->tasks = stats_get_tasks(&(target->tasks_count));
    189189        if (target->tasks == NULL)
    190190                return "Cannot get tasks";
    191        
     191
    192192        target->tasks_perc =
    193193            (perc_task_t *) calloc(target->tasks_count, sizeof(perc_task_t));
    194194        if (target->tasks_perc == NULL)
    195195                return "Not enough memory for task utilization";
    196        
     196
    197197        /* Get threads */
    198198        target->threads = stats_get_threads(&(target->threads_count));
    199199        if (target->threads == NULL)
    200200                return "Cannot get threads";
    201        
     201
    202202        /* Get Exceptions */
    203203        target->exceptions = stats_get_exceptions(&(target->exceptions_count));
    204204        if (target->exceptions == NULL)
    205205                return "Cannot get exceptions";
    206        
     206
    207207        target->exceptions_perc =
    208208            (perc_exc_t *) calloc(target->exceptions_count, sizeof(perc_exc_t));
    209209        if (target->exceptions_perc == NULL)
    210210                return "Not enough memory for exception utilization";
    211        
     211
    212212        /* Get physical memory */
    213213        target->physmem = stats_get_physmem();
    214214        if (target->physmem == NULL)
    215215                return "Cannot get physical memory";
    216        
     216
    217217        target->ucycles_diff = calloc(target->tasks_count,
    218218            sizeof(uint64_t));
    219219        if (target->ucycles_diff == NULL)
    220220                return "Not enough memory for user utilization";
    221        
     221
    222222        /* Allocate memory for computed values */
    223223        target->kcycles_diff = calloc(target->tasks_count,
     
    225225        if (target->kcycles_diff == NULL)
    226226                return "Not enough memory for kernel utilization";
    227        
     227
    228228        target->ecycles_diff = calloc(target->exceptions_count,
    229229            sizeof(uint64_t));
    230230        if (target->ecycles_diff == NULL)
    231231                return "Not enough memory for exception cycles utilization";
    232        
     232
    233233        target->ecount_diff = calloc(target->exceptions_count,
    234234            sizeof(uint64_t));
    235235        if (target->ecount_diff == NULL)
    236236                return "Not enough memory for exception count utilization";
    237        
     237
    238238        return NULL;
    239239}
     
    249249        /* For each CPU: Compute total cycles and divide it between
    250250           user and kernel */
    251        
     251
    252252        size_t i;
    253253        for (i = 0; i < new_data->cpus_count; i++) {
     
    257257                    new_data->cpus[i].busy_cycles - old_data->cpus[i].busy_cycles;
    258258                uint64_t sum = idle + busy;
    259                
     259
    260260                FRACTION_TO_FLOAT(new_data->cpus_perc[i].idle, idle * 100, sum);
    261261                FRACTION_TO_FLOAT(new_data->cpus_perc[i].busy, busy * 100, sum);
    262262        }
    263        
     263
    264264        /* For all tasks compute sum and differencies of all cycles */
    265        
     265
    266266        uint64_t virtmem_total = 0;
    267267        uint64_t resmem_total = 0;
    268268        uint64_t ucycles_total = 0;
    269269        uint64_t kcycles_total = 0;
    270        
     270
    271271        for (i = 0; i < new_data->tasks_count; i++) {
    272272                /* Match task with the previous instance */
    273                
     273
    274274                bool found = false;
    275275                size_t j;
     
    280280                        }
    281281                }
    282                
     282
    283283                if (!found) {
    284284                        /* This is newly borned task, ignore it */
     
    287287                        continue;
    288288                }
    289                
     289
    290290                new_data->ucycles_diff[i] =
    291291                    new_data->tasks[i].ucycles - old_data->tasks[j].ucycles;
    292292                new_data->kcycles_diff[i] =
    293293                    new_data->tasks[i].kcycles - old_data->tasks[j].kcycles;
    294                
     294
    295295                virtmem_total += new_data->tasks[i].virtmem;
    296296                resmem_total += new_data->tasks[i].resmem;
     
    298298                kcycles_total += new_data->kcycles_diff[i];
    299299        }
    300        
     300
    301301        /* For each task compute percential change */
    302        
     302
    303303        for (i = 0; i < new_data->tasks_count; i++) {
    304304                FRACTION_TO_FLOAT(new_data->tasks_perc[i].virtmem,
     
    311311                    new_data->kcycles_diff[i] * 100, kcycles_total);
    312312        }
    313        
     313
    314314        /* For all exceptions compute sum and differencies of cycles */
    315        
     315
    316316        uint64_t ecycles_total = 0;
    317317        uint64_t ecount_total = 0;
    318        
     318
    319319        for (i = 0; i < new_data->exceptions_count; i++) {
    320320                /*
     
    323323                 * usually disappear, but it does not hurt.
    324324                 */
    325                
     325
    326326                bool found = false;
    327327                size_t j;
     
    332332                        }
    333333                }
    334                
     334
    335335                if (!found) {
    336336                        /* This is a new exception, ignore it */
     
    339339                        continue;
    340340                }
    341                
     341
    342342                new_data->ecycles_diff[i] =
    343343                    new_data->exceptions[i].cycles - old_data->exceptions[j].cycles;
    344344                new_data->ecount_diff[i] =
    345345                    new_data->exceptions[i].count - old_data->exceptions[i].count;
    346                
     346
    347347                ecycles_total += new_data->ecycles_diff[i];
    348348                ecount_total += new_data->ecount_diff[i];
    349349        }
    350        
     350
    351351        /* For each exception compute percential change */
    352        
     352
    353353        for (i = 0; i < new_data->exceptions_count; i++) {
    354354                FRACTION_TO_FLOAT(new_data->exceptions_perc[i].cycles,
     
    363363        field_t *fa = (field_t *)a + sort_column;
    364364        field_t *fb = (field_t *)b + sort_column;
    365        
     365
    366366        if (fa->type > fb->type)
    367367                return 1 * sort_reverse;
     
    535535        if (target->load != NULL)
    536536                free(target->load);
    537        
     537
    538538        if (target->cpus != NULL)
    539539                free(target->cpus);
    540        
     540
    541541        if (target->cpus_perc != NULL)
    542542                free(target->cpus_perc);
    543        
     543
    544544        if (target->tasks != NULL)
    545545                free(target->tasks);
    546        
     546
    547547        if (target->tasks_perc != NULL)
    548548                free(target->tasks_perc);
    549        
     549
    550550        if (target->threads != NULL)
    551551                free(target->threads);
    552        
     552
    553553        if (target->exceptions != NULL)
    554554                free(target->exceptions);
    555        
     555
    556556        if (target->exceptions_perc != NULL)
    557557                free(target->exceptions_perc);
    558        
     558
    559559        if (target->physmem != NULL)
    560560                free(target->physmem);
    561        
     561
    562562        if (target->ucycles_diff != NULL)
    563563                free(target->ucycles_diff);
    564        
     564
    565565        if (target->kcycles_diff != NULL)
    566566                free(target->kcycles_diff);
    567        
     567
    568568        if (target->ecycles_diff != NULL)
    569569                free(target->ecycles_diff);
    570        
     570
    571571        if (target->ecount_diff != NULL)
    572572                free(target->ecount_diff);
     
    581581        data_t data_prev;
    582582        const char *ret = NULL;
    583        
     583
    584584        screen_init();
    585585        printf("Reading initial data...\n");
    586        
     586
    587587        if ((ret = read_data(&data)) != NULL)
    588588                goto out;
    589        
     589
    590590        /* Compute some rubbish to have initialised values */
    591591        compute_percentages(&data, &data);
    592        
     592
    593593        /* And paint screen until death */
    594594        while (true) {
     
    601601                                goto out;
    602602                        }
    603                        
     603
    604604                        compute_percentages(&data_prev, &data);
    605605                        free_data(&data_prev);
     
    671671                print_data(&data);
    672672        }
    673        
     673
    674674out:
    675675        screen_done();
    676676        free_data(&data);
    677        
     677
    678678        if (ret != NULL) {
    679679                fprintf(stderr, "%s: %s\n", NAME, ret);
    680680                return 1;
    681681        }
    682        
     682
    683683        return 0;
    684684}
  • uspace/dist/src/c/demos/top/top.h

    r3061bc1 ra35b458  
    112112        time_t minutes;
    113113        time_t seconds;
    114        
     114
    115115        sysarg_t udays;
    116116        sysarg_t uhours;
    117117        sysarg_t uminutes;
    118118        sysarg_t useconds;
    119        
     119
    120120        size_t load_count;
    121121        load_t *load;
    122        
     122
    123123        size_t cpus_count;
    124124        stats_cpu_t *cpus;
    125125        perc_cpu_t *cpus_perc;
    126        
     126
    127127        size_t tasks_count;
    128128        stats_task_t *tasks;
    129129        perc_task_t *tasks_perc;
    130        
     130
    131131        size_t threads_count;
    132132        stats_thread_t *threads;
    133        
     133
    134134        size_t exceptions_count;
    135135        stats_exc_t *exceptions;
    136136        perc_exc_t *exceptions_perc;
    137        
     137
    138138        stats_physmem_t *physmem;
    139        
     139
    140140        uint64_t *ucycles_diff;
    141141        uint64_t *kcycles_diff;
Note: See TracChangeset for help on using the changeset viewer.