[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: Some bugs...
From: Bernhard Rosenkraenzer <bero () redhat ! de>
Date: 2001-08-10 12:27:33
[Download RAW message or body]
On Fri, 10 Aug 2001, Dirk Mueller wrote:
> > Any objections to doing this correctly (yes, I volunteer to do it)? [I'll
> > fix it if nobody complains today]
>
> No, but please post a patch first.
Here you go.
LLaP
bero
["kpm-fix.patch" (TEXT/PLAIN)]
Only in kpm-old: Makefile
Only in kpm-old: Makefile.in
Only in kpm-old/icons: Makefile
Only in kpm-old/icons: Makefile.in
diff -ur kpm-old/infobar.C kpm/infobar.C
--- kpm-old/infobar.C Thu Nov 16 11:21:00 2000
+++ kpm/infobar.C Fri Aug 10 14:13:30 2001
@@ -166,7 +166,7 @@
swap_lbl->setText(s);
}
- int u = Procinfo::uptime;
+ unsigned long u = Procinfo::uptime;
int up_days = u / (3600 * 24);
u %= (3600 * 24);
int up_hrs = u / 3600;
diff -ur kpm-old/proc.C kpm/proc.C
--- kpm-old/proc.C Fri Aug 10 12:29:00 2001
+++ kpm/proc.C Fri Aug 10 14:20:12 2001
@@ -13,6 +13,7 @@
#include <sys/param.h>
#include <klocale.h>
+#include <qfile.h>
#include "qps.h"
#include "proc.h"
@@ -164,7 +165,7 @@
unsigned Procinfo::cpu_time[];
unsigned Procinfo::old_cpu_time[];
unsigned Procinfo::boot_time = 0;
-int Procinfo::uptime = 0;
+unsigned long Procinfo::uptime = 0;
QIntDict<Sockinfo> Procinfo::socks(101);
bool Procinfo::socks_current = FALSE;
@@ -190,37 +191,14 @@
char buf[4096];
// read memory info
- strcpy(path, procdir);
- strcat(path, "/meminfo");
- if(read_file(path, buf, sizeof(buf)) <= 0) return;
-
- // Skip the old /meminfo cruft, making this work in post-2.0.42 kernels
- // as well. (values are now in kB)
- char *p = strstr(buf, "MemTotal:");
- int match;
-
- // 2.4 kernels have 6 more fields:
- match = sscanf(p, "MemTotal: %d kB\nMemFree: %d kB\nMemShared: %d kB\n"
- "Buffers: %d kB\nCached: %d kB\nSwapCached: %*d kB\n"
- "Active: %*d kB\nInact_dirty: %*d kB\n"
- "Inact_clean: %*d kB\nInact_target: %*d kB\n"
- "HighTotal: %*d kB\nHighFree: %*d kB\n"
- "LowTotal: %*d kB\nLowFree: %*d kB\n"
- "SwapTotal: %d kB\nSwapFree: %d kB",
- &mem_total, &mem_free, &mem_shared, &mem_buffers,
- &mem_cached, &swap_total, &swap_free);
-
- // newer Linux have 2 more fields
- if (match != 7)
- match = sscanf(p, "MemTotal: %d kB\nMemFree: %d kB\nMemShared: %d kB\nBuffers: %d"
- " kB\nCached: %d kB\nBigTotal: %*d kB\nBigFree: %*d kB\nSwapTotal: %d kB\n SwapFree: %d",
- &mem_total, &mem_free, &mem_shared, &mem_buffers,
- &mem_cached, &swap_total, &swap_free);
- if(match != 7)
- match = sscanf(p, "MemTotal: %d kB\nMemFree: %d kB\nMemShared: %d kB\nBuffers: %d"
- " kB\nCached: %d kB\nSwapTotal: %d kB\n SwapFree: %d",
- &mem_total, &mem_free, &mem_shared, &mem_buffers,
- &mem_cached, &swap_total, &swap_free);
+ Meminfo m;
+ mem_total = m.value("MemTotal");
+ mem_free = m.value("MemFree");
+ mem_shared = m.value("MemShared");
+ mem_buffers = m.value("Buffers");
+ mem_cached = m.value("Cached");
+ swap_total = m.value("SwapTotal");
+ swap_free = m.value("SwapFree");
// read system status
strcpy(path, procdir);
@@ -231,7 +209,7 @@
sscanf(buf, "cpu %u %u %u %u",
&cpu_time[CPU_USER], &cpu_time[CPU_NICE],
&cpu_time[CPU_SYSTEM], &cpu_time[CPU_IDLE]);
- p = strstr(buf, "btime");
+ char *p = strstr(buf, "btime");
if(!p) {
fprintf(stderr, "Warning: btime not found, unknown btime!\n");
boot_time = time(NULL);
@@ -244,7 +222,7 @@
if(read_file(path, buf, sizeof(buf)) < 0) return;
float up_s;
sscanf(buf, "%f", &up_s);
- uptime = (int)up_s;
+ uptime = (unsigned long)up_s;
}
int Procinfo::get_policy()
@@ -939,3 +917,24 @@
return (r == 0) ? ((*a)->pid > (*b)->pid ? 1 : -1) : -r;
}
+Meminfo::Meminfo(QString const &filename)
+{
+ QString s;
+ QFile f(filename);
+ f.open(IO_ReadOnly);
+ while(f.readLine(s, 256)>=0) {
+ QString key=s.left(s.find(':'));
+ QString value=s.mid(s.find(':')+1).simplifyWhiteSpace();
+ if(value.contains(' '))
+ value=value.left(value.find(' '));
+ values.insert(key, value.toULong());
+ }
+ f.close();
+}
+unsigned long Meminfo::value(QString const &key) const
+{
+ if(values.contains(key))
+ return values[key];
+ return 0;
+}
+// vim:ts=4:sw=4:tw=78
diff -ur kpm-old/proc.h kpm/proc.h
--- kpm-old/proc.h Thu Nov 16 11:21:00 2000
+++ kpm/proc.h Fri Aug 10 14:15:46 2001
@@ -11,6 +11,7 @@
#include <qstring.h>
#include <qwindowdefs.h>
#include <qintdict.h>
+#include <qmap.h>
#include <ksharedptr.h>
@@ -162,7 +163,7 @@
static unsigned boot_time;
// from /proc/uptime
- static int uptime; // seconds of uptime
+ static unsigned long uptime; // seconds of uptime
// from /proc/net/{tcp,udp}
static QIntDict<Sockinfo> socks;
@@ -399,4 +400,12 @@
Proc *proc;
};
+class Meminfo {
+public:
+ Meminfo(QString const &filename="/proc/meminfo");
+ unsigned long value(QString const &key) const;
+private:
+ QMap<QString,unsigned long> values;
+};
#endif // PROC_H
+// vim:sw=4
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic