|
Packit Service |
407539 |
/* Copyright (C) 1998-99 Martin Baulig
|
|
Packit Service |
407539 |
This file is part of LibGTop 1.0.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
Contributed by Martin Baulig <martin@home-of-linux.org>, September 1998.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
LibGTop is free software; you can redistribute it and/or modify it
|
|
Packit Service |
407539 |
under the terms of the GNU General Public License as published by
|
|
Packit Service |
407539 |
the Free Software Foundation; either version 2 of the License,
|
|
Packit Service |
407539 |
or (at your option) any later version.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit Service |
407539 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
Packit Service |
407539 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
Packit Service |
407539 |
for more details.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
407539 |
along with LibGTop; see the file COPYING. If not, write to the
|
|
Packit Service |
407539 |
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
Packit Service |
407539 |
Boston, MA 02110-1301, USA.
|
|
Packit Service |
407539 |
*/
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <config.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <locale.h>
|
|
Packit Service |
407539 |
#include <libintl.h>
|
|
Packit Service |
407539 |
#include <math.h>
|
|
Packit Service |
407539 |
#include <stdio.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <glibtop.h>
|
|
Packit Service |
407539 |
#include <glibtop/cpu.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
int
|
|
Packit Service |
407539 |
main (int argc, char *argv [])
|
|
Packit Service |
407539 |
{
|
|
Packit Service |
407539 |
glibtop_cpu cpu;
|
|
Packit Service |
407539 |
unsigned long frequency;
|
|
Packit Service |
407539 |
double total, user, nice, sys, idle;
|
|
Packit Service |
407539 |
double b_total, b_user, b_nice, b_sys, b_idle;
|
|
Packit Service |
407539 |
double s_total, s_user, s_nice, s_sys, s_idle;
|
|
Packit Service |
407539 |
char separator [BUFSIZ], buffer [BUFSIZ];
|
|
Packit Service |
407539 |
int ncpu, i;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
glibtop_init();
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
glibtop_get_cpu (&cpu);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
ncpu = glibtop_global_server->ncpu ? glibtop_global_server->ncpu : 1;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
frequency = (unsigned long) cpu.frequency;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
total = ((unsigned long) cpu.total) ? ((double) cpu.total) : 1.0;
|
|
Packit Service |
407539 |
user = ((unsigned long) cpu.user) ? ((double) cpu.user) : 1.0;
|
|
Packit Service |
407539 |
nice = ((unsigned long) cpu.nice) ? ((double) cpu.nice) : 1.0;
|
|
Packit Service |
407539 |
sys = ((unsigned long) cpu.sys) ? ((double) cpu.sys) : 1.0;
|
|
Packit Service |
407539 |
idle = ((unsigned long) cpu.idle) ? ((double) cpu.idle) : 1.0;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
s_total = s_user = s_nice = s_sys = s_idle = 0.0;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
b_total = total / ncpu;
|
|
Packit Service |
407539 |
b_user = user / ncpu;
|
|
Packit Service |
407539 |
b_nice = nice / ncpu;
|
|
Packit Service |
407539 |
b_sys = sys / ncpu;
|
|
Packit Service |
407539 |
b_idle = idle / ncpu;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
memset (separator, '-', 91);
|
|
Packit Service |
407539 |
separator [92] = '\0';
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
sprintf (buffer, "Ticks (%ld per second):", frequency);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
printf ("\n\n%-26s %12s %12s %12s %12s %12s\n%s\n", buffer,
|
|
Packit Service |
407539 |
"Total", "User", "Nice", "Sys", "Idle", separator);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
printf ("CPU (0x%08lx): %12.0f %12.0f %12.0f %12.0f %12.0f\n\n",
|
|
Packit Service |
407539 |
(unsigned long) cpu.flags, total, user, nice, sys, idle);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
for (i = 0; i < glibtop_global_server->ncpu; i++) {
|
|
Packit Service |
407539 |
printf ("CPU %3d (0x%08lx): %12lu %12lu %12lu %12lu %12lu\n", i,
|
|
Packit Service |
407539 |
(unsigned long) cpu.flags,
|
|
Packit Service |
407539 |
(unsigned long) cpu.xcpu_total [i],
|
|
Packit Service |
407539 |
(unsigned long) cpu.xcpu_user [i],
|
|
Packit Service |
407539 |
(unsigned long) cpu.xcpu_nice [i],
|
|
Packit Service |
407539 |
(unsigned long) cpu.xcpu_sys [i],
|
|
Packit Service |
407539 |
(unsigned long) cpu.xcpu_idle [i]);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
s_total += fabs (((double) cpu.xcpu_total [i]) - b_total);
|
|
Packit Service |
407539 |
s_user += fabs (((double) cpu.xcpu_user [i]) - b_user);
|
|
Packit Service |
407539 |
s_nice += fabs (((double) cpu.xcpu_nice [i]) - b_nice);
|
|
Packit Service |
407539 |
s_sys += fabs (((double) cpu.xcpu_sys [i]) - b_sys);
|
|
Packit Service |
407539 |
s_idle += fabs (((double) cpu.xcpu_idle [i]) - b_idle);
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
printf ("%s\n\n\n", separator);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
printf ("%-26s %12s %12s %12s %12s %12s\n%s\n", "Percent:",
|
|
Packit Service |
407539 |
"Total (%)", "User (%)", "Nice (%)", "Sys (%)",
|
|
Packit Service |
407539 |
"Idle (%)", separator);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
printf ("CPU (0x%08lx): %12.3f %12.3f %12.3f %12.3f %12.3f\n\n",
|
|
Packit Service |
407539 |
(unsigned long) cpu.flags, (double) total * 100.0 / total,
|
|
Packit Service |
407539 |
(double) user * 100.0 / total,
|
|
Packit Service |
407539 |
(double) nice * 100.0 / total,
|
|
Packit Service |
407539 |
(double) sys * 100.0 / total,
|
|
Packit Service |
407539 |
(double) idle * 100.0 / total);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
for (i = 0; i < glibtop_global_server->ncpu; i++) {
|
|
Packit Service |
407539 |
double p_total, p_user, p_nice, p_sys, p_idle;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
p_total = ((double) cpu.xcpu_total [i]) * 100.0 / total;
|
|
Packit Service |
407539 |
p_user = ((double) cpu.xcpu_user [i]) * 100.0 / user;
|
|
Packit Service |
407539 |
p_nice = ((double) cpu.xcpu_nice [i]) * 100.0 / nice;
|
|
Packit Service |
407539 |
p_sys = ((double) cpu.xcpu_sys [i]) * 100.0 / sys;
|
|
Packit Service |
407539 |
p_idle = ((double) cpu.xcpu_idle [i]) * 100.0 / idle;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
printf ("CPU %3d (0x%08lx): %12.3f %12.3f %12.3f %12.3f %12.3f\n",
|
|
Packit Service |
407539 |
i, (unsigned long) cpu.flags, p_total, p_user, p_nice,
|
|
Packit Service |
407539 |
p_sys, p_idle);
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
printf ("%s\n%-26s %12.3f %12.3f %12.3f %12.3f %12.3f\n\n", separator,
|
|
Packit Service |
407539 |
"Spin:", s_total * 100.0 / total, s_user * 100.0 / user,
|
|
Packit Service |
407539 |
s_nice * 100.0 / nice, s_sys * 100.0 / sys, s_idle * 100.0 / idle);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
exit (0);
|
|
Packit Service |
407539 |
}
|