Changeset 8b2aba5 in mainline for uspace/app/top/top.c


Ignore:
Timestamp:
2010-04-02T20:22:14Z (14 years ago)
Author:
Stanislav Kozina <stanislav.kozina@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade
Children:
ee35ba0b
Parents:
8f56d93
Message:

top echoes also basic cpu info

File:
1 edited

Legend:

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

    r8f56d93 r8b2aba5  
    3838#include <stdlib.h>
    3939#include <unistd.h>
    40 #include <io/console.h>
    4140#include <uptime.h>
    4241#include <task.h>
     
    5554#define MINUTE 60
    5655
    57 static void read_vars(data_t *target)
     56static void read_data(data_t *target)
    5857{
    5958        /* Read current time */
     
    8079        /* Read task ids */
    8180        target->task_count = get_tasks(&target->tasks);
     81
     82        /* Read cpu infos */
     83        target->cpu_count = get_cpu_infos(&target->cpus);
    8284}
     85
     86static void free_data(data_t *target)
     87{
     88        free(target->tasks);
     89}
     90
     91static inline void swap(data_t *first, data_t *second)
     92{
     93        data_t *temp;
     94        temp = first;
     95        first = second;
     96        second = temp;
     97}
     98
     99static data_t data[2];
    83100
    84101int main(int argc, char *argv[])
    85102{
    86         data_t old_data;
    87         data_t new_data;
     103        data_t *data1 = &data[0];
     104        data_t *data2 = &data[1];
    88105
    89106        /* Read initial stats */
    90107        printf("Reading initial data...\n");
    91         read_vars(&old_data);
     108        read_data(data1);
    92109        sleep(UPDATE_INTERVAL);
    93         read_vars(&new_data);
    94         print_data(&new_data);
    95         fflush(stdout);
     110        read_data(data2);
    96111
    97112        screen_init();
     113        print_data(data2);
    98114
    99115        /* And paint screen until death... */
     
    101117                char c = tgetchar(UPDATE_INTERVAL);
    102118                if (c < 0) {
    103                         read_vars(&new_data);
    104                         print_data(&new_data);
     119                        free_data(data1);
     120                        swap(data1, data2);
     121                        read_data(data2);
     122                        print_data(data2);
    105123                        continue;
    106124                }
    107125                switch (c) {
    108126                        case 'q':
     127                                clear_screen();
    109128                                return 0;
    110129                        default:
    111                                 moveto(10,10);
    112                                 printf("Unknown command: %c", c);
    113                                 fflush(stdout);
     130                                PRINT_WARNING("Unknown command: %c", c);
    114131                                break;
    115132                }
     
    117134        }
    118135
    119         free(new_data.tasks);
    120         puts("\n\n");
    121         fflush(stdout);
     136        free_data(data1);
     137        free_data(data2);
    122138        return 0;
    123139}
Note: See TracChangeset for help on using the changeset viewer.