New port: wmmemfree

WMMemFree shows system memory usage.  It runs as a dockapp for window
manager like WindowMaker or some other which supports dockapps.  On
the top side you have your physical memory usage and on the bottom there
is your swap space usage.

Submitted by:	Alexey Dokuchaev
This commit is contained in:
Max Khon 2003-04-11 10:28:51 +00:00
parent 526a33575a
commit 5f43e6f0c6
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=78733
10 changed files with 277 additions and 0 deletions

View File

@ -280,6 +280,7 @@
SUBDIR += wminet
SUBDIR += wmlmmon
SUBDIR += wmlongrun
SUBDIR += wmmemfree
SUBDIR += wmmemload
SUBDIR += wmmemmon
SUBDIR += wmmon

View File

@ -0,0 +1,32 @@
# New ports collection makefile for: wmmemfree
# Date created: 29 Mar 2003
# Whom: Alexey Dokuchaev <danfe@regency.nsu.ru>
#
# $FreeBSD$
#
PORTNAME= wmmemfree
PORTVERSION= 0.7
CATEGORIES= sysutils windowmaker
MASTER_SITES= http://ibiblio.org/pub/linux/X11/xutils/ \
ftp://ftp.ibiblio.org/pub/linux/X11/xutils/
MAINTAINER= danfe@regency.nsu.ru
COMMENT= Memory and swap monitoring dockapp
USE_BZIP2= yes
USE_X_PREFIX= yes
USE_XPM= yes
MAN1= ${PORTNAME}.1
post-patch:
@${CP} ${FILESDIR}/mem_freebsd.* ${WRKSRC}
do-install:
@${INSTALL_PROGRAM} ${WRKSRC}/${PORTNAME} ${PREFIX}/bin
@${CHMOD} g+s ${PREFIX}/bin/${PORTNAME}
@${CHOWN} root:kmem ${PREFIX}/bin/${PORTNAME}
@${INSTALL_MAN} ${WRKSRC}/${PORTNAME}.1 ${MANPREFIX}/man/man1
.include <bsd.port.mk>

View File

@ -0,0 +1 @@
MD5 (wmmemfree-0.7.tar.bz2) = 6b478209d907dd2955828e71319af757

View File

@ -0,0 +1,125 @@
/*
* mem_freebsd.c - get memory status
*
* Copyright (C) 2003 Alexey Dokuchaev <danfe@regency.nsu.ru>
* Parts are Copyright (C) 1993-2003 FreeBSD Project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
*/
#include <sys/types.h>
#include <sys/vmmeter.h>
#include <fcntl.h>
#include <kvm.h>
#include <nlist.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "mem_freebsd.h"
long long int mem_total, mem_used, mem_free, mem_buffers, mem_cached;
long long int swp_total, swp_used, swp_free;
static kvm_t *kd;
struct nlist nlst[] = { {"_cnt"}, {"_bufspace"}, {0} };
void
mem_init(void)
{
int pagesize;
if (!(kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")))
{
perror("kvm_open");
exit(1);
}
kvm_nlist(kd, nlst);
if (!nlst[0].n_type)
{
perror("kvm_nlist");
exit(1);
}
seteuid(getuid());
setegid(getgid());
if (geteuid() != getuid() || getegid() != getgid())
{
perror("sete?id");
exit(1);
}
}
void
mem_getfree()
{
struct vmmeter vm;
struct kvm_swap sw;
int bufspace = 0;
unsigned long cnt_offset;
unsigned long bufspace_offset;
static int firsttime = 1;
static int pagesin = -1;
static int pagesout = -1;
static time_t lasttime = 0;
time_t curtime;
if ((kvm_read(kd, nlst[0].n_value, &vm, sizeof(vm))
!= sizeof(vm)) ||
(kvm_read(kd, nlst[1].n_value, &bufspace, sizeof(bufspace))
!= sizeof(bufspace)))
{
perror("kvm_read");
exit(1);
}
mem_total = vm.v_page_count;
mem_free = vm.v_free_count;
mem_used = mem_total - mem_free;
mem_cached = vm.v_cache_count;
mem_buffers = bufspace / vm.v_page_size;
/*
* Only calculate when first time or when changes took place.
* Do not call it more than 1 time per 2 seconds; otherwise
* it can eat up to 50% of CPU time on heavy swap activity.
*/
curtime = time(NULL);
if (firsttime ||
(((vm.v_swappgsin > pagesin) ||
(vm.v_swappgsout > pagesout))
&& curtime > lasttime + 1))
{
if (kvm_getswapinfo(kd, &sw, 1, 0) >= 0 &&
sw.ksw_total)
{
swp_total = sw.ksw_total;
swp_used = sw.ksw_used;
swp_free = swp_total - swp_used;
}
firsttime = 0;
lasttime = curtime;
}
pagesin = vm.v_swappgsin;
pagesout = vm.v_swappgsout;
}

View File

@ -0,0 +1,32 @@
/*
* mem_freebsd.h
*
* Copyright (C) 2003 Alexey Dokuchaev <danfe@regency.nsu.ru>
* Parts are Copyright (C) 1993-2003 FreeBSD Project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
*/
#ifndef __MEM_FREEBSD_H__
#define __MEM_FREEBSD_H__
extern long long int mem_total, mem_used;
extern long long int mem_shared, mem_buffers, mem_cached;
extern long long int swp_total, swp_used;
void mem_init();
void mem_getfree();
#endif /* __MEM_FREEBSD_H__ */

View File

@ -0,0 +1,54 @@
--- Makefile.orig Sat Mar 22 02:59:07 2003
+++ Makefile Fri Apr 11 12:50:48 2003
@@ -1,38 +1,17 @@
-#Makefile
+CC ?= cc
+LDIR = -L${X11BASE}/lib
+IDIR = -I${X11BASE}/include
-PROG=wmmemfree
-OBJS=dockapp.o draw.o mem_linux.o options.o wmmemfree.o
+LIBS = -lX11 -lXpm -lXext -lkvm
-PREFIX=/usr/local
-BINDIR=$(PREFIX)/bin
-MANUALDIR=$(PREFIX)/share/man/man1
-CC=gcc
-STRIP=strip
-FLAGS=-Wall -O2
-RM=rm -f
-INST=install
-MANUAL=$(PROG).1
-LIBS=-L/usr/X11R6/lib -lX11 -lXext -lXpm
+OBJS = dockapp.o\
+ draw.o\
+ mem_freebsd.o\
+ options.o\
+ wmmemfree.o
-all: $(PROG)
+.c.o:
+ ${CC} ${CFLAGS} ${IDIR} ${DEFS} -c $< -o $*.o
-$(PROG): $(OBJS)
- $(CC) -o $(PROG) $(OBJS) $(LIBS)
- $(STRIP) $(PROG)
-%.o: %.c
- $(CC) $(FLAGS) -c $< -o $@
-clean:
- $(RM) $(OBJS) $(PROG)
-install: $(PROG)
- $(INST) -m 755 $(PROG) $(BINDIR)
- $(INST) -m 644 $(MANUAL) $(MANUALDIR)
-uninstall:
- $(RM) $(BINDIR)/$(PROG)
- $(RM) $(MANUALDIR)/$(MANUAL)
-
-dockapp.o: dockapp.c wmmemfree.h options.h draw.h xpm/bg.xpm xpm/on.xpm \
- xpm/off.xpm xpm/numbers.xpm xpm/panel.xpm
-draw.o: draw.c dockapp.h draw.h mem_linux.h options.h
-mem_linux.o: mem_linux.c
-options.o: options.c wmmemfree.h options.h
-wmmemfree.o: wmmemfree.c wmmemfree.h dockapp.h draw.h options.h
+all: ${OBJS}
+ ${CC} ${CFLAGS} -o wmmemfree ${OBJS} ${LDIR} ${LIBS}

View File

@ -0,0 +1,11 @@
--- draw.c.orig Fri Apr 11 12:47:47 2003
+++ draw.c Fri Apr 11 12:47:54 2003
@@ -24,7 +24,7 @@
#include "dockapp.h"
#include "draw.h"
-#include "mem_linux.h"
+#include "mem_freebsd.h"
#include "options.h"
void draw_window()

View File

@ -0,0 +1,16 @@
--- wmmemfree.c.orig Fri Apr 11 12:48:52 2003
+++ wmmemfree.c Fri Apr 11 12:50:05 2003
@@ -43,10 +43,11 @@
{
struct itimerval tv;
+ mem_init();
tv.it_value.tv_sec = 2; /* give 2 seconds for safety */
tv.it_value.tv_usec = 0;
- tv.it_interval.tv_sec = 0;
- tv.it_interval.tv_usec = opt_milisecs * 1000;
+ tv.it_interval.tv_sec = opt_milisecs / 1000;
+ tv.it_interval.tv_usec = (opt_milisecs % 1000) * 1000;
signal(SIGALRM, handle_timer);
setitimer(ITIMER_REAL, &tv, NULL);
}

View File

@ -0,0 +1,4 @@
WMMemFree shows system memory usage. It runs as a dockapp for window
manager like WindowMaker or some other which supports dockapps. On
the top side you have your physical memory usage and on the bottom there
is your swap space usage.

View File

@ -0,0 +1 @@
bin/wmmemfree