Changeset ee35ba0b in mainline


Ignore:
Timestamp:
2010-04-03T15:26:34Z (14 years ago)
Author:
Stanislav Kozina <stanislav.kozina@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
452268a
Parents:
8b2aba5
Message:

top echoes also percentage usage of cpu

Location:
uspace/app/top
Files:
4 edited

Legend:

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

    r8b2aba5 ree35ba0b  
    7070        }
    7171
     72/*
    7273        int i;
    7374        for (i = 0; i < result; ++i) {
     
    7576                get_task_info(tasks[i], &taskinfo);
    7677        }
     78        */
    7779
    7880        *out_tasks = tasks;
  • uspace/app/top/screen.c

    r8b2aba5 ree35ba0b  
    5050#define WHITE 0xf0f0f0
    5151#define BLACK 0x000000
     52
     53static void print_float(float f, int precision)
     54{
     55        printf("%u.", (unsigned int) f);
     56        int i;
     57        float rest = (f - (int)f) * 10;
     58        for (i = 0; i < precision; ++i) {
     59                printf("%d", (unsigned int)rest);
     60                rest = (rest - (int)rest) * 10;
     61        }
     62}
    5263
    5364static void resume_normal(void)
     
    112123        uspace_cpu_info_t *cpus = data->cpus;
    113124        for (i = 0; i < data->cpu_count; ++i) {
    114                 printf("Cpu%u (%4u Mhz): Busy ticks: %6llu, Idle Ticks: %6llu\n",
     125                printf("Cpu%u (%4u Mhz): Busy ticks: %6llu, Idle Ticks: %6llu",
    115126                        i, (unsigned int)cpus[i].frequency_mhz, cpus[i].busy_ticks,
    116127                        cpus[i].idle_ticks);
     128                printf(", idle: ");
     129                print_float(data->cpu_perc[i].idle, 2);
     130                puts("%, busy: ");
     131                print_float(data->cpu_perc[i].busy, 2);
     132                puts("%\n");
    117133                ++up_rows;
    118134        }
     
    163179        print_head();
    164180        puts("\n");
    165         print_tasks(data, 4);
     181        print_tasks(data, up_rows);
    166182        fflush(stdout);
    167183}
  • uspace/app/top/top.c

    r8b2aba5 ree35ba0b  
    5454#define MINUTE 60
    5555
     56int number = 0;
     57int number2 = 0;
    5658static void read_data(data_t *target)
    5759{
     
    8486}
    8587
     88/** Computes percentage differencies from old_data to new_data
     89 *
     90 * @param old_data      Pointer to old data strucutre.
     91 * @param new_data      Pointer to actual data where percetages are stored.
     92 *
     93 */
     94static void compute_percentages(data_t *old_data, data_t *new_data)
     95{
     96        /* Foreach cpu, compute total ticks and divide it between user and
     97         * system */
     98        unsigned int i;
     99        new_data->cpu_perc = malloc(new_data->cpu_count * sizeof(cpu_perc_t));
     100        for (i = 0; i < new_data->cpu_count; ++i) {
     101                uint64_t idle = new_data->cpus[i].idle_ticks - old_data->cpus[i].idle_ticks;
     102                uint64_t busy = new_data->cpus[i].busy_ticks - old_data->cpus[i].busy_ticks;
     103                uint64_t sum = idle + busy;
     104                new_data->cpu_perc[i].idle = ((float)(idle * 100) / sum);
     105                new_data->cpu_perc[i].busy = ((float)(busy * 100) / sum);
     106        }
     107}
     108
    86109static void free_data(data_t *target)
    87110{
    88111        free(target->tasks);
     112        free(target->cpus);
     113        free(target->cpu_perc);
    89114}
    90115
    91 static inline void swap(data_t *first, data_t *second)
     116static inline void swap(data_t **first, data_t **second)
    92117{
    93118        data_t *temp;
    94         temp = first;
    95         first = second;
    96         second = temp;
     119        temp = *first;
     120        *first = *second;
     121        *second = temp;
    97122}
    98123
     
    103128        data_t *data1 = &data[0];
    104129        data_t *data2 = &data[1];
     130        screen_init();
    105131
    106132        /* Read initial stats */
    107133        printf("Reading initial data...\n");
    108134        read_data(data1);
    109         sleep(UPDATE_INTERVAL);
    110         read_data(data2);
    111 
    112         screen_init();
    113         print_data(data2);
     135        /* Compute some rubbish to have initialised values */
     136        compute_percentages(data1, data1);
    114137
    115138        /* And paint screen until death... */
     
    117140                char c = tgetchar(UPDATE_INTERVAL);
    118141                if (c < 0) {
     142                        read_data(data2);
     143                        compute_percentages(data1, data2);
    119144                        free_data(data1);
    120                         swap(data1, data2);
    121                         read_data(data2);
    122145                        print_data(data2);
     146                        swap(&data1, &data2);
    123147                        continue;
    124148                }
  • uspace/app/top/top.h

    r8b2aba5 ree35ba0b  
    3838
    3939typedef struct {
     40        float idle;
     41        float busy;
     42} cpu_perc_t;
     43
     44typedef struct {
     45        float user;
     46        float system;
     47        float memory;
     48} task_perc_t;
     49
     50typedef struct {
    4051        unsigned int hours;
    4152        unsigned int minutes;
     
    4960        unsigned long load[3];
    5061
     62        unsigned int task_count;
    5163        task_id_t *tasks;
    52         unsigned int task_count;
    5364
     65        unsigned int cpu_count;
    5466        uspace_cpu_info_t *cpus;
    55         unsigned int cpu_count;
     67        cpu_perc_t *cpu_perc;
    5668} data_t;
    5769
Note: See TracChangeset for help on using the changeset viewer.