Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 9d491a7 in mainline


Ignore:
Timestamp:
2010-04-01T09:15:38Z (12 years ago)
Author:
Stanislav Kozina <stanislav.kozina@…>
Branches:
lfn, master
Children:
83a957a
Parents:
c0379fc
Message:

ps and uptime improvements

Location:
uspace/app
Files:
2 edited

Legend:

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

    rc0379fc r9d491a7  
    4848#define TASK_COUNT 10
    4949#define THREAD_COUNT 50
     50
     51#define ECHOLOAD1(x) ((x) >> 11)
     52#define ECHOLOAD2(x) (((x) & 0x7ff) / 2)
    5053
    5154/** Thread states */
     
    124127{
    125128        size_t load[3];
    126         load[0] = 0;
    127         load[1] = 0;
    128         load[2] = 0;
    129129        get_load(load);
    130         printf("Current load: %d.%03d %d.%03d %d.%03d\n", load[0] >> 11, (load[0] & 0x7ff) / 2, load[1] >> 11, (load[1] & 0x7ff) / 2, load[2] >> 11, (load[2] & 0x7ff) / 2);
     130        printf("System load: %d.%03d %d.%03d %d.%03d\n", ECHOLOAD1(load[0]), ECHOLOAD2(load[0]), ECHOLOAD1(load[1]), ECHOLOAD2(load[1]), ECHOLOAD1(load[2]), ECHOLOAD2(load[2]));
    131131}
    132132
  • uspace/app/uptime/uptime.c

    rc0379fc r9d491a7  
    3737#include <stdio.h>
    3838#include <uptime.h>
     39#include <sys/time.h>
     40#include <load.h>
     41
     42#define DAY 86400
     43#define HOUR 3600
     44#define MINUTE 60
     45
     46#define ECHOLOAD1(x) ((x) >> 11)
     47#define ECHOLOAD2(x) (((x) & 0x7ff) / 2)
    3948
    4049int main(int argc, char *argv[])
    4150{
     51        struct timeval time;
     52        uint64_t sec;
     53        if (gettimeofday(&time, NULL) != 0) {
     54                printf("Cannot get time of day!\n");
     55                return 1;
     56        }
     57        sec = time.tv_sec;
     58        printf("%02llu:%02llu:%02llu", (sec % DAY) / HOUR,
     59                        (sec % HOUR) / MINUTE, sec % MINUTE);
     60
    4261        uint64_t uptime;
     62        get_uptime(&uptime);
     63        printf("\tUp %4llu days, %02llu:%02llu:%02llu",
     64                uptime / DAY, (uptime % DAY) / HOUR, (uptime % HOUR) / MINUTE, uptime % MINUTE);
    4365
    44         get_uptime(&uptime);
    45         printf("Up %llu days, %llu hours, %llu minutes, %llu seconds\n",
    46                 uptime / 86400, (uptime % 86400) / 3600, (uptime % 3600) / 60, uptime % 60);
     66        size_t load[3];
     67        get_load(load);
     68        printf("\t load: %d.%03d %d.%03d %d.%03d ", ECHOLOAD1(load[0]), ECHOLOAD2(load[0]), ECHOLOAD1(load[1]), ECHOLOAD2(load[1]), ECHOLOAD1(load[2]), ECHOLOAD2(load[2]));
     69
     70        printf("\n");
    4771        return 0;
    4872}
Note: See TracChangeset for help on using the changeset viewer.