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


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.