Changeset 9dae191e in mainline for uspace/app/uptime/uptime.c


Ignore:
Timestamp:
2010-04-18T00:24:40Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a80687e5
Parents:
d8e3467
Message:

sysinfo API cleanup

  • better support for generated subtrees
  • synchronization
  • memory management (generated items cleanup)
  • simplier sysinfo_dump()

remove separate statistical syscalls, replace with virtual sysinfo items (some functionality is still missing)

  • naming consolidation
  • cleaner API
  • proper synchronization

minor renames

  • zone_print_list() → zones_print_list()
  • zone_busy_and_free() → zones_stats()
File:
1 edited

Legend:

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

    rd8e3467 r9dae191e  
    2828
    2929/** @addtogroup uptime
    30  * @brief Echo system uptime.
     30 * @brief Print system uptime.
    3131 * @{
    3232 */
     
    3636
    3737#include <stdio.h>
    38 #include <uptime.h>
     38#include <stats.h>
    3939#include <sys/time.h>
    40 #include <load.h>
     40#include <inttypes.h>
    4141
    42 #define DAY 86400
    43 #define HOUR 3600
    44 #define MINUTE 60
     42#define NAME  "uptime"
     43
     44#define DAY     86400
     45#define HOUR    3600
     46#define MINUTE  60
    4547
    4648int main(int argc, char *argv[])
    4749{
    4850        struct timeval time;
    49         uint64_t sec;
    5051        if (gettimeofday(&time, NULL) != 0) {
    51                 printf("Cannot get time of day!\n");
    52                 return 1;
     52                fprintf(stderr, "%s: Cannot get time of day\n", NAME);
     53                return -1;
    5354        }
    54         sec = time.tv_sec;
    55         printf("%02llu:%02llu:%02llu", (sec % DAY) / HOUR,
    56                         (sec % HOUR) / MINUTE, sec % MINUTE);
    57 
    58         uint64_t uptime;
    59         get_uptime(&uptime);
    60         printf(", up %4llu days, %02llu:%02llu:%02llu",
    61                 uptime / DAY, (uptime % DAY) / HOUR, (uptime % HOUR) / MINUTE, uptime % MINUTE);
    62 
    63         unsigned long load[3];
    64         get_load(load);
    65         puts(", load avarage: ");
    66         print_load_fragment(load[0], 2);
    67         puts(" ");
    68         print_load_fragment(load[1], 2);
    69         puts(" ");
    70         print_load_fragment(load[2], 2);
    71 
    72         puts("\n");
     55       
     56        uint64_t sec = time.tv_sec;
     57        printf("%02" PRIu64 ":%02" PRIu64 ":%02" PRIu64, (sec % DAY) / HOUR,
     58            (sec % HOUR) / MINUTE, sec % MINUTE);
     59       
     60        sysarg_t uptime = get_stats_uptime();
     61        printf(", up %u days, %02u:%02u:%02u", uptime / DAY,
     62            (uptime % DAY) / HOUR, (uptime % HOUR) / MINUTE, uptime % MINUTE);
     63       
     64        size_t count;
     65        load_t *load = get_stats_load(&count);
     66        if (load != NULL) {
     67                printf(", load avarage: ");
     68               
     69                size_t i;
     70                for (i = 0; i < count; i++) {
     71                        if (i > 0)
     72                                printf(" ");
     73                       
     74                        print_load_fragment(load[i], 2);
     75                }
     76        }
     77       
     78        printf("\n");
    7379        return 0;
    7480}
Note: See TracChangeset for help on using the changeset viewer.