Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65bf48110a | ||
|
|
1268b76c3c | ||
| d3837a3dbf | |||
| 25677ed9ff | |||
|
|
382c8ec129 | ||
|
|
34548bbd21 |
27
Makefile
27
Makefile
@@ -1,25 +1,17 @@
|
||||
# OS=$(uname) make
|
||||
|
||||
### OS = FreeBSD
|
||||
PROG= xmem
|
||||
VERSION= 1.27
|
||||
FreeBSD_lflag= -lkvm
|
||||
LDFLAGS+= -L/usr/X11R6/lib -L/usr/local/lib/ -lX11 -lXt -lXaw -lXmu
|
||||
LDFLAGS+= $($(OS)_lflag)
|
||||
LDFLAGS+= -L/usr/X11R6/lib -L/usr/local/lib/ -lX11 -lXt -lXaw -lXmu
|
||||
LDFLAGS+= -lkvm
|
||||
CFLAGS+= -Wall -I/usr/X11R6/include/ -I/usr/local/include/
|
||||
OBJECTS= xmem.o MemStripChart.o
|
||||
FreeBSD_stub = get_mem_fbsd.o
|
||||
OpenBSD_stub = get_mem.o
|
||||
OBJECTS += $($(OS)_stub)
|
||||
|
||||
OBJECTS= xmem.o MemStripChart.o get_mem.o
|
||||
|
||||
all: xmem
|
||||
|
||||
xmem.full:
|
||||
echo "full not supported yet"
|
||||
@echo "full not supported yet"
|
||||
|
||||
xmem.debug:
|
||||
echo "debug not supported yet"
|
||||
@echo "debug not supported yet"
|
||||
|
||||
xmem: $(OBJECTS)
|
||||
$(CC) -o xmem $(OBJECTS) $(LDFLAGS)
|
||||
@@ -27,10 +19,10 @@ xmem: $(OBJECTS)
|
||||
%.o: %c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
clean:
|
||||
clean:
|
||||
-rm -rf $(OBJECTS) $(PROG)
|
||||
|
||||
dist:
|
||||
dist:
|
||||
mkdir -p ${PROG}-${VERSION}
|
||||
cp *.h *.c Makefile xmem.1 xmem.bit copyright XMem.ad ${PROG}-${VERSION}
|
||||
tar cfvz ${PROG}-${VERSION}.tar.gz ${PROG}-${VERSION}
|
||||
@@ -40,15 +32,14 @@ dist-clean:
|
||||
-rm ${PROG}-${VERSION}.tar.gz
|
||||
|
||||
install:
|
||||
install -d -m 755 {PREFIX}/bin/
|
||||
install -d -m 755 ${PREFIX}/bin/
|
||||
install -c -S -s -o root -g bin -m 755 xmem ${PREFIX}/bin/xmem
|
||||
install -d -m 755 ${PREFIX}/man/man1/
|
||||
install -c -o root -g bin -m 644 xmem.1 ${PREFIX}/man/man1/xmem.1
|
||||
install -d -m 755 ${PREFIX}/lib/X11/app-defaults/
|
||||
install -c -o root -g bin -m 644 XMem.ad ${PREFIX}/lib/X11/app-defaults/XMem
|
||||
install -d -m 755 ${PREFIX}/share/${PROG}/
|
||||
install -d -m 755 ${PREFIX}/share/${PROG}/
|
||||
install -c -o root -g bin -m 644 xmem.bit ${PREFIX}/share/${PROG}/xmem.bit
|
||||
install -c -o root -g bin -m 644 copyright ${PREFIX}/share/${PROG}/copyright
|
||||
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
2
README.md
Normal file
2
README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# xmem(1) X11 Utility
|
||||

