asmon: Just assume linux kernel > v2.6
Running asmon in a new kernel (v4.19 here) did not display memory information because the code checked whether the kernel was _exactly_ v2.6. Although I could modify the check for > v2.6 I decided to drop support for versions less than v2.6 (released in 2003).
This commit is contained in:
parent
e239e4a58d
commit
742d4deddf
|
@ -41,8 +41,6 @@
|
||||||
/* Evil globals I haven't removed yet */
|
/* Evil globals I haven't removed yet */
|
||||||
long last_pageins = 0, last_pageouts = 0;
|
long last_pageins = 0, last_pageouts = 0;
|
||||||
long last_swapins = 0, last_swapouts = 0;
|
long last_swapins = 0, last_swapouts = 0;
|
||||||
//double old;
|
|
||||||
static int has_kern26 = 0;
|
|
||||||
|
|
||||||
#ifdef EXEC_ON_CLICK
|
#ifdef EXEC_ON_CLICK
|
||||||
char Command[256] = "";
|
char Command[256] = "";
|
||||||
|
@ -77,9 +75,6 @@ int main(int argc, char *argv[])
|
||||||
int allmem = 1;
|
int allmem = 1;
|
||||||
int Xpid = 1;
|
int Xpid = 1;
|
||||||
char *ProgName;
|
char *ProgName;
|
||||||
struct utsname name;
|
|
||||||
int kernMajor, kernMinor, kernRev;
|
|
||||||
|
|
||||||
ProgName = argv[0];
|
ProgName = argv[0];
|
||||||
|
|
||||||
if (strlen(ProgName) >= 5)
|
if (strlen(ProgName) >= 5)
|
||||||
|
@ -144,18 +139,6 @@ int main(int argc, char *argv[])
|
||||||
openXwindow(argc, argv, asmon_master_xpm, asmon_mask_bits,
|
openXwindow(argc, argv, asmon_master_xpm, asmon_mask_bits,
|
||||||
asmon_mask_width, asmon_mask_height);
|
asmon_mask_width, asmon_mask_height);
|
||||||
|
|
||||||
if (uname(&name) != -1) {
|
|
||||||
if (strcmp(name.sysname, "Linux") == 0) {
|
|
||||||
sscanf(name.release, "%d.%d.%d", &kernMajor, &kernMinor,
|
|
||||||
&kernRev);
|
|
||||||
if ((kernMajor == 2) && (kernMinor == 6))
|
|
||||||
has_kern26 = 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Can't find system name\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
asmon_routine(Xpid, allmem);
|
asmon_routine(Xpid, allmem);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -344,7 +327,6 @@ void DrawCPU(void)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if ((fp = fopen("/proc/stat", "r")) != NULL) {
|
if ((fp = fopen("/proc/stat", "r")) != NULL) {
|
||||||
if (has_kern26 > 0) {
|
|
||||||
// CPU data
|
// CPU data
|
||||||
fscanf(fp, "cpu %lf %lf %lf %lf %lf %lf %lf", info,
|
fscanf(fp, "cpu %lf %lf %lf %lf %lf %lf %lf", info,
|
||||||
info + 1, info + 2, info + 3, info + 4, info + 5,
|
info + 1, info + 2, info + 3, info + 4, info + 5,
|
||||||
|
@ -373,44 +355,18 @@ void DrawCPU(void)
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// CPU data
|
|
||||||
fscanf(fp, "cpu %lf %lf %lf %lf", info, info + 1,
|
|
||||||
info + 2, info + 3);
|
|
||||||
|
|
||||||
// gather data for LED's
|
|
||||||
while (fgets(buf, 127, fp)) {
|
|
||||||
if (strstr(buf, "page"))
|
|
||||||
sscanf(buf, "page %ld %ld", &pageins,
|
|
||||||
&pageouts);
|
|
||||||
|
|
||||||
if (strstr(buf, "swap"))
|
|
||||||
sscanf(buf, "swap %ld %ld", &swapins,
|
|
||||||
&swapouts);
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate CPU stuff
|
// Calculate CPU stuff
|
||||||
if (has_kern26 > 0) {
|
|
||||||
for (i = 0; i < 7; i++) {
|
for (i = 0; i < 7; i++) {
|
||||||
fields[i] = info[i] - cpustat[i];
|
fields[i] = info[i] - cpustat[i];
|
||||||
cputotal += fields[i];
|
cputotal += fields[i];
|
||||||
cpustat[i] = info[i];
|
cpustat[i] = info[i];
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
for (i = 0; i < 4; i++) {
|
|
||||||
fields[i] = info[i] - cpustat[i];
|
|
||||||
cputotal += fields[i];
|
|
||||||
cpustat[i] = info[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//idlee=info[3]-old;
|
//idlee=info[3]-old;
|
||||||
|
|
||||||
//old=info[3];
|
//old=info[3];
|
||||||
|
|
||||||
// CPU Bar
|
|
||||||
|
|
||||||
//cputotal = 100 * l1 ;
|
//cputotal = 100 * l1 ;
|
||||||
//cputotal=(100-(idlee*100/16))*26/100;
|
//cputotal=(100-(idlee*100/16))*26/100;
|
||||||
if (cputotal > 0) {
|
if (cputotal > 0) {
|
||||||
|
@ -580,17 +536,13 @@ float DrawMemSwap(float total, int allmem)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
if ((fp = fopen("/proc/meminfo", "r")) != NULL) {
|
if ((fp = fopen("/proc/meminfo", "r")) != NULL) {
|
||||||
static float stotal = 0.0, sshared = 0.0, sbuffers =
|
|
||||||
0.0, scached = 0.0;
|
|
||||||
char junk[128];
|
char junk[128];
|
||||||
float used, freeM, shared, buffers, cached, swaptotal,
|
float used, freeM, buffers, cached, swaptotal,
|
||||||
swapused, swapfreeM;
|
swapused, swapfreeM;
|
||||||
unsigned long MEMshar, MEMbuff, MEMswap;
|
unsigned long MEMshar, MEMbuff, MEMswap;
|
||||||
int tempy, tempa;
|
int tempy, tempa;
|
||||||
|
|
||||||
if (has_kern26 > 0) {
|
|
||||||
float scratch;
|
float scratch;
|
||||||
|
|
||||||
while (!feof(fp)) {
|
while (!feof(fp)) {
|
||||||
fgets(junk, 120, fp);
|
fgets(junk, 120, fp);
|
||||||
if (strstr(junk, "MemTotal")) {
|
if (strstr(junk, "MemTotal")) {
|
||||||
|
@ -625,21 +577,10 @@ float DrawMemSwap(float total, int allmem)
|
||||||
swapused = swaptotal - swapfreeM;
|
swapused = swaptotal - swapfreeM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
fgets(junk, 80, fp);
|
|
||||||
fscanf(fp, "Mem: %f %f %f %f %f %f\nSwap: %f %f %f",
|
|
||||||
&total, &used, &freeM, &shared, &buffers,
|
|
||||||
&cached, &swaptotal, &swapused, &swapfreeM);
|
|
||||||
}
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
/* All mem areas */
|
/* All mem areas */
|
||||||
if (stotal != total || sshared != shared || sbuffers != buffers
|
|
||||||
|| scached != cached) {
|
|
||||||
stotal = total;
|
|
||||||
sshared = shared;
|
|
||||||
sbuffers = buffers;
|
|
||||||
scached = cached;
|
|
||||||
if ((total / 101048576) >= 1) {
|
if ((total / 101048576) >= 1) {
|
||||||
MEMshar =
|
MEMshar =
|
||||||
((used - buffers - cached) / total) * 27;
|
((used - buffers - cached) / total) * 27;
|
||||||
|
@ -677,7 +618,7 @@ float DrawMemSwap(float total, int allmem)
|
||||||
} else {
|
} else {
|
||||||
copyXPMArea(16, 46, 2, 14, 41, 16);
|
copyXPMArea(16, 46, 2, 14, 41, 16);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/* SWAP Meter */
|
/* SWAP Meter */
|
||||||
if (swaptotal == 0)
|
if (swaptotal == 0)
|
||||||
MEMswap = 0;
|
MEMswap = 0;
|
||||||
|
@ -705,6 +646,7 @@ float DrawMemSwap(float total, int allmem)
|
||||||
} else {
|
} else {
|
||||||
copyXPMArea(16, 46, 2, 14, 41, 30);
|
copyXPMArea(16, 46, 2, 14, 41, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return (total);
|
return (total);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue