source: mainline/uspace/app/top/top.c@ 79edc36

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 79edc36 was 79edc36, checked in by Stanislav Kozina <stanislav.kozina@…>, 16 years ago

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

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Copyright (c) 2010 Stanislav Kozina
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup top
30 * @brief Top utility.
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <unistd.h>
40#include <io/console.h>
41#include <uptime.h>
42#include <task.h>
43#include <thread.h>
44#include <sys/time.h>
45#include <load.h>
46#include "screen.h"
47#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}
79
80int main(int argc, char *argv[])
81{
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
91 screen_init();
92
93 /* And paint screen until death... */
94 while (true) {
95 char c = tgetchar(UPDATE_INTERVAL);
96 if (c < 0) {
97 read_vars(&new_data);
98 print_data(&new_data);
99 continue;
100 }
101 switch (c) {
102 case 'q':
103 return 0;
104 default:
105 moveto(10,10);
106 printf("Unknown command: %c", c);
107 fflush(stdout);
108 break;
109 }
110
111 }
112
113 puts("\n\n");
114 fflush(stdout);
115 return 0;
116}
117
118/** @}
119 */
Note: See TracBrowser for help on using the repository browser.