Changeset a35b458 in mainline for uspace/app/top/top.c


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/top/top.c

    r3061bc1 ra35b458  
    153153        target->table.num_fields = 0;
    154154        target->table.fields = NULL;
    155        
     155
    156156        /* Get current time */
    157157        struct timeval time;
    158158        gettimeofday(&time, NULL);
    159        
     159
    160160        target->hours = (time.tv_sec % DAY) / HOUR;
    161161        target->minutes = (time.tv_sec % HOUR) / MINUTE;
    162162        target->seconds = time.tv_sec % MINUTE;
    163        
     163
    164164        /* Get uptime */
    165165        struct timeval uptime;
    166166        getuptime(&uptime);
    167        
     167
    168168        target->udays = uptime.tv_sec / DAY;
    169169        target->uhours = (uptime.tv_sec % DAY) / HOUR;
    170170        target->uminutes = (uptime.tv_sec % HOUR) / MINUTE;
    171171        target->useconds = uptime.tv_sec % MINUTE;
    172        
     172
    173173        /* Get load */
    174174        target->load = stats_get_load(&(target->load_count));
    175175        if (target->load == NULL)
    176176                return "Cannot get system load";
    177        
     177
    178178        /* Get CPUs */
    179179        target->cpus = stats_get_cpus(&(target->cpus_count));
    180180        if (target->cpus == NULL)
    181181                return "Cannot get CPUs";
    182        
     182
    183183        target->cpus_perc =
    184184            (perc_cpu_t *) calloc(target->cpus_count, sizeof(perc_cpu_t));
    185185        if (target->cpus_perc == NULL)
    186186                return "Not enough memory for CPU utilization";
    187        
     187
    188188        /* Get tasks */
    189189        target->tasks = stats_get_tasks(&(target->tasks_count));
    190190        if (target->tasks == NULL)
    191191                return "Cannot get tasks";
    192        
     192
    193193        target->tasks_perc =
    194194            (perc_task_t *) calloc(target->tasks_count, sizeof(perc_task_t));
    195195        if (target->tasks_perc == NULL)
    196196                return "Not enough memory for task utilization";
    197        
     197
    198198        /* Get threads */
    199199        target->threads = stats_get_threads(&(target->threads_count));
    200200        if (target->threads == NULL)
    201201                return "Cannot get threads";
    202        
     202
    203203        /* Get Exceptions */
    204204        target->exceptions = stats_get_exceptions(&(target->exceptions_count));
    205205        if (target->exceptions == NULL)
    206206                return "Cannot get exceptions";
    207        
     207
    208208        target->exceptions_perc =
    209209            (perc_exc_t *) calloc(target->exceptions_count, sizeof(perc_exc_t));
    210210        if (target->exceptions_perc == NULL)
    211211                return "Not enough memory for exception utilization";
    212        
     212
    213213        /* Get physical memory */
    214214        target->physmem = stats_get_physmem();
    215215        if (target->physmem == NULL)
    216216                return "Cannot get physical memory";
    217        
     217
    218218        target->ucycles_diff = calloc(target->tasks_count,
    219219            sizeof(uint64_t));
    220220        if (target->ucycles_diff == NULL)
    221221                return "Not enough memory for user utilization";
    222        
     222
    223223        /* Allocate memory for computed values */
    224224        target->kcycles_diff = calloc(target->tasks_count,
     
    226226        if (target->kcycles_diff == NULL)
    227227                return "Not enough memory for kernel utilization";
    228        
     228
    229229        target->ecycles_diff = calloc(target->exceptions_count,
    230230            sizeof(uint64_t));
    231231        if (target->ecycles_diff == NULL)
    232232                return "Not enough memory for exception cycles utilization";
    233        
     233
    234234        target->ecount_diff = calloc(target->exceptions_count,
    235235            sizeof(uint64_t));
    236236        if (target->ecount_diff == NULL)
    237237                return "Not enough memory for exception count utilization";
    238        
     238
    239239        return NULL;
    240240}
     
    250250        /* For each CPU: Compute total cycles and divide it between
    251251           user and kernel */
    252        
     252
    253253        size_t i;
    254254        for (i = 0; i < new_data->cpus_count; i++) {
     
    258258                    new_data->cpus[i].busy_cycles - old_data->cpus[i].busy_cycles;
    259259                uint64_t sum = idle + busy;
    260                
     260
    261261                FRACTION_TO_FLOAT(new_data->cpus_perc[i].idle, idle * 100, sum);
    262262                FRACTION_TO_FLOAT(new_data->cpus_perc[i].busy, busy * 100, sum);
    263263        }
    264        
     264
    265265        /* For all tasks compute sum and differencies of all cycles */
    266        
     266
    267267        uint64_t virtmem_total = 0;
    268268        uint64_t resmem_total = 0;
    269269        uint64_t ucycles_total = 0;
    270270        uint64_t kcycles_total = 0;
    271        
     271
    272272        for (i = 0; i < new_data->tasks_count; i++) {
    273273                /* Match task with the previous instance */
    274                
     274
    275275                bool found = false;
    276276                size_t j;
     
    281281                        }
    282282                }
    283                
     283
    284284                if (!found) {
    285285                        /* This is newly borned task, ignore it */
     
    288288                        continue;
    289289                }
    290                
     290
    291291                new_data->ucycles_diff[i] =
    292292                    new_data->tasks[i].ucycles - old_data->tasks[j].ucycles;
    293293                new_data->kcycles_diff[i] =
    294294                    new_data->tasks[i].kcycles - old_data->tasks[j].kcycles;
    295                
     295
    296296                virtmem_total += new_data->tasks[i].virtmem;
    297297                resmem_total += new_data->tasks[i].resmem;
     
    299299                kcycles_total += new_data->kcycles_diff[i];
    300300        }
    301        
     301
    302302        /* For each task compute percential change */
    303        
     303
    304304        for (i = 0; i < new_data->tasks_count; i++) {
    305305                FRACTION_TO_FLOAT(new_data->tasks_perc[i].virtmem,
     
    312312                    new_data->kcycles_diff[i] * 100, kcycles_total);
    313313        }
    314        
     314
    315315        /* For all exceptions compute sum and differencies of cycles */
    316        
     316
    317317        uint64_t ecycles_total = 0;
    318318        uint64_t ecount_total = 0;
    319        
     319
    320320        for (i = 0; i < new_data->exceptions_count; i++) {
    321321                /*
     
    324324                 * usually disappear, but it does not hurt.
    325325                 */
    326                
     326
    327327                bool found = false;
    328328                size_t j;
     
    333333                        }
    334334                }
    335                
     335
    336336                if (!found) {
    337337                        /* This is a new exception, ignore it */
     
    340340                        continue;
    341341                }
    342                
     342
    343343                new_data->ecycles_diff[i] =
    344344                    new_data->exceptions[i].cycles - old_data->exceptions[j].cycles;
    345345                new_data->ecount_diff[i] =
    346346                    new_data->exceptions[i].count - old_data->exceptions[i].count;
    347                
     347
    348348                ecycles_total += new_data->ecycles_diff[i];
    349349                ecount_total += new_data->ecount_diff[i];
    350350        }
    351        
     351
    352352        /* For each exception compute percential change */
    353        
     353
    354354        for (i = 0; i < new_data->exceptions_count; i++) {
    355355                FRACTION_TO_FLOAT(new_data->exceptions_perc[i].cycles,
     
    364364        field_t *fa = (field_t *)a + sort_column;
    365365        field_t *fb = (field_t *)b + sort_column;
    366        
     366
    367367        if (fa->type > fb->type)
    368368                return 1 * sort_reverse;
     
    536536        if (target->load != NULL)
    537537                free(target->load);
    538        
     538
    539539        if (target->cpus != NULL)
    540540                free(target->cpus);
    541        
     541
    542542        if (target->cpus_perc != NULL)
    543543                free(target->cpus_perc);
    544        
     544
    545545        if (target->tasks != NULL)
    546546                free(target->tasks);
    547        
     547
    548548        if (target->tasks_perc != NULL)
    549549                free(target->tasks_perc);
    550        
     550
    551551        if (target->threads != NULL)
    552552                free(target->threads);
    553        
     553
    554554        if (target->exceptions != NULL)
    555555                free(target->exceptions);
    556        
     556
    557557        if (target->exceptions_perc != NULL)
    558558                free(target->exceptions_perc);
    559        
     559
    560560        if (target->physmem != NULL)
    561561                free(target->physmem);
    562        
     562
    563563        if (target->ucycles_diff != NULL)
    564564                free(target->ucycles_diff);
    565        
     565
    566566        if (target->kcycles_diff != NULL)
    567567                free(target->kcycles_diff);
    568        
     568
    569569        if (target->ecycles_diff != NULL)
    570570                free(target->ecycles_diff);
    571        
     571
    572572        if (target->ecount_diff != NULL)
    573573                free(target->ecount_diff);
     
    582582        data_t data_prev;
    583583        const char *ret = NULL;
    584        
     584
    585585        screen_init();
    586586        printf("Reading initial data...\n");
    587        
     587
    588588        if ((ret = read_data(&data)) != NULL)
    589589                goto out;
    590        
     590
    591591        /* Compute some rubbish to have initialised values */
    592592        compute_percentages(&data, &data);
    593        
     593
    594594        /* And paint screen until death */
    595595        while (true) {
     
    602602                                goto out;
    603603                        }
    604                        
     604
    605605                        compute_percentages(&data_prev, &data);
    606606                        free_data(&data_prev);
     
    672672                print_data(&data);
    673673        }
    674        
     674
    675675out:
    676676        screen_done();
    677677        free_data(&data);
    678        
     678
    679679        if (ret != NULL) {
    680680                fprintf(stderr, "%s: %s\n", NAME, ret);
    681681                return 1;
    682682        }
    683        
     683
    684684        return 0;
    685685}
Note: See TracChangeset for help on using the changeset viewer.