aboutsummaryrefslogtreecommitdiffstats
path: root/src/firemon/top.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/firemon/top.c')
-rw-r--r--src/firemon/top.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/firemon/top.c b/src/firemon/top.c
index 0633370ac..56f171f5b 100644
--- a/src/firemon/top.c
+++ b/src/firemon/top.c
@@ -154,8 +154,8 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne
154 154
155 // cpu 155 // cpu
156 itv *= clocktick; 156 itv *= clocktick;
157 float ud = (float) (*utime - pids[index].utime) / itv * 100; 157 float ud = (float) (*utime - pids[index].option.top.utime) / itv * 100;
158 float sd = (float) (*stime - pids[index].stime) / itv * 100; 158 float sd = (float) (*stime - pids[index].option.top.stime) / itv * 100;
159 float cd = ud + sd; 159 float cd = ud + sd;
160 *cpu = cd; 160 *cpu = cd;
161 char cpu_str[10]; 161 char cpu_str[10];
@@ -179,6 +179,34 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne
179 return rv; 179 return rv;
180} 180}
181 181
182// recursivity!!!
183void pid_store_cpu(unsigned index, unsigned parent, unsigned *utime, unsigned *stime) {
184 if (pids[index].level == 1) {
185 *utime = 0;
186 *stime = 0;
187 }
188
189 // Remove unused parameter warning
190 (void)parent;
191
192 unsigned utmp = 0;
193 unsigned stmp = 0;
194 pid_get_cpu_time(index, &utmp, &stmp);
195 *utime += utmp;
196 *stime += stmp;
197
198 unsigned i;
199 for (i = index + 1; i < (unsigned)max_pids; i++) {
200 if (pids[i].parent == (pid_t)index)
201 pid_store_cpu(i, index, utime, stime);
202 }
203
204 if (pids[index].level == 1) {
205 pids[index].option.top.utime = *utime;
206 pids[index].option.top.stime = *stime;
207 }
208}
209
182 210
183typedef struct node_t { 211typedef struct node_t {
184 struct node_t *next; 212 struct node_t *next;
@@ -267,7 +295,7 @@ void top(void) {
267 295
268 // set pid table 296 // set pid table
269 int i; 297 int i;
270 int itv = 1; // 1 second interval 298 int itv = 3; // 3 second interval
271 pid_read(0); 299 pid_read(0);
272 300
273 // start cpu measurements 301 // start cpu measurements