Changeset 79edc36 in mainline for uspace/app/top/top.c


Ignore:
Timestamp:
2010-04-01T15:21:03Z (14 years ago)
Author:
Stanislav Kozina <stanislav.kozina@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
62550dce
Parents:
83a957a
Message:

System load echo fix, now it looks realistic
top echoes first values (uptime)
Several ps and uptime fixes

File:
1 edited

Legend:

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

    r83a957a r79edc36  
    3737#include <stdio.h>
    3838#include <stdlib.h>
    39 #include <async.h>
    4039#include <unistd.h>
    4140#include <io/console.h>
    42 #include <vfs/vfs.h>
     41#include <uptime.h>
     42#include <task.h>
     43#include <thread.h>
     44#include <sys/time.h>
     45#include <load.h>
    4346#include "screen.h"
    4447#include "input.h"
     48#include "top.h"
     49
     50#define UPDATE_INTERVAL 1
     51
     52#define DAY 86400
     53#define HOUR 3600
     54#define MINUTE 60
     55
     56static void read_vars(data_t *target)
     57{
     58        /* Read current time */
     59        struct timeval time;
     60        if (gettimeofday(&time, NULL) != 0) {
     61                printf("Cannot get time of day!\n");
     62                exit(1);
     63        }
     64        target->hours = (time.tv_sec % DAY) / HOUR;
     65        target->minutes = (time.tv_sec % HOUR) / MINUTE;
     66        target->seconds = time.tv_sec % MINUTE;
     67
     68        /* Read uptime */
     69        uint64_t uptime;
     70        get_uptime(&uptime);
     71        target->uptime_d = uptime / DAY;
     72        target->uptime_h = (uptime % DAY) / HOUR;
     73        target->uptime_m = (uptime % HOUR) / MINUTE;
     74        target->uptime_s = uptime % MINUTE;
     75
     76        /* Read load */
     77        get_load(target->load);
     78}
    4579
    4680int main(int argc, char *argv[])
    4781{
     82        data_t old_data;
     83        data_t new_data;
     84
     85        /* Read initial stats */
     86        printf("Reading initial data...\n");
     87        read_vars(&old_data);
     88        sleep(UPDATE_INTERVAL);
     89        read_vars(&new_data);
     90
    4891        screen_init();
    4992
    5093        /* And paint screen until death... */
    51         int i = 0;
    5294        while (true) {
    53                 char c = tgetchar();
     95                char c = tgetchar(UPDATE_INTERVAL);
    5496                if (c < 0) {
    55                         clear_screen();
    56                         moveto(0,0);
    57                         printf("Still running;-) for  %d...", i++);
    58                         fflush(stdout);
     97                        read_vars(&new_data);
     98                        print_data(&new_data);
    5999                        continue;
    60100                }
     
    68108                                break;
    69109                }
     110
    70111        }
    71112
     113        puts("\n\n");
    72114        fflush(stdout);
    73115        return 0;
Note: See TracChangeset for help on using the changeset viewer.