Changes in uspace/app/top/top.c [172aad6:b3b7e14a] in mainline


Ignore:
File:
1 edited

Legend:

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

    r172aad6 rb3b7e14a  
    4444#include <arch/barrier.h>
    4545#include <errno.h>
    46 #include <sort.h>
    4746#include "screen.h"
    4847#include "input.h"
     
    5857
    5958op_mode_t op_mode = OP_TASKS;
    60 sort_mode_t sort_mode = SORT_TASK_CYCLES;
    6159bool excs_all = false;
    6260
     
    6967        target->tasks = NULL;
    7068        target->tasks_perc = NULL;
    71         target->tasks_map = NULL;
    7269        target->threads = NULL;
    7370        target->exceptions = NULL;
    7471        target->exceptions_perc = NULL;
    7572        target->physmem = NULL;
    76         target->ucycles_diff = NULL;
    77         target->kcycles_diff = NULL;
    78         target->ecycles_diff = NULL;
    79         target->ecount_diff = NULL;
    8073       
    8174        /* Get current time */
     
    120113                return "Not enough memory for task utilization";
    121114       
    122         target->tasks_map =
    123             (size_t *) calloc(target->tasks_count, sizeof(size_t));
    124         if (target->tasks_map == NULL)
    125                 return "Not enough memory for task map";
    126        
    127115        /* Get threads */
    128116        target->threads = stats_get_threads(&(target->threads_count));
     
    144132        if (target->physmem == NULL)
    145133                return "Cannot get physical memory";
    146        
    147         target->ucycles_diff = calloc(target->tasks_count,
    148             sizeof(uint64_t));
    149         if (target->ucycles_diff == NULL)
    150                 return "Not enough memory for user utilization";
    151        
    152         /* Allocate memory for computed values */
    153         target->kcycles_diff = calloc(target->tasks_count,
    154             sizeof(uint64_t));
    155         if (target->kcycles_diff == NULL)
    156                 return "Not enough memory for kernel utilization";
    157        
    158         target->ecycles_diff = calloc(target->exceptions_count,
    159             sizeof(uint64_t));
    160         if (target->ecycles_diff == NULL)
    161                 return "Not enough memory for exception cycles utilization";
    162        
    163         target->ecount_diff = calloc(target->exceptions_count,
    164             sizeof(uint64_t));
    165         if (target->ecount_diff == NULL)
    166                 return "Not enough memory for exception count utilization";
    167134       
    168135        return NULL;
     
    175142 *
    176143 */
    177 static void compute_percentages(data_t *old_data, data_t *new_data)
     144static const char *compute_percentages(data_t *old_data, data_t *new_data)
    178145{
    179         /* For each CPU: Compute total cycles and divide it between
     146        /* Allocate memory */
     147       
     148        uint64_t *ucycles_diff = calloc(new_data->tasks_count,
     149            sizeof(uint64_t));
     150        if (ucycles_diff == NULL)
     151                return "Not enough memory for user utilization";
     152       
     153        uint64_t *kcycles_diff = calloc(new_data->tasks_count,
     154            sizeof(uint64_t));
     155        if (kcycles_diff == NULL) {
     156                free(ucycles_diff);
     157                return "Not enough memory for kernel utilization";
     158        }
     159       
     160        uint64_t *ecycles_diff = calloc(new_data->exceptions_count,
     161            sizeof(uint64_t));
     162        if (ecycles_diff == NULL) {
     163                free(ucycles_diff);
     164                free(kcycles_diff);
     165                return "Not enough memory for exception cycles utilization";
     166        }
     167       
     168        uint64_t *ecount_diff = calloc(new_data->exceptions_count,
     169            sizeof(uint64_t));
     170        if (ecount_diff == NULL) {
     171                free(ucycles_diff);
     172                free(kcycles_diff);
     173                free(ecycles_diff);
     174                return "Not enough memory for exception count utilization";
     175        }
     176       
     177        /* For each CPU: Compute total ticks and divide it between
    180178           user and kernel */
    181179       
     
    183181        for (i = 0; i < new_data->cpus_count; i++) {
    184182                uint64_t idle =
    185                     new_data->cpus[i].idle_cycles - old_data->cpus[i].idle_cycles;
     183                    new_data->cpus[i].idle_ticks - old_data->cpus[i].idle_ticks;
    186184                uint64_t busy =
    187                     new_data->cpus[i].busy_cycles - old_data->cpus[i].busy_cycles;
     185                    new_data->cpus[i].busy_ticks - old_data->cpus[i].busy_ticks;
    188186                uint64_t sum = idle + busy;
    189187               
     
    212210                if (!found) {
    213211                        /* This is newly borned task, ignore it */
    214                         new_data->ucycles_diff[i] = 0;
    215                         new_data->kcycles_diff[i] = 0;
     212                        ucycles_diff[i] = 0;
     213                        kcycles_diff[i] = 0;
    216214                        continue;
    217215                }
    218216               
    219                 new_data->ucycles_diff[i] =
     217                ucycles_diff[i] =
    220218                    new_data->tasks[i].ucycles - old_data->tasks[j].ucycles;
    221                 new_data->kcycles_diff[i] =
     219                kcycles_diff[i] =
    222220                    new_data->tasks[i].kcycles - old_data->tasks[j].kcycles;
    223221               
    224222                virtmem_total += new_data->tasks[i].virtmem;
    225                 ucycles_total += new_data->ucycles_diff[i];
    226                 kcycles_total += new_data->kcycles_diff[i];
     223                ucycles_total += ucycles_diff[i];
     224                kcycles_total += kcycles_diff[i];
    227225        }
    228226       
     
    233231                    new_data->tasks[i].virtmem * 100, virtmem_total);
    234232                FRACTION_TO_FLOAT(new_data->tasks_perc[i].ucycles,
    235                     new_data->ucycles_diff[i] * 100, ucycles_total);
     233                    ucycles_diff[i] * 100, ucycles_total);
    236234                FRACTION_TO_FLOAT(new_data->tasks_perc[i].kcycles,
    237                     new_data->kcycles_diff[i] * 100, kcycles_total);
     235                    kcycles_diff[i] * 100, kcycles_total);
    238236        }
    239237       
     
    261259                if (!found) {
    262260                        /* This is a new exception, ignore it */
    263                         new_data->ecycles_diff[i] = 0;
    264                         new_data->ecount_diff[i] = 0;
     261                        ecycles_diff[i] = 0;
     262                        ecount_diff[i] = 0;
    265263                        continue;
    266264                }
    267265               
    268                 new_data->ecycles_diff[i] =
     266                ecycles_diff[i] =
    269267                    new_data->exceptions[i].cycles - old_data->exceptions[j].cycles;
    270                 new_data->ecount_diff[i] =
     268                ecount_diff[i] =
    271269                    new_data->exceptions[i].count - old_data->exceptions[i].count;
    272270               
    273                 ecycles_total += new_data->ecycles_diff[i];
    274                 ecount_total += new_data->ecount_diff[i];
     271                ecycles_total += ecycles_diff[i];
     272                ecount_total += ecount_diff[i];
    275273        }
    276274       
     
    279277        for (i = 0; i < new_data->exceptions_count; i++) {
    280278                FRACTION_TO_FLOAT(new_data->exceptions_perc[i].cycles,
    281                     new_data->ecycles_diff[i] * 100, ecycles_total);
     279                    ecycles_diff[i] * 100, ecycles_total);
    282280                FRACTION_TO_FLOAT(new_data->exceptions_perc[i].count,
    283                     new_data->ecount_diff[i] * 100, ecount_total);
    284         }
    285 }
    286 
    287 static int cmp_data(void *a, void *b, void *arg)
    288 {
    289         size_t ia = *((size_t *) a);
    290         size_t ib = *((size_t *) b);
    291         data_t *data = (data_t *) arg;
    292        
    293         uint64_t acycles = data->ucycles_diff[ia] + data->kcycles_diff[ia];
    294         uint64_t bcycles = data->ucycles_diff[ib] + data->kcycles_diff[ib];
    295        
    296         if (acycles > bcycles)
    297                 return -1;
    298        
    299         if (acycles < bcycles)
    300                 return 1;
    301        
    302         return 0;
    303 }
    304 
    305 static void sort_data(data_t *data)
    306 {
    307         size_t i;
    308        
    309         for (i = 0; i < data->tasks_count; i++)
    310                 data->tasks_map[i] = i;
    311        
    312         qsort((void *) data->tasks_map, data->tasks_count,
    313             sizeof(size_t), cmp_data, (void *) data);
     281                    ecount_diff[i] * 100, ecount_total);
     282        }
     283       
     284        /* Cleanup */
     285       
     286        free(ucycles_diff);
     287        free(kcycles_diff);
     288        free(ecycles_diff);
     289        free(ecount_diff);
     290       
     291        return NULL;
    314292}
    315293
     
    342320        if (target->physmem != NULL)
    343321                free(target->physmem);
    344        
    345         if (target->ucycles_diff != NULL)
    346                 free(target->ucycles_diff);
    347        
    348         if (target->kcycles_diff != NULL)
    349                 free(target->kcycles_diff);
    350        
    351         if (target->ecycles_diff != NULL)
    352                 free(target->ecycles_diff);
    353        
    354         if (target->ecount_diff != NULL)
    355                 free(target->ecount_diff);
    356322}
    357323
     
    369335       
    370336        /* Compute some rubbish to have initialised values */
    371         compute_percentages(&data_prev, &data_prev);
     337        if ((ret = compute_percentages(&data_prev, &data_prev)) != NULL)
     338                goto out;
    372339       
    373340        /* And paint screen until death */
     
    380347                        }
    381348                       
    382                         compute_percentages(&data_prev, &data);
    383                         sort_data(&data);
     349                        if ((ret = compute_percentages(&data_prev, &data)) != NULL) {
     350                                free_data(&data);
     351                                goto out;
     352                        }
     353                       
    384354                        print_data(&data);
    385355                        free_data(&data_prev);
Note: See TracChangeset for help on using the changeset viewer.