Archiv verlassen und diese Seite im Standarddesign anzeigen : CPU-Nutzung/-Auslastung
markuskolp
21.04.2004, 14:35
Hi,
ich möchte mit Perl die Ressourcen von meinem System anschauen.
Hab bereits geschafft folgende Informationen zu ergattern:
Informationen zu Prozessen (wie ID, Namen,..)
Auslastung von Speicher (Realer, Virtueller)
Auslastung von Festplatten (freier Speicher,...)
Jedoch fehlt mir noch die CPU-Nutzung !!
Wie kann ich diese anschauen?
Wenn vorhanden, mit welchem Modul ist dies möglich?
Jan Krüger
21.04.2004, 16:34
Vielleicht hilft dir folgender C-Code aus Bubblefishymon weiter:
/* returns current CPU load in percent, 0 to 100 */
int system_cpu(void)
{
unsigned int cpuload;
u_int64_t load, total, oload, ototal;
u_int64_t ab, ac, ad, ae;
int i;
FILE *stat;
stat = fopen("/proc/stat", "r");
fscanf(stat, "%*s %Ld %Ld %Ld %Ld", &ab, &ac, &ad, &ae);
fclose(stat);
/* Find out the CPU load */
/* user + sys = load
* total = total */
load = ab + ac + ad; /* cpu.user + cpu.sys; */
total = ab + ac + ad + ae; /* cpu.total; */
/* "i" is an index into a load history */
i = bm.loadIndex;
oload = bm.load[ i ];
ototal = bm.total[ i ];
bm.load[ i ] = load;
bm.total[ i ] = total;
bm.loadIndex = (i + 1) % bm.samples;
/*
Because the load returned from libgtop is a value accumulated
over time, and not the current load, the current load percentage
is calculated as the extra amount of work that has been performed
since the last sample. yah, right, what the fuck does that mean?
*/
if (ototal == 0) /* ototal == 0 means that this is the first time
we get here */
cpuload = 0;
else if ((total - ototal) <= 0)
cpuload = 100;
else
cpuload = (100 * (load - oload)) / (total - ototal);
return cpuload;
}
markuskolp
22.04.2004, 15:40
danke, für linux wahrscheinlich geeignet aber wie kann ichs auch unter windows machen?
Jan Krüger
22.04.2004, 15:56
Mit irgendwelchen Win32-API-Calls, musst du in der Doku nachsehen. Vielleicht auch mal die Symbole ansehen, die der Systemmonitor importiert.
Panarello
18.05.2004, 00:54
hi i'm looking this source but here is it the struct of bm ??? i need this source for my work in my college.
Thanks!
Jan Krüger
18.05.2004, 02:33
Hi,
the code is an excerpt from Bubblefishymon, which you should find by entering that term into Google.
Panarello
18.05.2004, 15:36
well i find the complete source here : http://www.ne.jp/asahi/linux/timecop/software/bubblemon-dockapp-1.46.tar.gz
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.