sumi@minako.stars.flab.fujitsu.co.jp (Shinji Sumimoto) (11/30/89)
Submitted-by: ucbcad!uunet.UU.NET!sumi%minako.stars.flab.fujitsu.junet Posting-number: Volume 5, Issue 33 Archive-name: xtacho/patch1 Patch-To: xtacho: Volume 4, Issue 63 (July 19, 1989) ----- Shinji Sumimoto Fujitsu Laboratories Ltd. Artificial Intelligence Laboratory sumi@minako.stars.flab.fujitsu.co.jp ------- ------ Followings are new patch ------ Submitted-by: sumi@minako.stars.flab.fujitsu.co.jp (Shinji Sumimoto) Posting-number: Volume 1. Archive-name: xtacho/patch1 Original-Archive: (v04i063: xtacho -- x cpu tachometer, Part01/01 Date: 19 Jul 89 23:29:32 GMT) This is a patch to improve xtacho that was posted by Kazuhiko Shutoh (e-mail: shutoh@isl.yamaha.co.jp). This improves following improvements: 1) Triple tachometer display. Xtachos displays System, User, Idle tachometers from the left side. 2) Support a system without rstat library. Xtachos gets the data from /dev/kmem This xtachos works well on Sun-3(SunOS 4.0,X11R3) and 4.3BSD(X11R3). These patches consist of following files: README--- You already know patch1--- patch file to xtachos patch.sh- shell script for making xtachos Any comments and bug fixes are welcome. Have fun ! ----- Shinji Sumimoto Fujitsu Laboratories Ltd. Artificial Intelligence Laboratory sumi@minako.stars.flab.fujitsu.co.jp ------- ------------- cut here -------------- #!/bin/sh # shar: Shell Archiver (v1.22) # # Run the following text with /bin/sh to create: # README # patch.sh # patch1 # echo "x - extracting README (Text)" sed 's/^X//' << 'SHAR_EOF' > README && XSubmitted-by: sumi@minako.stars.flab.fujitsu.co.jp (Shinji Sumimoto) XPosting-number: Volume 1, XArchive-name: xtacho/patch1 X XThese patches to xtacho improve following improvements: X X 1) Triple tachometer display. X Xtachos displays System, User, Idle tachometers from the left side. X X 2) Support a system without rstat library. X xtachos gets the data from /dev/kmem X XThis xtachos works well on Sun-3(SunOS 4.0,X11R3) and 4.3BSD(X11R3). X XThese patches consist of following files: X X README--- You already know X patch1--- patch file to xtachos X patch.sh- shell script for making xtachos X X XTODO: X Please execute patch.sh, this automatically replaces X xtacho files, and make xtachos files. X And edit a Makefile in following way: X (defaults: It's for sun) X X - If your system has a rstat library, X please adds compiler option -DRSTAT.(in defaults) X X - If your system does not have a rstat liibrary, X please remove -DRSTAT. X Program gets a data from /dev/kmem X X And executes make command. X X Have fun ! X SHAR_EOF chmod 0644 README || echo "restore of README fails" echo "x - extracting patch.sh (Text)" sed 's/^X//' << 'SHAR_EOF' > patch.sh && X#!/bin/sh Xcat patch1 | patch Xmv xtacho.c xtachos.c Xmv xtacho.h xtachos.h SHAR_EOF chmod 0755 patch.sh || echo "restore of patch.sh fails" echo "x - extracting patch1 (Text)" sed 's/^X//' << 'SHAR_EOF' > patch1 && XIndex: Makefile X*** Makefile.xtacho Sat Nov 25 18:26:19 1989 X--- Makefile Sat Nov 25 18:31:17 1989 X*************** X*** 1,4 **** X! # SCCS ID @(#)Makefile 1.7 7/14/89 X # X # Makefile - Makefile for xtacho X # X--- 1,4 ---- X! # SCCS ID @(#)Makefile 1.5 7/12/89 X # X # Makefile - Makefile for xtacho X # X*************** X*** 9,20 **** X # comment and the author's name is retained. The author assumes no X # responsibility for lost sleep as a consequence of use of this software. X # X! # Send any comments, bug reports, etc. to: shutoh@isl.yamaha.JUNET or, X! # for oversea: shutoh%isl.yamaha.JUNET%kddlab@uunet.uu.net X # X # X CC = /bin/cc X! CFLAGS = -f68881 -O X DESTDIR = /usr/bin/X11 X MANDIR = /usr/man/mann X # X--- 9,26 ---- X # comment and the author's name is retained. The author assumes no X # responsibility for lost sleep as a consequence of use of this software. X # X! # Send any comments, bug reports, etc. to shutoh@isl.yamaha.JUNET X # X # X CC = /bin/cc X! # for machines with rstat library X! # for sun-3 X! CFLAGS = -f68881 -O -DRSTAT X! # for sun-4 X! #CFLAGS = -O -DRSTAT X! # for BSD without rstat library X! #CFLAGS = -O X! X DESTDIR = /usr/bin/X11 X MANDIR = /usr/man/mann X # X*************** X*** 25,36 **** X # Libraries for X11R3 X # X LIBS = -lXaw -lXmu -lXt -lX11 -lm -lrpcsvc X X ############################################################################## X! PROGRAMS = ./xtacho X! SRCS = ./xtacho.c X! OBJS = ./xtacho.o X! LOCALHDRS = ./xtacho.h ./xtacho.icon X EXTERNHDRS = /usr/include/stdio.h \ X /usr/include/math.h \ X /usr/include/rpcsvc/rstat.h \ X--- 31,44 ---- X # Libraries for X11R3 X # X LIBS = -lXaw -lXmu -lXt -lX11 -lm -lrpcsvc X+ # without rstat library X+ #LIBS = -lXaw -lXmu -lXt -lX11 -lm X X ############################################################################## X! PROGRAMS = ./xtachos X! SRCS = ./xtachos.c X! OBJS = ./xtachos.o X! LOCALHDRS = ./xtachos.h ./xtacho.icon X EXTERNHDRS = /usr/include/stdio.h \ X /usr/include/math.h \ X /usr/include/rpcsvc/rstat.h \ XIndex: xtacho.c X*** xtacho.c Sat Nov 25 18:26:21 1989 X--- xtachos.c Sat Nov 25 18:32:28 1989 X*************** X*** 1,9 **** X! static char sccsid[] = "@(#)xtacho.c 1.9 7/18/89"; X X /* X * xtacho - The cpu load tachometer for X11 X * X * Author: Kazuhiko Shutoh, 1989. X * X * Permission to use, copy, modify and distribute without charge this software, X * documentation, images, etc. is granted, provided that this comment and the X--- 1,10 ---- X! static char sccsid[] = "@(#)xtachos.c 1.5 7/12/89"; X X /* X * xtacho - The cpu load tachometer for X11 X * X * Author: Kazuhiko Shutoh, 1989. X+ * Revised by Shinji Sumimoto, 1989/9 (xtachos) X * X * Permission to use, copy, modify and distribute without charge this software, X * documentation, images, etc. is granted, provided that this comment and the X*************** X*** 10,20 **** X * author's name is retained. The author assumes no responsibility for lost X * sleep as a consequence of use of this software. X * X! * Send any comments, bug reports, etc. to: shutoh@isl.yamaha.JUNET or, X! * for oversea: shutoh%isl.yamaha.JUNET%kddlab@uunet.uu.net X! * X */ X X #include <X11/Intrinsic.h> X #include <X11/StringDefs.h> X #include <X11/Shell.h> X--- 11,28 ---- X * author's name is retained. The author assumes no responsibility for lost X * sleep as a consequence of use of this software. X * X! * Send any comments, bug reports, etc. to shutoh@isl.yamaha.JUNET X! * X */ X X+ #include <stdio.h> X+ #include <math.h> X+ #ifdef RSTAT X+ #include <rpcsvc/rstat.h> X+ #else /* 4.3 BSD */ X+ #include <nlist.h> X+ #include <sys/dk.h> X+ #endif X #include <X11/Intrinsic.h> X #include <X11/StringDefs.h> X #include <X11/Shell.h> X*************** X*** 22,34 **** X #include <X11/Label.h> X #include <X11/Command.h> X #include <X11/Form.h> X! #include <stdio.h> X! #include <math.h> X! #include <rpcsvc/rstat.h> X! #include "xtacho.h" X #include "xtacho.icon" X X XtCallbackProc redraw_callback(); X XtTimerCallbackProc PollingCpuStatus(); X void SetupTacho(); X void GetGraphicContexts(); X--- 30,40 ---- X #include <X11/Label.h> X #include <X11/Command.h> X #include <X11/Form.h> X! #include "xtachos.h" X #include "xtacho.icon" X X XtCallbackProc redraw_callback(); X+ XtCallbackProc Destroy(); X XtTimerCallbackProc PollingCpuStatus(); X void SetupTacho(); X void GetGraphicContexts(); X*************** X*** 41,56 **** X void DrawSingleNumber(); X void DrawNeedle(); X X! Widget toplevel, base, info, meter; X! GC gcForeground, gcBackground, gcNeedle; X X char hostname[MAXCHARS]; X unsigned char monitor_item; X long update; X! Cardinal current_status = 0; X! Cardinal old_status = 0; X! Cardinal old_status_time = 0; X X main(argc, argv) X int argc; X char **argv; X--- 47,75 ---- X void DrawSingleNumber(); X void DrawNeedle(); X X! Widget toplevel, base, info[3], meter[3]; X! GC gcForeground, gcBackground, gcNeedle[3]; X X char hostname[MAXCHARS]; X unsigned char monitor_item; X long update; X! Cardinal current_status[3] = { 0,0,0 }; X! Cardinal old_status[3] = { 0,0,0 }; X! Cardinal old_status_time[3] = { 0,0,0 }; X! #ifndef RSTAT X! struct statstime { X! long cp_time[4]; X! int tmp; X! } ; X! struct nlist nl[]= { X! {"_cp_time"}, X! {""}, X! }; X X+ #define KERNEL_NAME "/vmunix" X+ #define MEM_NAME "/dev/kmem" X+ int mfd; X+ #endif X main(argc, argv) X int argc; X char **argv; X*************** X*** 57,63 **** X { X X Arg args[10]; X! Cardinal i; X XtIntervalId intervalId; X XtTranslations newTranslations; X static XtActionsRec redrawActions[] = { X--- 76,82 ---- X { X X Arg args[10]; X! Cardinal i, j; X XtIntervalId intervalId; X XtTranslations newTranslations; X static XtActionsRec redrawActions[] = { X*************** X*** 69,75 **** X <ResReq>: expose()"; X X struct statstime cpu_status; X! char label[MAXCHARS]; X X X toplevel = XtInitialize("xtacho", "XTacho", NULL, 0, &argc, argv); X--- 88,94 ---- X <ResReq>: expose()"; X X struct statstime cpu_status; X! char label[3][MAXCHARS]; X X X toplevel = XtInitialize("xtacho", "XTacho", NULL, 0, &argc, argv); X*************** X*** 84,130 **** X SetupTacho(argc, argv); X X base = XtCreateManagedWidget("base", formWidgetClass, toplevel, NULL, 0); X X! switch (monitor_item) { X! case USER_CPU: X! sprintf(label, "%s : User", hostname); X! break; X X- case SYSTEM_CPU: X- sprintf(label, "%s : System", hostname); X- break; X- X- case IDLE_CPU: X- sprintf(label, "%s : Idle", hostname); X- break; X- X- default: X- break; X- } X- X- i = 0; X- XtSetArg(args[i], XtNlabel, label);i++; X- XtSetArg(args[i], XtNwidth, 100);i++; X- info = XtCreateManagedWidget("info", labelWidgetClass, base, args, i); X- X- i = 0; X- XtSetArg(args[i], XtNwidth, 100);i++; X- XtSetArg(args[i], XtNheight, 100);i++; X- XtSetArg(args[i], XtNborderWidth, 0);i++; X- XtSetArg(args[i], XtNfromVert, info);i++; X- meter = XtCreateManagedWidget("meter", boxWidgetClass, base, args, i); X- X- GetGraphicContexts(meter); X- X XtAddActions(redrawActions, XtNumber(redrawActions)); X newTranslations = XtParseTranslationTable(overrideTranslations); X- XtOverrideTranslations(meter, newTranslations); X X! rstat(hostname, &cpu_status); X! X! old_status_time = cpu_status.cp_time[monitor_item]; X! X! X /* Interval timer start */ X X intervalId = XtAddTimeOut(update, PollingCpuStatus, NULL); X--- 103,150 ---- X SetupTacho(argc, argv); X X base = XtCreateManagedWidget("base", formWidgetClass, toplevel, NULL, 0); X+ sprintf(label[0], "%s : User", hostname); X+ sprintf(label[1], "System"); X+ sprintf(label[2], "Idle"); X+ for(j = 0; j < 3; j++) { X+ i = 0; X+ XtSetArg(args[i], XtNlabel, label[j]);i++; X+ XtSetArg(args[i], XtNwidth, 100);i++; X+ if(j!=0) { X+ XtSetArg(args[i], XtNfromHoriz, info[j-1]);i++; X+ } X+ info[j] = XtCreateManagedWidget("info", labelWidgetClass, base, args, i); X+ } X+ for(j = 0; j < 3; j++) { X+ i = 0; X+ XtSetArg(args[i], XtNwidth, 100);i++; X+ XtSetArg(args[i], XtNheight, 100);i++; X+ XtSetArg(args[i], XtNborderWidth, 0);i++; X+ XtSetArg(args[i], XtNfromVert, info[j]);i++; X+ if(j!=0) { X+ XtSetArg(args[i], XtNfromHoriz, meter[j-1]);i++; X+ } X+ meter[j] = XtCreateManagedWidget("meter", boxWidgetClass, base, args, i); X X! GetGraphicContexts(meter[j], j); X! } X! #ifdef RSTAT X! rstat(hostname, &cpu_status); X! #else X! sys_init(); X! get_stat(&cpu_status.cp_time[0]); X! #endif X! cpu_status.cp_time[0] = cpu_status.cp_time[0] + cpu_status.cp_time[1]; X! cpu_status.cp_time[1] = cpu_status.cp_time[2]; X! cpu_status.cp_time[2] = cpu_status.cp_time[3]; X X XtAddActions(redrawActions, XtNumber(redrawActions)); X newTranslations = XtParseTranslationTable(overrideTranslations); X X! for(j = 0; j < 3; j++) { X! XtOverrideTranslations(meter[j], newTranslations); X! old_status_time[j] = cpu_status.cp_time[j]; X! } X /* Interval timer start */ X X intervalId = XtAddTimeOut(update, PollingCpuStatus, NULL); X*************** X*** 169,176 **** X } X X void X! GetGraphicContexts(w) X Widget w; X { X X Arg args[2]; X--- 189,197 ---- X } X X void X! GetGraphicContexts(w, j) X Widget w; X+ Cardinal j; X { X X Arg args[2]; X*************** X*** 189,195 **** X gcv.foreground = args[0].value; X gcv.foreground = args[0].value; X gcv.function = GXinvert; X! gcNeedle = XtGetGC(w, GCFunction, &gcv); X } X X void X--- 210,216 ---- X gcv.foreground = args[0].value; X gcv.foreground = args[0].value; X gcv.function = GXinvert; X! gcNeedle[j] = XtGetGC(w, GCFunction, &gcv); X } X X void X*************** X*** 224,229 **** X--- 245,251 ---- X Cardinal d_ry; X Cardinal d_width; X Cardinal d_height; X+ Cardinal j; X X X XtSetArg(args[0], XtNwidth, 0); X*************** X*** 253,261 **** X /* Draw gauge */ X X DrawGauge(w, gcForeground, d_rx, d_ry); X X- DrawNeedle(w, gcNeedle, current_status); X- X } X X void X--- 275,289 ---- X /* Draw gauge */ X X DrawGauge(w, gcForeground, d_rx, d_ry); X+ for(j=0; j < 3; j++) { X+ if(meter[j] == w) { X+ goto find; X+ } X+ } X+ return; X+ find: X+ DrawNeedle(w, gcNeedle[j], current_status[j]); X X } X X void X*************** X*** 446,480 **** X { X X struct statstime system_status; X! Cardinal load_count, step; X X /* Get new CpuTime */ X! X rstat(hostname, &system_status); X! current_status = (double) (system_status.cp_time[monitor_item] - old_status_time) / ((double) update / 2000.0); X! old_status_time = system_status.cp_time[monitor_item]; X X! if (current_status > 100) X! current_status /= 2; X! X! if (current_status != old_status) { X /* Move Needle */ X X! if (current_status < old_status) X step = -1; X else X step = 1; X X! for (load_count = old_status; load_count != current_status; load_count += step) X! DrawNeedle(meter, gcNeedle, load_count); X X! for (load_count = old_status + step; load_count != current_status + step; load_count += step) X! DrawNeedle(meter, gcNeedle, load_count); X X! } X X XtAddTimeOut(update, PollingCpuStatus, NULL); X X- old_status = current_status; X- X } X--- 474,544 ---- X { X X struct statstime system_status; X! Cardinal load_count, step, j, tmp; X X /* Get new CpuTime */ X! #ifdef RSTAT X rstat(hostname, &system_status); X! #else X! get_stat(&system_status.cp_time[0]); X! #endif X! system_status.cp_time[0] = system_status.cp_time[0] + system_status.cp_time[1]; X! system_status.cp_time[1] = system_status.cp_time[2]; X! system_status.cp_time[2] = system_status.cp_time[3]; X! tmp = 0; X! for(j = 0; j < 3; j++) { X! tmp += (system_status.cp_time[j] - old_status_time[j]) ; X! } X! X! for(j = 0; j < 3; j++) { X! current_status[j] = (double) (system_status.cp_time[j] - old_status_time[j]) / ((double) tmp / 100.0); X! old_status_time[j] = system_status.cp_time[j]; X! X! if (current_status[j] > 100) X! current_status[j] /= 2; X X! if (current_status[j] != old_status[j]) { X /* Move Needle */ X X! if (current_status[j] < old_status[j]) X step = -1; X else X step = 1; X X! for (load_count = old_status[j]; load_count != current_status[j]; load_count += step) X! DrawNeedle(meter[j], gcNeedle[j], load_count); X X! for (load_count = old_status[j] + step; load_count != current_status[j] + step; load_count += step) X! DrawNeedle(meter[j], gcNeedle[j], load_count); X X! } X X+ old_status[j] = current_status[j]; X+ } X+ X XtAddTimeOut(update, PollingCpuStatus, NULL); X X } X+ X+ #ifndef RSTAT X+ /* get CPU status from kernel */ X+ sys_init() X+ { X+ nlist("/vmunix", nl); X+ if(nl[0].n_type == 0) { X+ fprintf(stderr, "no namelist in %s\n", KERNEL_NAME); X+ exit(1); X+ } X+ if((mfd = open(MEM_NAME, 0)) < 0) { X+ fprintf(stderr, "fali to open %s\n", MEM_NAME); X+ exit(1); X+ } X+ } X+ get_stat(mem_ad) X+ int *mem_ad; X+ { X+ lseek(mfd, nl[0].n_value, 0); X+ read(mfd, mem_ad, 16); X+ } X+ X+ #endif SHAR_EOF chmod 0644 patch1 || echo "restore of patch1 fails" exit 0 #--------------------- end of file ---------------------