|
||||
162
get_mem.c
162
get_mem.c
@@ -1,15 +1,17 @@
|
||||
/* $Id: get_mem.c,v 1.5 2018/12/26 18:46:04 bch Exp $
|
||||
*
|
||||
* Adapted: get memory usage on OpenBSD
|
||||
* Author: Christian Barthel <bch@online.de>
|
||||
*
|
||||
* xmem(1) utility adapted by Christian Barthel <bch@online.de>:
|
||||
* - Added OpenBSD support
|
||||
* - Added FreeBSD support
|
||||
*
|
||||
* get memory usage, from get_load.c derived
|
||||
*
|
||||
* Author: Hans-Helmut Buehmann 20. Jan. 1996
|
||||
*
|
||||
*
|
||||
* Modified for more recent kernels Helmut Geyer Oct. 1996
|
||||
*/
|
||||
|
||||
#if __OpenBSD__
|
||||
|
||||
#include <sys/param.h> /* DEV_BSIZE MAXCOMLEN PZERO */
|
||||
#include <sys/sysctl.h>
|
||||
@@ -26,11 +28,11 @@
|
||||
#include <err.h>
|
||||
#include "MemStripChart.h"
|
||||
|
||||
static int pageshift = -1;
|
||||
static int pageshift = -1;
|
||||
#define pagetok(size) ((size) << pageshift)
|
||||
#define LOG1024 10
|
||||
#define LOG1024 10
|
||||
|
||||
static double allmem_kb = 0;
|
||||
static double allmem_kb = 0;
|
||||
|
||||
static void initPageShift(void)
|
||||
{
|
||||
@@ -43,7 +45,7 @@ static void initPageShift(void)
|
||||
pageshift -= LOG1024;
|
||||
}
|
||||
|
||||
static double getSwapFrac()
|
||||
static double getSwapFrac()
|
||||
{
|
||||
struct swapent *swdev;
|
||||
int used, total, nswap, rnswap, i;
|
||||
@@ -76,17 +78,17 @@ static double getSwapFrac()
|
||||
return (double)used/total;
|
||||
}
|
||||
|
||||
void GetMemLoadPoint(Widget w, caddr_t closure, caddr_t call_data)
|
||||
void GetMemLoadPoint(Widget w, caddr_t closure, caddr_t call_data)
|
||||
{
|
||||
static int bcstats_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT};
|
||||
static int uvmexp_mib[] = {CTL_VM, VM_UVMEXP};
|
||||
MemStripChartCallbackData ret;
|
||||
struct uvmexp uvmexp;
|
||||
struct bcachestats bcstats;
|
||||
size_t size;
|
||||
|
||||
if (pageshift < 0)
|
||||
initPageShift();
|
||||
size_t size;
|
||||
|
||||
if (pageshift < 0)
|
||||
initPageShift();
|
||||
|
||||
size = sizeof(uvmexp);
|
||||
if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) < 0) {
|
||||
@@ -100,7 +102,7 @@ void GetMemLoadPoint(Widget w, caddr_t closure, caddr_t call_data)
|
||||
}
|
||||
|
||||
|
||||
allmem_kb = pagetok(uvmexp.npages);
|
||||
allmem_kb = pagetok(uvmexp.npages);
|
||||
ret.cached = pagetok(bcstats.numbufpages) / allmem_kb;
|
||||
ret.free = pagetok(uvmexp.free) / allmem_kb;
|
||||
ret.buffer = 0;
|
||||
@@ -108,9 +110,137 @@ void GetMemLoadPoint(Widget w, caddr_t closure, caddr_t call_data)
|
||||
ret.swap = getSwapFrac();
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%lf %lf %lf %lf %lf\n", allmem_kb, ret.code, ret.cached, ret.free, ret.swap);
|
||||
printf("%lf %lf %lf %lf %lf\n",
|
||||
allmem_kb,
|
||||
ret.code,
|
||||
ret.cached,
|
||||
ret.free,
|
||||
ret.swap);
|
||||
#endif
|
||||
|
||||
|
||||
memcpy(call_data, &ret, sizeof(MemStripChartCallbackData));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------------- */
|
||||
|
||||
#if __FreeBSD__
|
||||
|
||||
/* $Id: get_mem_fbsd.c,v 1.1 2018/12/26 18:46:16 bch Exp $
|
||||
*
|
||||
* Author: Christian Barthel <bch@online.de>
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/types.h> /* DEV_BSIZE MAXCOMLEN PZERO */
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <kvm.h>
|
||||
|
||||
#include <X11/Xos.h>
|
||||
#include <X11/Intrinsic.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
#include "MemStripChart.h"
|
||||
|
||||
static int pageshift = -1;
|
||||
static int pagesize = 0;
|
||||
static kvm_t *kd = 0;
|
||||
#define pagetok(size) ((size) << pageshift)
|
||||
#define LOG1024 10
|
||||
|
||||
static unsigned int allmem_pages = 0;
|
||||
|
||||
static void initPageShift(void)
|
||||
{
|
||||
pagesize = getpagesize();
|
||||
size_t len = sizeof(allmem_pages);
|
||||
int mib[len];
|
||||
pageshift = 0;
|
||||
while (pagesize > 1) {
|
||||
pageshift++;
|
||||
pagesize >>= 1;
|
||||
}
|
||||
pageshift -= LOG1024;
|
||||
|
||||
kd = kvm_open(NULL, "/dev/null" ,NULL, O_RDONLY, "kvm_open");
|
||||
|
||||
if (sysctlbyname("vm.stats.vm.v_page_count", &allmem_pages, &len, NULL, 0) == -1)
|
||||
perror("sysctl");
|
||||
#ifdef DEBUG
|
||||
printf("page_count: %d\n", allmem_pages);
|
||||
#endif
|
||||
}
|
||||
|
||||
static double getSwapFrac()
|
||||
{
|
||||
/* XXX Borrowed from top(1) code: */
|
||||
int n;
|
||||
struct kvm_swap swapary[1];
|
||||
static int pagesize = 0;
|
||||
static unsigned long swap_maxpages = 0;
|
||||
size_t sz = sizeof(swap_maxpages);
|
||||
|
||||
int retavail = 0;
|
||||
int retfree = 0;
|
||||
|
||||
|
||||
n = kvm_getswapinfo(kd, swapary, 1, 0);
|
||||
if (n < 0 || swapary[0].ksw_total == 0)
|
||||
return (0);
|
||||
|
||||
if (swap_maxpages == 0)
|
||||
sysctlbyname("vm.swap_maxpages",
|
||||
&swap_maxpages, &sz, NULL, 0);
|
||||
|
||||
if ( swapary[0].ksw_total > swap_maxpages )
|
||||
swapary[0].ksw_total = swap_maxpages;
|
||||
|
||||
retavail = swapary[0].ksw_total;
|
||||
retfree = swapary[0].ksw_total - swapary[0].ksw_used;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("swap: %d %d %d %d\n", retavail,
|
||||
retavail, swapary[0].ksw_total,
|
||||
swapary[0].ksw_used);
|
||||
#endif
|
||||
return (double)(retavail-retfree)/(double)retavail;
|
||||
}
|
||||
|
||||
void GetMemLoadPoint(Widget w, caddr_t closure, caddr_t call_data)
|
||||
{
|
||||
MemStripChartCallbackData ret;
|
||||
int a, b;
|
||||
size_t sz = sizeof(int);
|
||||
double cache = 0;
|
||||
|
||||
if (pageshift < 0)
|
||||
initPageShift();
|
||||
|
||||
sysctlbyname("vm.stats.vm.v_wire_count", &a, &sz, NULL, 0);
|
||||
ret.code = (double)a / (double)allmem_pages;
|
||||
|
||||
sysctlbyname("vm.stats.vm.v_active_count", &a, &sz, NULL, 0);
|
||||
ret.buffer = (double)a / (double)allmem_pages;
|
||||
|
||||
/* v_cache_count and v_inactive_count are treated similarly */
|
||||
sysctlbyname("vm.stats.vm.v_inactive_count", &a, &sz, NULL, 0);
|
||||
sysctlbyname("vm.stats.vm.v_cache_count", &b, &sz, NULL, 0);
|
||||
ret.cached = (double)(a + b) / allmem_pages;
|
||||
|
||||
|
||||
sysctlbyname("vm.stats.vm.v_free_count", &a, &sz, NULL, 0);
|
||||
ret.free = (double)a / allmem_pages;
|
||||
ret.swap = getSwapFrac();
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%u %lf %lf %lf %lf\n", allmem_pages,
|
||||
ret.code, ret.cached, ret.free, ret.swap);
|
||||
#endif
|
||||
memcpy(call_data, &ret, sizeof(MemStripChartCallbackData));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
113
get_mem_fbsd.c
113
get_mem_fbsd.c
@@ -1,113 +0,0 @@
|
||||
/* $Id: get_mem_fbsd.c,v 1.1 2018/12/26 18:46:16 bch Exp $
|
||||
*
|
||||
* Author: Christian Barthel <bch@online.de>
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/types.h> /* DEV_BSIZE MAXCOMLEN PZERO */
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <kvm.h>
|
||||
|
||||
#include <X11/Xos.h>
|
||||
#include <X11/Intrinsic.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
#include "MemStripChart.h"
|
||||
|
||||
static int pageshift = -1;
|
||||
static int pagesize = 0;
|
||||
static kvm_t *kd = 0;
|
||||
#define pagetok(size) ((size) << pageshift)
|
||||
#define LOG1024 10
|
||||
|
||||
static unsigned int allmem_pages = 0;
|
||||
|
||||
static void initPageShift(void)
|
||||
{
|
||||
pagesize = getpagesize();
|
||||
size_t len = sizeof(allmem_pages);
|
||||
int mib[len];
|
||||
pageshift = 0;
|
||||
while (pagesize > 1) {
|
||||
pageshift++;
|
||||
pagesize >>= 1;
|
||||
}
|
||||
pageshift -= LOG1024;
|
||||
|
||||
kd = kvm_open(NULL, "/dev/null" ,NULL, O_RDONLY, "kvm_open");
|
||||
|
||||
if (sysctlbyname("vm.stats.vm.v_page_count", &allmem_pages, &len, NULL, 0) == -1)
|
||||
perror("sysctl");
|
||||
#ifdef DEBUG
|
||||
printf("page_count: %d\n", allmem_pages);
|
||||
#endif
|
||||
}
|
||||
|
||||
static double getSwapFrac()
|
||||
{
|
||||
/* XXX Borrowed from top(1) code: */
|
||||
int n;
|
||||
struct kvm_swap swapary[1];
|
||||
static int pagesize = 0;
|
||||
static unsigned long swap_maxpages = 0;
|
||||
size_t sz = sizeof(swap_maxpages);
|
||||
|
||||
int retavail = 0;
|
||||
int retfree = 0;
|
||||
|
||||
|
||||
n = kvm_getswapinfo(kd, swapary, 1, 0);
|
||||
if (n < 0 || swapary[0].ksw_total == 0)
|
||||
return (0);
|
||||
|
||||
if (swap_maxpages == 0)
|
||||
sysctlbyname("vm.swap_maxpages", &swap_maxpages, &sz, NULL, 0);
|
||||
|
||||
if ( swapary[0].ksw_total > swap_maxpages )
|
||||
swapary[0].ksw_total = swap_maxpages;
|
||||
|
||||
retavail = swapary[0].ksw_total;
|
||||
retfree = swapary[0].ksw_total - swapary[0].ksw_used;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("swap: %d %d %d %d\n", retavail, retavail, swapary[0].ksw_total,
|
||||
swapary[0].ksw_used);
|
||||
#endif
|
||||
return (double)(retavail-retfree)/(double)retavail;
|
||||
}
|
||||
|
||||
void GetMemLoadPoint(Widget w, caddr_t closure, caddr_t call_data)
|
||||
{
|
||||
MemStripChartCallbackData ret;
|
||||
int a, b;
|
||||
size_t sz = sizeof(int);
|
||||
double cache = 0;
|
||||
|
||||
if (pageshift < 0)
|
||||
initPageShift();
|
||||
|
||||
sysctlbyname("vm.stats.vm.v_wire_count", &a, &sz, NULL, 0);
|
||||
ret.code = (double)a / (double)allmem_pages;
|
||||
|
||||
sysctlbyname("vm.stats.vm.v_active_count", &a, &sz, NULL, 0);
|
||||
ret.buffer = (double)a / (double)allmem_pages;
|
||||
|
||||
/* v_cache_count and v_inactive_count are treated similarly */
|
||||
sysctlbyname("vm.stats.vm.v_inactive_count", &a, &sz, NULL, 0);
|
||||
sysctlbyname("vm.stats.vm.v_cache_count", &b, &sz, NULL, 0);
|
||||
ret.cached = (double)(a + b) / allmem_pages;
|
||||
|
||||
|
||||
sysctlbyname("vm.stats.vm.v_free_count", &a, &sz, NULL, 0);
|
||||
ret.free = (double)a / allmem_pages;
|
||||
ret.swap = getSwapFrac();
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%u %lf %lf %lf %lf\n", allmem_pages,
|
||||
ret.code, ret.cached, ret.free, ret.swap);
|
||||
#endif
|
||||
memcpy(call_data, &ret, sizeof(MemStripChartCallbackData));
|
||||
}
|
||||
104
www/index.html
Executable file
104
www/index.html
Executable file
@@ -0,0 +1,104 @@
|
||||
<head>
|
||||
<link rel="shortcut icon" href="stat//icons/favicon.ico" />
|
||||
|
||||
|
||||
<title>onfire.org</title>
|
||||
<style type="text/css">
|
||||
body {font-family:"Comic Sans MS", cursive, sans-serif;
|
||||
color: black;
|
||||
}
|
||||
#footer {
|
||||
position:relative;
|
||||
bottom:-5em;
|
||||
text-align:right;
|
||||
margin-top: 10px;
|
||||
width: 100%;
|
||||
height: 2em;
|
||||
text-align: right;
|
||||
line-height: 2.0em;
|
||||
padding-right=5px;
|
||||
}
|
||||
|
||||
#all {
|
||||
position: relative;
|
||||
padding-left: 10px;
|
||||
padding-right: 38px;
|
||||
}
|
||||
|
||||
.blink {
|
||||
animation: blink 1s steps(5, start) infinite;
|
||||
-webkit-animation: blink 1s steps(5, start) infinite;
|
||||
}
|
||||
@keyframes blink {
|
||||
to {
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
@-webkit-keyframes blink {
|
||||
to {
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body bgcolor="white">
|
||||
<h1>xmem</h1>
|
||||
<tt>xmem</tt> is an X11 utility to display memory and swap usage. It was initially
|
||||
created by the K. Shane Hartman (MIT-LCS) and Stuart A. Malone (MIT-LCS); with
|
||||
features added by Jim Gettys (MIT-Athena), Bob Scheifler (MIT-LCS),
|
||||
Tony Della Fera (MIT-Athena), and Chris Peterson (MIT-LCS). I did the initial
|
||||
import from a Debian package and added support for OpenBSD and pledged the code.
|
||||
<br>
|
||||
I wasn't able to find any homepage, so I decided to host
|
||||
<a href="https://git.onfire.org/bch/cgi-bin/gitweb.cgi?p=unix/xmem;a=summary">code</a>
|
||||
and
|
||||
<a href="http://onfire.org/snapshots/xmem/xmem-1.26.tar.gz">snapshots</a> here.
|
||||
Current version is 1.26.
|
||||
If you are, or know the author, please let <a href="mailto:bch@online.de">me</a> know!
|
||||
<br>
|
||||
<h2>Sample: running xmem on my system: </h2>
|
||||
<table border=0>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="./xmem.png"><img src="./xmem_s.png" alt="xmem pic"></a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="./xmem_fvwmbar.png"><img src="./xmem_fvwmbar_s.png" alt="xmem pic"></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>Another xmem(1) user: <a href="https://xteddy.org/xmem.html">xteddy.org/xmem</a></p>
|
||||
<h2>xmem license</h2>
|
||||
<pre>
|
||||
Copyright (C) 1987 X Consortium
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of the X Consortium shall
|
||||
not be used in advertising or otherwise to promote the sale, use or
|
||||
other dealings in this Software without prior written authorization from
|
||||
the X Consortium.
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
BIN
www/xmem.png
Executable file
BIN
www/xmem.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 950 KiB |
BIN
www/xmem_fvwmbar.png
Executable file
BIN
www/xmem_fvwmbar.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
www/xmem_fvwmbar_s.png
Executable file
BIN
www/xmem_fvwmbar_s.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
BIN
www/xmem_s.png
Executable file
BIN
www/xmem_s.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Reference in New Issue
Block a user