├── .gitignore ├── CHANGES ├── COPYING ├── COPYING.BSD ├── COPYING.GPL ├── Host.cc ├── Host.h ├── Makefile ├── README ├── README.dragonflybsd ├── README.freebsd ├── README.gnu ├── README.irix ├── README.linux ├── README.netbsd ├── README.openbsd ├── TODO ├── Xdefaults ├── Xdefaults.stipple ├── Xrm.cc ├── Xrm.h ├── Xrmcommandline.h ├── bitfieldmeter.cc ├── bitfieldmeter.h ├── bitmeter.cc ├── bitmeter.h ├── bsd ├── MeterMaker.cc ├── MeterMaker.h ├── btrymeter.cc ├── btrymeter.h ├── coretemp.cc ├── coretemp.h ├── cpumeter.cc ├── cpumeter.h ├── defines.h ├── diskmeter.cc ├── diskmeter.h ├── intmeter.cc ├── intmeter.h ├── intratemeter.cc ├── intratemeter.h ├── kernel.cc ├── kernel.h ├── loadmeter.cc ├── loadmeter.h ├── memmeter.cc ├── memmeter.h ├── netmeter.cc ├── netmeter.h ├── pagemeter.cc ├── pagemeter.h ├── sensor.cc ├── sensor.h ├── swapmeter.cc └── swapmeter.h ├── defresources.awk ├── fieldmeter.cc ├── fieldmeter.h ├── fieldmeterdecay.cc ├── fieldmeterdecay.h ├── fieldmetergraph.cc ├── fieldmetergraph.h ├── gnu ├── MeterMaker.cc ├── MeterMaker.h ├── get_def_pager.c ├── get_def_pager.h ├── loadmeter.cc ├── loadmeter.h ├── memmeter.cc ├── memmeter.h ├── pagemeter.cc ├── pagemeter.h ├── swapmeter.cc └── swapmeter.h ├── hpux ├── MeterMaker.cc ├── MeterMaker.h ├── cpumeter.cc ├── cpumeter.h ├── loadmeter.cc ├── loadmeter.h ├── memmeter.cc ├── memmeter.h ├── pagemeter.cc ├── pagemeter.h ├── swapmeter.cc └── swapmeter.h ├── irix65 ├── MeterMaker.cc ├── MeterMaker.h ├── cpumeter.cc ├── cpumeter.h ├── diskmeter.cc ├── diskmeter.h ├── gfxmeter.cc ├── gfxmeter.h ├── loadmeter.cc ├── loadmeter.h ├── memmeter.cc ├── memmeter.h ├── sarmeter.cc └── sarmeter.h ├── linux ├── MeterMaker.cc ├── MeterMaker.h ├── acpitemp.cc ├── acpitemp.h ├── btrymeter.cc ├── btrymeter.h ├── coretemp.cc ├── coretemp.h ├── cpumeter.cc ├── cpumeter.h ├── diskmeter.cc ├── diskmeter.h ├── intmeter.cc ├── intmeter.h ├── intratemeter.cc ├── intratemeter.h ├── lmstemp.cc ├── lmstemp.h ├── loadmeter.cc ├── loadmeter.h ├── memmeter.cc ├── memmeter.h ├── netmeter.cc ├── netmeter.h ├── nfsmeter.cc ├── nfsmeter.h ├── pagemeter.cc ├── pagemeter.h ├── raidmeter.cc ├── raidmeter.h ├── serialmeter.cc ├── serialmeter.h ├── swapmeter.cc ├── swapmeter.h ├── wirelessmeter.cc └── wirelessmeter.h ├── llist.cc ├── llist.h ├── main.cc ├── meter.cc ├── meter.h ├── mkdist ├── pllist.h ├── sensorfieldmeter.cc ├── sensorfieldmeter.h ├── stringutils.cc ├── stringutils.h ├── sunos5 ├── MeterMaker.cc ├── MeterMaker.h ├── cpumeter.cc ├── cpumeter.h ├── diskmeter.cc ├── diskmeter.h ├── intratemeter.cc ├── intratemeter.h ├── kstats.h ├── loadmeter.cc ├── loadmeter.h ├── memmeter.cc ├── memmeter.h ├── netmeter.cc ├── netmeter.h ├── pagemeter.cc ├── pagemeter.h ├── swapmeter.cc └── swapmeter.h ├── targets ├── dragonflybsd ├── freebsd ├── netbsd └── openbsd ├── timer.h ├── timeval.h ├── xosview.1 ├── xosview.cc ├── xosview.desktop ├── xosview.h ├── xosview.png ├── xwin.cc └── xwin.h /.gitignore: -------------------------------------------------------------------------------- 1 | .config 2 | xosview 3 | *.d 4 | *.o 5 | dist 6 | 7 | ## Auto-generated stuff: 8 | defaultstring.cc 9 | Xdefaults 10 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | The majority of the xosview source code is covered by the GNU 2 | General Public License (GPL), which is presented in the file 3 | COPYING.GPL. 4 | 5 | In addition, a portion of the NetBSD port's code is covered under 6 | the traditional BSD copyright, which is presented in COPYING.BSD. If you 7 | plan on modifying or distributing any portion of this code, make sure 8 | that you agree to the terms in the BSD copyright (which in general is 9 | less restrictive than the GPL, from what I've seen, but I'm not a 10 | lawyer-type). These files are: 11 | netbsd/swapinternal.cc 12 | 13 | Lastly, various portions of the xosview source code were developed 14 | by various authors who have intentionally chosen to allow the user 15 | to choose between the BSD copyright or the GPL copyright. These files 16 | are: 17 | fieldmeterdecay.h 18 | fieldmeterdecay.cc 19 | general.h 20 | netbsd/MeterMaker.h 21 | netbsd/MeterMaker.cc 22 | netbsd/cpumeter.h 23 | netbsd/cpumeter.cc 24 | netbsd/diskmeter.h 25 | netbsd/diskmeter.cc 26 | netbsd/loadmeter.h 27 | netbsd/loadmeter.cc 28 | netbsd/memmeter.h 29 | netbsd/memmeter.cc 30 | netbsd/netbsd.h 31 | netbsd/netbsd.cc 32 | netbsd/netmeter.h 33 | netbsd/netmeter.cc 34 | netbsd/swapmeter.h 35 | netbsd/swapmeter.cc 36 | 37 | Brian Grayson, Feb. 1997 38 | -------------------------------------------------------------------------------- /COPYING.BSD: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990 The Regents of the University of California. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the University of 16 | * California, Berkeley and its contributors. 17 | * 4. Neither the name of the University nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | */ 34 | -------------------------------------------------------------------------------- /Host.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _Host_h 8 | #define _Host_h 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | class Host { 18 | public: 19 | Host(const char *hostname); 20 | Host(const struct in_addr *address); 21 | Host(unsigned int addr); 22 | Host(const Host& host) { copy(host); _failure = host._failure; } 23 | virtual ~Host(void); 24 | 25 | Host &operator=(const Host& host) { 26 | clear(); 27 | copy(host); 28 | _failure = host._failure; 29 | 30 | return *this; 31 | } 32 | 33 | bool operator==(const Host& host) const; 34 | bool operator!=(const Host& host) const { return !(*this == host); } 35 | 36 | // indicates a valid Host. 37 | bool valid(void) const { return _valid; } 38 | operator bool(void) const { return _valid; } 39 | int reasonForFailure(void) const; // returns h_errno at time of failure 40 | bool tryAgain(void) const; // Ok to try again? 41 | 42 | const char *officialName(void) const { return _hent.h_name; } 43 | 44 | int numAliases(void) const { return _numAliases; } 45 | const char *alias(int num) const { return _hent.h_aliases[num]; } 46 | 47 | int addrType(void) const { return _hent.h_addrtype; } 48 | int addrLength(void) const { return _hent.h_length; } 49 | 50 | int numAddresses(void) const { return _numAddresses; } 51 | struct in_addr *address(int num) const { 52 | return (in_addr *)_hent.h_addr_list[num]; 53 | } 54 | 55 | // Linux will choke and die inside of inet_ntoa() when 56 | // this function is called. The Host class has been run 57 | // through purify and the problem is not in it. Must be 58 | // another linux library problem :(. 59 | const char *strAddress(int num) const { return inet_ntoa(*address(num)); } 60 | 61 | // Should not use this under linux for the same reashon as the above 62 | // function. 63 | std::ostream &print(std::ostream &os) const; 64 | 65 | protected: 66 | private: 67 | struct hostent _hent; 68 | int _numAliases; 69 | int _numAddresses; 70 | bool _valid; 71 | int _failure; 72 | 73 | void copy(const Host& host) { copy(&host._hent); } 74 | void copy(const struct hostent *hent); 75 | void clear(void); 76 | bool check(const struct hostent *hent); 77 | bool constuct(const struct in_addr *address); 78 | }; 79 | 80 | // Do not use this under linux until inet_ntoa() is fixed. 81 | inline std::ostream &operator<<(std::ostream &os, const Host& host) { 82 | return host.print(os); 83 | } 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This version of xosview is distributed from the following sites: 2 | 3 | http://www.pogo.org.uk/~mark/xosview/ 4 | https://github.com/hills/xosview 5 | 6 | The build no longer uses GNU autoconfig. Control is via Makefile 7 | variables. In general, you should be able to build on Linux using: 8 | 9 | $ make 10 | $ make install 11 | 12 | To change the target prefix, use, for example: 13 | 14 | $ make install PREFIX=/usr 15 | 16 | For more fine-grained control, see the Makefile for available 17 | variables. 18 | 19 | To specify a particular platform, use one of: 20 | 21 | $ make PLATFORM=linux 22 | $ make PLATFORM=bsd 23 | $ make PLATFORM=irix65 24 | $ make PLATFORM=sunos5 25 | $ make PLATFORM=gnu 26 | 27 | Please see the README file for your platform for any special 28 | instructions for running xosview on that platform. 29 | 30 | The Makefile picks up additional variables from a .config file in the 31 | source code directory. You may prefer to use this if you are doing 32 | several builds for testing and debugging. 33 | 34 | Some platform variants require specific build flags; see the 'targets' 35 | directory for preset .config files. 36 | 37 | See the man page for information on the xosview display and how to 38 | customize it. 39 | 40 | See the COPYING file for licensing terms. 41 | -------------------------------------------------------------------------------- /README.dragonflybsd: -------------------------------------------------------------------------------- 1 | Support for DragonflyBSD added by Tomi Tapper (tomi.o.tapper@jyu.fi). Tested 2 | on DragonflyBSD version 3.0, but may work on other versions (earlier or later) 3 | as well. Please test and report if possible. 4 | 5 | For building xosview by hand, add these lines into .config. 6 | 7 | CPPFLAGS += -I/usr/pkg/include 8 | LDLIBS += -lkvm -lkinfo -ldevstat -L/usr/pkg/lib 9 | 10 | 11 | ***************************************************************************** 12 | Note: xosview needs to run 'setgid kmem' in order to access some of the 13 | kernel information (at least until some more statistics are added to 14 | the /kern or /proc file systems). If you do not have root or kmem 15 | permission on the machine, xosview will not run. 16 | ***************************************************************************** 17 | -------------------------------------------------------------------------------- /README.freebsd: -------------------------------------------------------------------------------- 1 | The FreeBSD port now has much better support, thanks to Tom 2 | Pavel. From within the ports system, xosview ought to build out 3 | of the box --- if not, it's a bug. 4 | 5 | This version of xosview no longer supports FreeBSD versions below 7.0. Users 6 | of older versions need xosview version below 1.9. 7 | 8 | For building xosview by hand, add these lines into .config. 9 | 10 | CPPFLAGS += -I/usr/local/include 11 | LDLIBS += -lkvm -ldevstat -L/usr/local/lib 12 | 13 | 14 | ***************************************************************************** 15 | Note: xosview needs to run 'setgid kmem' in order to access some of the 16 | kernel information (at least until some more statistics are added to 17 | the /kern or /proc file systems). If you do not have root or kmem 18 | permission on the machine, xosview will not run. 19 | ***************************************************************************** 20 | -------------------------------------------------------------------------------- /README.gnu: -------------------------------------------------------------------------------- 1 | Support for GNU/Hurd added by Samuel Thibault (samuel.thibault@ens-lyon.org). 2 | 3 | -------------------------------------------------------------------------------- /README.irix: -------------------------------------------------------------------------------- 1 | 2 | The IRIX port supports: 3 | 4 | - load meter 5 | 6 | - cpu meter: The cpu meter has a new X resource cpuFormat, with the 7 | possible values of single, all, auto or both. It 8 | determines how cpu meters are handled for 9 | multiprocessors: single displays only meters for each 10 | cpu, all displays only a cumulative meter for all cpus, 11 | both displays both and auto behaves like both on mp 12 | machines and single on up machines. 13 | 14 | - mem meter 15 | 16 | - gfx meter: Displays swapbuffers/second. 17 | 18 | Of course, you're welcome to send me patches. 19 | 20 | For the gfx meter, sadc is forked to read the activity. The sadc 21 | process is handled from the singleton SarMeter, which reads the binary 22 | data from sadc and converts it into structures. Currently, it parses 23 | gfxinfo and diskinfo data. The diskinfo can be used to create a disk 24 | meter, but I do not have the time currently. As said above, send me 25 | patches ;). 26 | 27 | 28 | It is tested on: 29 | 30 | IP20, IP22, IP27, IP30, IP32 and IP35. 31 | 32 | 33 | Stefan Eilemann, Apr 03 eilemann@gmail.com 34 | 35 | -------------------------------------------------------------------------------- /README.netbsd: -------------------------------------------------------------------------------- 1 | NetBSD version originally written and maintained by Brian Grayson 2 | (bgrayson@netbsd.org). Brought up-to-date with NetBSD 5 by Tomi Tapper 3 | (tomi.o.tapper@jyu.fi). 4 | 5 | This version of xosview no longer supports NetBSD versions below 4.0. Users 6 | of older versions need xosview version below 1.9. 7 | 8 | For building xosview by hand, add these lines into .config. 9 | 10 | CPPFLAGS += -I/usr/X11R7/include 11 | LDLIBS += -lkvm -lprop -L/usr/X11R7/lib -Wl,--rpath=/usr/X11R7/lib 12 | 13 | 14 | ***************************************************************************** 15 | Note: xosview needs to run 'setgid kmem' in order to access some of the 16 | kernel information (at least until some more statistics are added to 17 | the /kern or /proc file systems). If you do not have root or kmem 18 | permission on the machine, xosview will not run. 19 | ***************************************************************************** 20 | -------------------------------------------------------------------------------- /README.openbsd: -------------------------------------------------------------------------------- 1 | OpenBSD version originally written and maintained by Brian Grayson 2 | (bgrayson@netbsd.org). Brought up-to-date with OpenBSD 5 by Tomi Tapper 3 | (tomi.o.tapper@jyu.fi). This version has been made on OpenBSD version 5.1. 4 | It may work on other versions (earlier or later) as well. Please test and 5 | report if possible. 6 | 7 | For building xosview by hand, add these lines into .config. 8 | 9 | CPPFLAGS += -I/usr/X11R6/include 10 | LDLIBS += -lkvm -L/usr/X11R6/lib 11 | 12 | 13 | ***************************************************************************** 14 | Note: xosview needs to run 'setgid kmem' in order to access some of the 15 | kernel information (at least until some more statistics are added to 16 | the /kern or /proc file systems). If you do not have root or kmem 17 | permission on the machine, xosview will not run. 18 | ***************************************************************************** 19 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - Get rid of -Wno-deprecated and fix the C++ headers to use 2 | the new convention. 3 | 4 | Linux: Add support for some of the stats generated by the lm78 kernel 5 | module. Fist, I need to get it (lm78) working well on one of my 6 | systems. 7 | 8 | NetBSD: Add interrupt-rate meter, add tape-drive meter (or 9 | arbitrary device throughput meter?) 10 | 11 | * Optimise graphing meter to use XCopyArea (or similar) and expose 12 | events to reduce X traffic. 13 | 14 | * Make xosview re-check resources when the resources are changed, 15 | or when a signal is sent to it, or a key is pressed in it? 16 | 17 | * Add command-line on/off switches for most, if not all, meters. 18 | Fix MeterMaker in the other (non-NetBSD) ports to check for all meters, 19 | not just load and serial. 20 | 21 | * Add command-line arg for specifying an instance name, so that we can 22 | say "xosview -name xosview-stipple" and have the xosview-stipple* 23 | resources read in also. 24 | Redo the fieldmeter drawing code -- it (and the decayfieldmeter 25 | code) is very ugly. 26 | 27 | * Add in stipple support for those stuck with 1-bit displays (black, 28 | or white) (just MacBSD people?). 29 | 30 | * Make a better resource for turning meters off/on. Currently, we 31 | overload other resources. 32 | 33 | * If all meters are disabled, either via resources or command-line 34 | options, xosview dies from float-exception. Probably, we're 35 | dividing by the number of meters somewhere. Fix this. 36 | 37 | NetBSD: Clean up symbol defs in netbsd.cc 38 | NetBSD: Merge swapinternal.cc (or at least a lot of it) into kernel.cc 39 | NetBSD, Linux, hp: Instead of allowing each meter to figure out the 40 | per-sec rate for a measurement (page, disk, net), add a fieldmeter 41 | function that does the calculation, using SAMPLE_MSECS and 42 | priority_. See the netbsd/diskmeter.cc code for what I think is the 43 | correct formula (it took me a few attempts to get it right!) 44 | Fix depend stuff 45 | * Get autolookup of X stuff -- perhaps use xmkmf/imake in configure? 46 | 47 | Change the CacheColor stuff from Tom Pavel's patches to be a 48 | new memWiredColor. 49 | 50 | * Change the names on all NetBSD* functions to just be BSD*, 51 | since they are shared across multiple *BSD ports. 52 | 53 | * Merge in NetBSD interrupt support. 54 | 55 | * Add auto-detect for number of interrupts for NetBSD. 56 | 57 | x Add in support and auto-detect for new NetBSD UVM stuff. 58 | (added, but no auto-detect). 59 | 60 | Merge in Tom's Xt stuff. -- deferred: it appears to require 61 | Xt, Xaw, and ICE, IIRC, which bloats static executables too 62 | much for my taste. bgrayson 63 | 64 | * The Netmeter under *BSD has wrap problems: the internal 65 | counter in the kernel is 32 bits, so once we receive 4G of 66 | traffic, we wrap, and it looks like we received a lot of 67 | negative traffic? (I _think_ this is the cause). 68 | -------------------------------------------------------------------------------- /Xdefaults.stipple: -------------------------------------------------------------------------------- 1 | # See the README.netbsd file on how to use the stipple options and 2 | # these example resources. 3 | 4 | xosvstipple*enableStipple: True 5 | xosvstipple*loadWarnColor: red 6 | xosvstipple*loadProcColor: red 7 | xosvstipple*loadIdleColor: red 8 | xosvstipple*cpuUserColor: red 9 | xosvstipple*cpuNiceColor: red 10 | xosvstipple*cpuSystemColor: red 11 | xosvstipple*cpuInterruptColor: red 12 | xosvstipple*cpuSInterruptColor: red 13 | xosvstipple*cpuFreeColor: red 14 | xosvstipple*cpuGuestColor: red 15 | xosvstipple*cpuStolenColor: red 16 | xosvstipple*memUsedColor: orange 17 | xosvstipple*memSharedColor: orange 18 | xosvstipple*memBufferColor: orange 19 | xosvstipple*memSlabColor: orange 20 | xosvstipple*memPTColor: orange 21 | xosvstipple*memCacheColor: orange 22 | xosvstipple*memFreeColor: orange 23 | xosvstipple*memTextColor: orange 24 | xosvstipple*memOtherColor: orange 25 | xosvstipple*memActiveColor: orange 26 | xosvstipple*memInactiveColor: orange 27 | xosvstipple*swapUsedColor: yellow 28 | xosvstipple*swapFreeColor: yellow 29 | xosvstipple*netInColor: green 30 | xosvstipple*netOutColor: green 31 | xosvstipple*netBackground: green 32 | xosvstipple*serialOnColor: red 33 | xosvstipple*serialOffColor: aquamarine 34 | xosvstipple*intOnColor: red 35 | xosvstipple*intOffColor: aquamarine 36 | xosvstipple*diskUsedColor: blue 37 | xosvstipple*diskIdleColor: blue 38 | xosvstipple*pageInColor: purple 39 | xosvstipple*pageOutColor: purple 40 | xosvstipple*pageIdleColor: purple 41 | 42 | xosvstipplebw*meterLabelColor: black 43 | xosvstipplebw*usedLabelColor: black 44 | xosvstipplebw*background: white 45 | xosvstipplebw*foreground: black 46 | xosvstipplebw*enableStipple: True 47 | xosvstipplebw*loadWarnColor: black 48 | xosvstipplebw*loadProcColor: black 49 | xosvstipplebw*loadIdleColor: black 50 | xosvstipplebw*cpuUserColor: black 51 | xosvstipplebw*cpuNiceColor: black 52 | xosvstipplebw*cpuSystemColor: black 53 | xosvstipplebw*cpuInterruptColor:black 54 | xosvstipplebw*cpuSInterruptColor:black 55 | xosvstipplebw*cpuFreeColor: black 56 | xosvstipplebw*cpuGuestColor: black 57 | xosvstipplebw*cpuStolenColor: black 58 | xosvstipplebw*memUsedColor: black 59 | xosvstipplebw*memSharedColor: black 60 | xosvstipplebw*memBufferColor: black 61 | xosvstipplebw*memSlabColor: black 62 | xosvstipplebw*memPTColor: black 63 | xosvstipplebw*memCacheColor: black 64 | xosvstipplebw*memFreeColor: black 65 | xosvstipplebw*memTextColor: black 66 | xosvstipplebw*memOtherColor: black 67 | xosvstipplebw*memActiveColor: black 68 | xosvstipplebw*memInactiveColor: black 69 | xosvstipplebw*swapUsedColor: black 70 | xosvstipplebw*swapFreeColor: black 71 | xosvstipplebw*netInColor: black 72 | xosvstipplebw*netOutColor: black 73 | xosvstipplebw*netBackground: black 74 | xosvstipplebw*serialOnColor: black 75 | xosvstipplebw*serialOffColor: white 76 | xosvstipplebw*intOnColor: black 77 | xosvstipplebw*intOffColor: white 78 | xosvstipplebw*diskUsedColor: black 79 | xosvstipplebw*diskIdleColor: black 80 | xosvstipplebw*pageInColor: black 81 | xosvstipplebw*pageOutColor: black 82 | xosvstipplebw*pageIdleColor: black 83 | 84 | -------------------------------------------------------------------------------- /Xrm.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _Xrm_h 8 | #define _Xrm_h 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | class Xrm { 16 | public: 17 | Xrm(const char *className, const char *instanceName); 18 | Xrm(const char *instanceName, int argc, char **argv); 19 | ~Xrm(); 20 | 21 | const char *className(void) const { return XrmQuarkToString(_class); } 22 | const char *instanceName(void) const { return XrmQuarkToString(_instance); } 23 | 24 | const char *getResource(const char *rname) const; 25 | const char* getDisplayName (int argc, char** argv); 26 | void loadAndMergeResources(int& argc, char** argv, Display* display); 27 | 28 | std::ostream &dump(std::ostream &os) const; 29 | 30 | private: 31 | XrmDatabase _db; 32 | XrmClass _class, _instance; 33 | const char* _display_name; // Used solely for getting the display's resources. 34 | 35 | //void getArgs(int argc, char **argv); 36 | static Bool enumCB(XrmDatabase *, XrmBindingList bindings, 37 | XrmQuarkList quarks, XrmRepresentation *type, 38 | XrmValue *value, XPointer closure); 39 | void initClassName(const char* className); 40 | 41 | static bool _initialized; 42 | }; 43 | 44 | inline std::ostream &operator<<(std::ostream &os, const Xrm &xrm){ 45 | return xrm.dump(os); 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /bitfieldmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1999, 2006 Thomas Waldmann (ThomasWaldmann@gmx.de) 3 | // based on work of Mike Romberg ( mike.romberg@noaa.gov ) 4 | // 5 | // This file may be distributed under terms of the GPL 6 | // 7 | // 8 | #ifndef _BITFIELDMETER_H_ 9 | #define _BITFIELDMETER_H_ 10 | 11 | #include "meter.h" 12 | #include "xosview.h" 13 | #include "timer.h" 14 | 15 | 16 | class BitFieldMeter : public Meter { 17 | public: 18 | BitFieldMeter( XOSView *parent, int numBits = 1, int numfields = 1, 19 | const char *title = "", 20 | const char *bitlegend = "", const char *fieldlegend = "", 21 | int docaptions = 0, int dolegends = 0, int dousedlegends = 0 ); 22 | virtual ~BitFieldMeter( void ); 23 | 24 | virtual void drawfields( int mandatory = 0 ); 25 | void drawBits( int mandatory = 0 ); 26 | 27 | void setfieldcolor( int field, const char *color ); 28 | void setfieldcolor( int field, unsigned long color); 29 | void docaptions( int val ) { docaptions_ = val; } 30 | void dolegends( int val ) { dolegends_ = val; } 31 | void dousedlegends( int val ) { dousedlegends_ = val; } 32 | void reset( void ); 33 | 34 | void setUsed (double val, double total); 35 | void setBits(int startbit, unsigned char values); 36 | 37 | void draw( void ); 38 | void checkevent( void ); 39 | void disableMeter ( void ); 40 | 41 | virtual void checkResources( void ); 42 | 43 | protected: 44 | enum UsedType { INVALID_0, FLOAT, PERCENT, AUTOSCALE, INVALID_TAIL }; 45 | 46 | int numfields_; 47 | double *fields_; 48 | double total_, used_, lastused_; 49 | int *lastvals_, *lastx_; 50 | unsigned long *colors_; 51 | unsigned long usedcolor_; 52 | UsedType print_; 53 | int printedZeroTotalMesg_; 54 | int numWarnings_; 55 | bool metric_; 56 | int usedoffset_; 57 | 58 | unsigned long onColor_, offColor_; 59 | char *bits_, *lastbits_; 60 | int numbits_; 61 | 62 | void SetUsedFormat ( const char * const str ); 63 | void drawfieldlegend( void ); 64 | void drawused( int mandatory ); 65 | bool checkX(int x, int width) const; 66 | 67 | void setNumFields(int n); 68 | void setNumBits(int n); 69 | char *fieldLegend_; 70 | 71 | void setfieldlegend(const char *fieldlegend); 72 | 73 | private: 74 | Timer _timer; 75 | protected: 76 | void IntervalTimerStart() { _timer.start(); } 77 | void IntervalTimerStop() { _timer.stop(); } 78 | // Before, we simply called _timer.report(), which returns usecs. 79 | // However, it suffers from wrap/overflow/sign-bit problems, so 80 | // instead we use doubles for everything. 81 | double IntervalTimeInMicrosecs() { return _timer.report_usecs(); } 82 | double IntervalTimeInSecs() { return _timer.report_usecs()/1e6; } 83 | }; 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /bitmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #include "bitmeter.h" 8 | 9 | 10 | BitMeter::BitMeter( XOSView *parent, 11 | const char *title, const char *legend, int numBits, 12 | int docaptions, int, int dousedlegends) 13 | : Meter( parent, title, legend, docaptions, dousedlegends, dousedlegends ), 14 | bits_(NULL), lastbits_(NULL), disabled_(false) { 15 | setNumBits(numBits); 16 | } 17 | 18 | BitMeter::~BitMeter( void ){ 19 | delete [] bits_; 20 | delete [] lastbits_; 21 | } 22 | 23 | void BitMeter::setNumBits(int n){ 24 | numbits_ = n; 25 | delete [] bits_; 26 | delete [] lastbits_; 27 | 28 | bits_ = new char[numbits_]; 29 | lastbits_ = new char[numbits_]; 30 | 31 | for ( int i = 0 ; i < numbits_ ; i++ ) 32 | bits_[i] = lastbits_[i] = 0; 33 | } 34 | 35 | void BitMeter::disableMeter ( void ) { 36 | disabled_ = true; 37 | onColor_ = parent_->allocColor ("gray"); 38 | offColor_ = onColor_; 39 | Meter::legend ("Disabled"); 40 | 41 | } 42 | 43 | void BitMeter::checkResources( void ){ 44 | Meter::checkResources(); 45 | } 46 | 47 | void BitMeter::checkevent( void ){ 48 | drawBits(); 49 | } 50 | 51 | void BitMeter::drawBits( int mandatory ){ 52 | static int pass = 1; 53 | 54 | // pass = (pass + 1) % 2; 55 | 56 | int x1 = x_ + 0, x2; 57 | 58 | for ( int i = 0 ; i < numbits_ ; i++ ){ 59 | if ( i != (numbits_ - 1) ) 60 | x2 = x_ + ((i + 1) * (width_+1)) / numbits_ - 1; 61 | else 62 | x2 = x_ + (width_+1) - 1; 63 | 64 | if ( (bits_[i] != lastbits_[i]) || mandatory ){ 65 | if ( bits_[i] && pass ) 66 | parent_->setForeground( onColor_ ); 67 | else 68 | parent_->setForeground( offColor_ ); 69 | 70 | parent_->drawFilledRectangle( x1, y_, x2 - x1, height_); 71 | } 72 | 73 | lastbits_[i] = bits_[i]; 74 | 75 | x1 = x2 + 2; 76 | } 77 | } 78 | 79 | void BitMeter::draw( void ){ 80 | parent_->lineWidth( 1 ); 81 | parent_->setForeground( parent_->foreground() ); 82 | parent_->drawFilledRectangle( x_ -1, y_ - 1, width_ + 2, height_ + 2 ); 83 | 84 | parent_->lineWidth( 0 ); 85 | 86 | if ( dolegends_ ){ 87 | parent_->setForeground( textcolor_ ); 88 | 89 | int offset; 90 | if ( dousedlegends_ ) 91 | offset = parent_->textWidth( "XXXXXXXXXX" ); 92 | else 93 | offset = parent_->textWidth( "XXXXXX" ); 94 | 95 | parent_->drawString( x_ - offset + 1, y_ + height_, title_ ); 96 | parent_->setForeground( onColor_ ); 97 | if(docaptions_) 98 | { 99 | parent_->drawString( x_, y_ - 5, legend_ ); 100 | } 101 | } 102 | 103 | drawBits( 1 ); 104 | } 105 | 106 | void BitMeter::setBits(int startbit, unsigned char values){ 107 | unsigned char mask = 1; 108 | for (int i = startbit ; i < startbit + 8 ; i++){ 109 | bits_[i] = values & mask; 110 | mask = mask << 1; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /bitmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _BITMETER_H_ 8 | #define _BITMETER_H_ 9 | 10 | #include "meter.h" 11 | #include "xosview.h" 12 | 13 | 14 | class BitMeter : public Meter { 15 | public: 16 | BitMeter( XOSView *parent, 17 | const char *title = "", const char *legend ="", 18 | int numBits = 1, int docaptions = 0, int dolegends = 0, int dousedlegends = 0 ); 19 | virtual ~BitMeter( void ); 20 | 21 | void checkevent( void ); 22 | void draw( void ); 23 | void disableMeter ( void ); 24 | 25 | int numBits(void) const { return numbits_; } 26 | void setNumBits(int n); 27 | 28 | void checkResources( void ); 29 | protected: 30 | unsigned long onColor_, offColor_; 31 | char *bits_, *lastbits_; 32 | int numbits_; 33 | bool disabled_; 34 | 35 | void setBits(int startbit, unsigned char values); 36 | 37 | void drawBits( int mandatory = 0 ); 38 | private: 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /bsd/MeterMaker.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 4 | // 5 | // This file was written by Brian Grayson for the NetBSD and xosview 6 | // projects. 7 | // This file may be distributed under terms of the GPL or of the BSD 8 | // license, whichever you choose. The full license notices are 9 | // contained in the files COPYING.GPL and COPYING.BSD, which you 10 | // should have received. If not, contact one of the xosview 11 | // authors for a copy. 12 | // 13 | 14 | #ifndef _MeterMaker_h 15 | #define _MeterMaker_h 16 | 17 | #include "pllist.h" 18 | #include "meter.h" 19 | #include "xosview.h" 20 | 21 | 22 | class MeterMaker : public PLList { 23 | public: 24 | MeterMaker(XOSView *xos); 25 | void makeMeters(void); 26 | 27 | private: 28 | XOSView *_xos; 29 | }; 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /bsd/btrymeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 by Tomi Tapper ( tomi.o.tapper@student.jyu.fi ) 3 | // 4 | // Based on linux/btrymeter.cc: 5 | // Copyright (c) 1997, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 6 | // 7 | // This file may be distributed under terms of the GPL 8 | // 9 | 10 | #include "btrymeter.h" 11 | #include "kernel.h" 12 | #include 13 | 14 | 15 | BtryMeter::BtryMeter( XOSView *parent ) 16 | : FieldMeter( parent, 2, "BTRY", "CHRG/USED", 1, 1, 0 ) { 17 | old_state_ = 255; 18 | } 19 | 20 | BtryMeter::~BtryMeter( void ) { 21 | } 22 | 23 | void BtryMeter::checkResources( void ) { 24 | FieldMeter::checkResources(); 25 | 26 | leftcolor_ = parent_->allocColor( parent_->getResource("batteryLeftColor") ); 27 | usedcolor_ = parent_->allocColor( parent_->getResource("batteryUsedColor") ); 28 | chargecolor_ = parent_->allocColor( parent_->getResource("batteryChargeColor") ); 29 | fullcolor_ = parent_->allocColor( parent_->getResource("batteryFullColor") ); 30 | lowcolor_ = parent_->allocColor( parent_->getResource("batteryLowColor") ); 31 | critcolor_ = parent_->allocColor( parent_->getResource("batteryCritColor") ); 32 | nonecolor_ = parent_->allocColor( parent_->getResource("batteryNoneColor") ); 33 | 34 | setfieldcolor(0, leftcolor_); 35 | setfieldcolor(1, usedcolor_); 36 | 37 | priority_ = atoi( parent_->getResource("batteryPriority") ); 38 | SetUsedFormat( parent_->getResource("batteryUsedFormat") ); 39 | } 40 | 41 | void BtryMeter::checkevent( void ) { 42 | getstats(); 43 | drawfields(); 44 | } 45 | 46 | void BtryMeter::getstats( void ) { 47 | int remaining; 48 | unsigned int state; 49 | 50 | BSDGetBatteryInfo(&remaining, &state); 51 | 52 | if (state != old_state_) { 53 | if (state == XOSVIEW_BATT_NONE) { // no battery present 54 | setfieldcolor(0, nonecolor_); 55 | legend("NONE/NONE"); 56 | } 57 | else if (state & XOSVIEW_BATT_FULL) { // full battery 58 | setfieldcolor(0, fullcolor_); 59 | legend("CHRG/FULL"); 60 | } 61 | else { // present, not full 62 | if (state & XOSVIEW_BATT_CRITICAL) // critical charge 63 | setfieldcolor(0, critcolor_); 64 | else if (state & XOSVIEW_BATT_LOW) // low charge 65 | setfieldcolor(0, lowcolor_); 66 | else { // above low, below full 67 | if (state & XOSVIEW_BATT_CHARGING) // is charging 68 | setfieldcolor(0, chargecolor_); 69 | else 70 | setfieldcolor(0, leftcolor_); 71 | } 72 | // legend tells if charging or discharging 73 | if (state & XOSVIEW_BATT_CHARGING) 74 | legend("CHRG/AC"); 75 | else 76 | legend("CHRG/USED"); 77 | } 78 | drawlegend(); 79 | parent_->draw(); // make sure the field changes colour too 80 | old_state_ = state; 81 | } 82 | 83 | total_ = 100.0; 84 | fields_[0] = remaining; 85 | fields_[1] = total_ - remaining; 86 | setUsed(fields_[0], total_); 87 | } 88 | -------------------------------------------------------------------------------- /bsd/btrymeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 by Tomi Tapper ( tomi.o.tapper@student.jyu.fi ) 3 | // 4 | // Based on linux/btrymeter.h: 5 | // Copyright (c) 1997, 2005, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 6 | // 7 | // This file may be distributed under terms of the GPL 8 | // 9 | 10 | #ifndef _BTRYMETER_H_ 11 | #define _BTRYMETER_H_ 12 | 13 | #include "fieldmeter.h" 14 | #include "xosview.h" 15 | 16 | 17 | class BtryMeter : public FieldMeter { 18 | public: 19 | BtryMeter( XOSView *parent ); 20 | ~BtryMeter( void ); 21 | 22 | const char *name( void ) const { return "BtryMeter"; } 23 | void checkevent( void ); 24 | void checkResources( void ); 25 | 26 | protected: 27 | void getstats( void ); 28 | 29 | private: 30 | unsigned long leftcolor_, usedcolor_, chargecolor_, fullcolor_, 31 | lowcolor_, critcolor_, nonecolor_; 32 | unsigned int old_state_; 33 | }; 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /bsd/coretemp.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2008 by Tomi Tapper 3 | // 4 | // Read coretemp reading with sysctl and display actual temperature. 5 | // If actual >= high, actual temp changes color to indicate alarm. 6 | // 7 | // File based on linux/lmstemp.* by 8 | // Copyright (c) 2000, 2006 by Leopold Toetsch 9 | // 10 | // This file may be distributed under terms of the GPL 11 | // 12 | // 13 | // 14 | 15 | #include "coretemp.h" 16 | #include "kernel.h" 17 | #include 18 | #include 19 | #include 20 | 21 | 22 | CoreTemp::CoreTemp( XOSView *parent, const char *label, const char *caption, int cpu) 23 | : FieldMeter( parent, 3, label, caption, 1, 1, 1 ) { 24 | metric_ = true; 25 | cpu_ = cpu; 26 | cpucount_ = countCpus(); 27 | temps_ = (float *)calloc(cpucount_, sizeof(float)); 28 | } 29 | 30 | CoreTemp::~CoreTemp( void ) { 31 | free(temps_); 32 | } 33 | 34 | void CoreTemp::checkResources( void ) { 35 | FieldMeter::checkResources(); 36 | 37 | actcolor_ = parent_->allocColor( parent_->getResource( "coretempActColor" ) ); 38 | highcolor_ = parent_->allocColor( parent_->getResource( "coretempHighColor" ) ); 39 | setfieldcolor( 0, actcolor_ ); 40 | setfieldcolor( 1, parent_->getResource( "coretempIdleColor") ); 41 | setfieldcolor( 2, highcolor_ ); 42 | 43 | priority_ = atoi( parent_->getResource( "coretempPriority" ) ); 44 | const char *highest = parent_->getResourceOrUseDefault( "coretempHighest", "100" ); 45 | total_ = atoi( highest ); 46 | const char *high = parent_->getResourceOrUseDefault( "coretempHigh", NULL ); 47 | SetUsedFormat( parent_->getResource( "coretempUsedFormat" ) ); 48 | 49 | // Get tjMax here and use as total. 50 | float total = -300.0; 51 | float *tjmax = (float *)calloc(cpucount_, sizeof(float)); 52 | BSDGetCPUTemperature(temps_, tjmax); 53 | for (int i = 0; i < cpucount_; i++) { 54 | if (tjmax[i] > total) 55 | total = tjmax[i]; 56 | } 57 | free(tjmax); 58 | if (total > 0.0) 59 | total_ = total; 60 | 61 | char l[32]; 62 | if (!high) { 63 | high_ = total_; 64 | snprintf(l, 32, "ACT(\260C)/HIGH/%d", (int)total_); 65 | } 66 | else { 67 | high_ = atoi( high ); 68 | snprintf(l, 32, "ACT(\260C)/%d/%d", (int)high_, (int)total_); 69 | } 70 | legend(l); 71 | } 72 | 73 | unsigned int CoreTemp::countCpus( void ) { 74 | return BSDGetCPUTemperature(NULL, NULL); 75 | } 76 | 77 | void CoreTemp::checkevent( void ) { 78 | getcoretemp(); 79 | drawfields(); 80 | } 81 | 82 | void CoreTemp::getcoretemp( void ) { 83 | BSDGetCPUTemperature(temps_, NULL); 84 | 85 | fields_[0] = 0.0; 86 | if ( cpu_ >= 0 && cpu_ < cpucount_ ) { // one core 87 | fields_[0] = temps_[cpu_]; 88 | } 89 | else if ( cpu_ == -1 ) { // average 90 | float tempval = 0.0; 91 | for (int i = 0; i < cpucount_; i++) 92 | tempval += temps_[i]; 93 | fields_[0] = tempval / (float)cpucount_; 94 | } 95 | else if ( cpu_ == -2 ) { // maximum 96 | float tempval = -300.0; 97 | for (int i = 0; i < cpucount_; i++) { 98 | if (temps_[i] > tempval) 99 | tempval = temps_[i]; 100 | } 101 | fields_[0] = tempval; 102 | } 103 | else { // should not happen 104 | std::cerr << "Unknown CPU core number in coretemp." << std::endl; 105 | parent_->done(1); 106 | return; 107 | } 108 | 109 | setUsed(fields_[0], total_); 110 | if (fields_[0] < 0) 111 | fields_[0] = 0; 112 | fields_[1] = high_ - fields_[0]; 113 | fields_[2] = total_ - fields_[1] - fields_[0]; 114 | if (fields_[0] > total_) 115 | fields_[0] = total_; 116 | if (fields_[2] < 0) 117 | fields_[2] = 0; 118 | 119 | if (fields_[1] < 0) { // alarm: T > high 120 | fields_[1] = 0; 121 | if (colors_[0] != highcolor_) { 122 | setfieldcolor( 0, highcolor_ ); 123 | drawlegend(); 124 | } 125 | } 126 | else { 127 | if (colors_[0] != actcolor_) { 128 | setfieldcolor( 0, actcolor_ ); 129 | drawlegend(); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /bsd/coretemp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2008 by Tomi Tapper 3 | // 4 | // File based on linux/lmstemp.* by 5 | // Copyright (c) 2000, 2006 by Leopold Toetsch 6 | // 7 | // This file may be distributed under terms of the GPL 8 | // 9 | // 10 | // 11 | #ifndef _CORETEMP_H_ 12 | #define _CORETEMP_H_ 13 | 14 | 15 | #include "fieldmeter.h" 16 | #include "xosview.h" 17 | 18 | 19 | class CoreTemp : public FieldMeter { 20 | public: 21 | CoreTemp( XOSView *parent, const char *label, const char *caption, int cpu); 22 | ~CoreTemp( void ); 23 | 24 | const char *name( void ) const { return "CoreTemp"; } 25 | void checkevent( void ); 26 | void checkResources( void ); 27 | 28 | static unsigned int countCpus( void ); 29 | 30 | protected: 31 | void getcoretemp( void ); 32 | 33 | private: 34 | int cpu_, cpucount_; 35 | float high_, *temps_; 36 | unsigned long actcolor_, highcolor_; 37 | }; 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /bsd/cpumeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // NetBSD port: 5 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 6 | // 7 | // This file was written by Brian Grayson for the NetBSD and xosview 8 | // projects. 9 | // This file may be distributed under terms of the GPL or of the BSD 10 | // license, whichever you choose. The full license notices are 11 | // contained in the files COPYING.GPL and COPYING.BSD, which you 12 | // should have received. If not, contact one of the xosview 13 | // authors for a copy. 14 | // 15 | 16 | #include "cpumeter.h" 17 | #include "kernel.h" 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | CPUMeter::CPUMeter( XOSView *parent, unsigned int nbr ) 24 | : FieldMeterGraph( parent, 5, "CPU", "USR/NICE/SYS/INT/FREE" ) { 25 | nbr_ = nbr; 26 | cpuindex_ = 0; 27 | bzero(cputime_, 10 * sizeof(cputime_[0][0])); 28 | BSDCPUInit(); 29 | 30 | char t[8] = "CPU"; 31 | if (nbr_ > 0) 32 | snprintf(t, 8, "CPU%d", nbr_ - 1); 33 | title(t); 34 | } 35 | 36 | CPUMeter::~CPUMeter( void ) { 37 | } 38 | 39 | void CPUMeter::checkResources( void ) { 40 | FieldMeterGraph::checkResources(); 41 | 42 | setfieldcolor( 0, parent_->getResource("cpuUserColor") ); 43 | setfieldcolor( 1, parent_->getResource("cpuNiceColor") ); 44 | setfieldcolor( 2, parent_->getResource("cpuSystemColor") ); 45 | setfieldcolor( 3, parent_->getResource("cpuInterruptColor") ); 46 | setfieldcolor( 4, parent_->getResource("cpuFreeColor") ); 47 | priority_ = atoi( parent_->getResource("cpuPriority") ); 48 | dodecay_ = parent_->isResourceTrue("cpuDecay"); 49 | useGraph_ = parent_->isResourceTrue("cpuGraph"); 50 | SetUsedFormat( parent_->getResource("cpuUsedFormat") ); 51 | } 52 | 53 | void CPUMeter::checkevent( void ) { 54 | getcputime(); 55 | drawfields(); 56 | } 57 | 58 | void CPUMeter::getcputime( void ) { 59 | uint64_t tempCPU[CPUSTATES]; 60 | total_ = 0; 61 | 62 | BSDGetCPUTimes(tempCPU, nbr_); 63 | 64 | int oldindex = (cpuindex_ + 1) % 2; 65 | for (int i = 0; i < CPUSTATES; i++) { 66 | cputime_[cpuindex_][i] = tempCPU[i]; 67 | fields_[i] = cputime_[cpuindex_][i] - cputime_[oldindex][i]; 68 | total_ += fields_[i]; 69 | } 70 | if (total_) { 71 | setUsed(total_ - fields_[4], total_); 72 | cpuindex_ = (cpuindex_ + 1) % 2; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /bsd/cpumeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // NetBSD port: 5 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 6 | // 7 | // This file was written by Brian Grayson for the NetBSD and xosview 8 | // projects. 9 | // This file may be distributed under terms of the GPL or of the BSD 10 | // license, whichever you choose. The full license notices are 11 | // contained in the files COPYING.GPL and COPYING.BSD, which you 12 | // should have received. If not, contact one of the xosview 13 | // authors for a copy. 14 | // 15 | 16 | #ifndef _CPUMETER_H_ 17 | #define _CPUMETER_H_ 18 | 19 | #include "fieldmetergraph.h" 20 | #include "xosview.h" 21 | #include "defines.h" 22 | 23 | // for CPUSTATES 24 | #if defined(XOSVIEW_NETBSD) || defined(XOSVIEW_OPENBSD) 25 | #include 26 | #else 27 | #include 28 | #endif 29 | 30 | 31 | class CPUMeter : public FieldMeterGraph { 32 | public: 33 | CPUMeter( XOSView *parent, unsigned int nbr ); 34 | ~CPUMeter( void ); 35 | 36 | const char *name( void ) const { return "CPUMeter"; } 37 | void checkevent( void ); 38 | void checkResources( void ); 39 | 40 | protected: 41 | void getcputime( void ); 42 | 43 | private: 44 | uint64_t cputime_[2][CPUSTATES]; 45 | unsigned int cpuindex_, nbr_; 46 | }; 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /bsd/defines.h: -------------------------------------------------------------------------------- 1 | #ifndef __defines_h__ 2 | #define __defines_h__ 3 | 4 | #include 5 | 6 | /* The BSD variant. */ 7 | #if defined __FreeBSD__ 8 | #define XOSVIEW_FREEBSD 9 | #elif defined __NetBSD__ 10 | #define XOSVIEW_NETBSD 11 | #elif defined __OpenBSD__ 12 | #define XOSVIEW_OPENBSD 13 | #elif defined __DragonFly__ 14 | #define XOSVIEW_DFBSD 15 | #endif 16 | 17 | #if !( defined(XOSVIEW_FREEBSD) || \ 18 | defined(XOSVIEW_NETBSD) || \ 19 | defined(XOSVIEW_OPENBSD) || \ 20 | defined(XOSVIEW_DFBSD) ) 21 | #error "Unsupported BSD variant." 22 | #endif 23 | 24 | /* UVM appeared on NetBSD 1.4 and OpenBSD 2.9. */ 25 | #if ( defined(__NetBSD__) && __NetBSD_Version__ >= 104000000 ) || \ 26 | ( defined(__OpenBSD__) && OpenBSD >= 200105 ) 27 | #define HAVE_UVM 1 28 | #endif 29 | 30 | /* swapctl appeared on NetBSD 1.3. and OpenBSD 2.6 */ 31 | #if ( defined(__NetBSD__) && __NetBSD_Version__ >= 103000000 ) || \ 32 | ( defined(__OpenBSD__) && OpenBSD >= 199912 ) 33 | #define HAVE_SWAPCTL 1 34 | #endif 35 | 36 | /* devstat appeared on FreeBSD 3.0. */ 37 | #if ( defined(__FreeBSD__) && __FreeBSD_version >= 300005 ) || \ 38 | defined(__DragonFly__) 39 | #define HAVE_DEVSTAT 1 40 | #endif 41 | 42 | /* kvm_getswapinfo appeared on FreeBSD 4.0 */ 43 | #if ( defined(__FreeBSD__) && __FreeBSD_version >= 400000 ) || \ 44 | defined(__DragonFly__) 45 | #define USE_KVM_GETSWAPINFO 1 46 | #endif 47 | 48 | /* Helper defines for battery meter. */ 49 | #define XOSVIEW_BATT_NONE 0 50 | #define XOSVIEW_BATT_CHARGING 1 51 | #define XOSVIEW_BATT_DISCHARGING 2 52 | #define XOSVIEW_BATT_FULL 4 53 | #define XOSVIEW_BATT_LOW 8 54 | #define XOSVIEW_BATT_CRITICAL 16 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /bsd/diskmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 3 | // 4 | // This file was written by Brian Grayson for the NetBSD and xosview 5 | // projects. 6 | // This file may be distributed under terms of the GPL or of the BSD 7 | // license, whichever you choose. The full license notices are 8 | // contained in the files COPYING.GPL and COPYING.BSD, which you 9 | // should have received. If not, contact one of the xosview 10 | // authors for a copy. 11 | // 12 | 13 | #include "diskmeter.h" 14 | #include "kernel.h" 15 | #include 16 | #include 17 | 18 | 19 | DiskMeter::DiskMeter( XOSView *parent, double max ) 20 | : FieldMeterGraph( parent, 3, "DISK", "READ/WRITE/IDLE" ) { 21 | dodecay_ = 0; 22 | maxBandwidth_ = max; 23 | total_ = max; 24 | if (!BSDDiskInit()) 25 | disableMeter(); 26 | 27 | /* Since at the first call, it will look like we transferred a 28 | * gazillion bytes, let's reset total_ again and do another 29 | * call. This will force total_ to be something reasonable. */ 30 | getstats(); 31 | total_ = max; 32 | getstats(); 33 | IntervalTimerStart(); 34 | /* By doing this check, we eliminate the startup situation where 35 | * all fields are 0, and total is 0, leading to nothing being drawn 36 | * on the meter. So, make it look like nothing was transferred, 37 | * out of a total of 1 bytes. */ 38 | fields_[0] = fields_[1] = 0.0; 39 | total_ = 1.0; 40 | fields_[2] = total_; 41 | } 42 | 43 | DiskMeter::~DiskMeter( void ) { 44 | } 45 | 46 | void DiskMeter::checkResources( void ) { 47 | FieldMeterGraph::checkResources(); 48 | 49 | setfieldcolor( 0, parent_->getResource("diskReadColor") ); 50 | setfieldcolor( 1, parent_->getResource("diskWriteColor") ); 51 | setfieldcolor( 2, parent_->getResource("diskIdleColor") ); 52 | priority_ = atoi( parent_->getResource("diskPriority") ); 53 | dodecay_ = parent_->isResourceTrue("diskDecay"); 54 | useGraph_ = parent_->isResourceTrue("diskGraph"); 55 | SetUsedFormat( parent_->getResource("diskUsedFormat") ); 56 | } 57 | 58 | void DiskMeter::checkevent( void ) { 59 | getstats(); 60 | drawfields(); 61 | } 62 | 63 | void DiskMeter::getstats( void ) { 64 | uint64_t reads = 0, writes = 0; 65 | // Reset to desired full-scale settings. 66 | total_ = maxBandwidth_; 67 | 68 | IntervalTimerStop(); 69 | BSDGetDiskXFerBytes(&reads, &writes); 70 | 71 | /* Adjust this to bytes/second. */ 72 | #if defined(HAVE_DEVSTAT) 73 | fields_[0] = reads / IntervalTimeInSecs(); 74 | fields_[1] = writes / IntervalTimeInSecs(); 75 | #else 76 | fields_[0] = (reads - prevreads_) / IntervalTimeInSecs(); 77 | fields_[1] = (writes - prevwrites_) / IntervalTimeInSecs(); 78 | prevreads_ = reads; 79 | prevwrites_ = writes; 80 | #endif 81 | IntervalTimerStart(); 82 | 83 | /* Adjust in case of first call. */ 84 | if (fields_[0] < 0.0) 85 | fields_[0] = 0.0; 86 | if (fields_[1] < 0.0) 87 | fields_[1] = 0.0; 88 | 89 | /* Adjust total_ if needed. */ 90 | if (fields_[0] + fields_[1] > total_) 91 | total_ = fields_[0] + fields_[1]; 92 | 93 | fields_[2] = total_ - (fields_[0] + fields_[1]); 94 | if (fields_[0] < 0.0) 95 | warnx("diskmeter: fields[0] of %f is < 0!", fields_[0]); 96 | if (fields_[1] < 0.0) 97 | warnx("diskmeter: fields[1] of %f is < 0!", fields_[1]); 98 | if (fields_[2] < 0.0) 99 | warnx("diskmeter: fields[2] of %f is < 0!", fields_[2]); 100 | 101 | setUsed(fields_[0] + fields_[1], total_); 102 | } 103 | -------------------------------------------------------------------------------- /bsd/diskmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // NetBSD port: 3 | // Copyright (c) 1995,1996,1997 Brian Grayson(bgrayson@netbsd.org) 4 | // 5 | // This file was written by Brian Grayson for the NetBSD and xosview 6 | // projects. 7 | // This file may be distributed under terms of the GPL or of the BSD 8 | // license, whichever you choose. The full license notices are 9 | // contained in the files COPYING.GPL and COPYING.BSD, which you 10 | // should have received. If not, contact one of the xosview 11 | // authors for a copy. 12 | // 13 | 14 | #ifndef _DISKMETER_H_ 15 | #define _DISKMETER_H_ 16 | 17 | #include "fieldmetergraph.h" 18 | #include "xosview.h" 19 | #include "defines.h" 20 | 21 | 22 | class DiskMeter : public FieldMeterGraph { 23 | public: 24 | DiskMeter( XOSView *parent, double max ); 25 | ~DiskMeter( void ); 26 | 27 | const char *name( void ) const { return "DiskMeter"; } 28 | void checkevent( void ); 29 | void checkResources( void ); 30 | 31 | protected: 32 | void getstats( void ); 33 | 34 | private: 35 | #ifndef HAVE_DEVSTAT 36 | uint64_t prevreads_, prevwrites_; 37 | #endif 38 | double maxBandwidth_; 39 | }; 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /bsd/intmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #include "intmeter.h" 8 | #include "kernel.h" 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | IntMeter::IntMeter( XOSView *parent, const char *, const char *, int dolegends, int dousedlegends ) 15 | : BitMeter( parent, "INTS", "IRQs", 1, dolegends, dousedlegends ) { 16 | if (!BSDIntrInit()) 17 | disableMeter(); 18 | irqcount_ = BSDNumInts(); 19 | irqs_ = (uint64_t *)calloc(irqcount_ + 1, sizeof(uint64_t)); 20 | lastirqs_ = (uint64_t *)calloc(irqcount_ + 1, sizeof(uint64_t)); 21 | inbrs_ = (unsigned int *)calloc(irqcount_ + 1, sizeof(int)); 22 | updateirqcount(true); 23 | } 24 | 25 | IntMeter::~IntMeter( void ) { 26 | free(irqs_); 27 | free(lastirqs_); 28 | free(inbrs_); 29 | } 30 | 31 | void IntMeter::checkevent( void ) { 32 | getirqs(); 33 | 34 | for (uint i = 0 ; i <= irqcount_ ; i++) { 35 | if (inbrs_[i] != 0) { 36 | if (realintnum_.find(i) == realintnum_.end()) { // new interrupt number 37 | updateirqcount(); 38 | return; 39 | } 40 | bits_[realintnum_[i]] = ((irqs_[i] - lastirqs_[i]) != 0); 41 | lastirqs_[i] = irqs_[i]; 42 | } 43 | } 44 | bzero(inbrs_, (irqcount_ + 1) * sizeof(inbrs_[0])); 45 | bzero(irqs_, (irqcount_ + 1) * sizeof(irqs_[0])); 46 | 47 | BitMeter::checkevent(); 48 | } 49 | 50 | void IntMeter::checkResources( void ) { 51 | BitMeter::checkResources(); 52 | onColor_ = parent_->allocColor( parent_->getResource( "intOnColor" ) ); 53 | offColor_ = parent_->allocColor( parent_->getResource( "intOffColor" ) ); 54 | priority_ = atoi( parent_->getResource( "intPriority" ) ); 55 | } 56 | 57 | void IntMeter::getirqs( void ) { 58 | BSDGetIntrStats(irqs_, inbrs_); 59 | } 60 | 61 | void IntMeter::updateirqcount( bool init ) { 62 | int count = 16; 63 | 64 | if (init) { 65 | getirqs(); 66 | for (int i = 0; i < 16; i++) 67 | realintnum_[i] = i; 68 | } 69 | for (uint i = 16; i <= irqcount_; i++) { 70 | if (inbrs_[i] != 0) { 71 | realintnum_[i] = count++; 72 | inbrs_[i] = 0; 73 | } 74 | } 75 | setNumBits(count); 76 | 77 | // Build the legend. 78 | std::ostringstream os; 79 | os << "0"; 80 | if (realintnum_.upper_bound(15) == realintnum_.end()) // only 16 ints 81 | os << "-15"; 82 | else { 83 | int prev = 15, prev2 = 14; 84 | for (std::map::const_iterator it = realintnum_.upper_bound(15), 85 | end = realintnum_.end(); it != end; ++it) { 86 | if ( &*it == &*realintnum_.rbegin() ) { // last element 87 | if (it->first == prev + 1) 88 | os << "-" ; 89 | else { 90 | if (prev == prev2 + 1) 91 | os << "-" << prev; 92 | os << "," ; 93 | } 94 | os << it->first; 95 | } 96 | else { 97 | if (it->first != prev + 1) { 98 | if (prev == prev2 + 1) 99 | os << "-" << prev; 100 | os << "," << it->first ; 101 | } 102 | } 103 | prev2 = prev; 104 | prev = it->first; 105 | } 106 | os << std::ends; 107 | } 108 | legend(os.str().c_str()); 109 | } 110 | -------------------------------------------------------------------------------- /bsd/intmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _INTMETER_H_ 8 | #define _INTMETER_H_ 9 | 10 | #include "bitmeter.h" 11 | #include "xosview.h" 12 | #include 13 | 14 | 15 | class IntMeter : public BitMeter { 16 | public: 17 | IntMeter( XOSView *parent, const char *title = "", const char *legend = "", 18 | int dolegends = 0, int dousedlegends = 0 ); 19 | ~IntMeter( void ); 20 | 21 | const char *name( void ) const { return "IntMeter"; } 22 | void checkevent( void ); 23 | void checkResources( void ); 24 | 25 | private: 26 | uint64_t *irqs_, *lastirqs_; 27 | unsigned int *inbrs_; 28 | unsigned int irqcount_; 29 | std::map realintnum_; 30 | 31 | protected: 32 | void getirqs( void ); 33 | void updateirqcount( bool init = false ); 34 | }; 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /bsd/intratemeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1999 by Brian Grayson (bgrayson@netbsd.org) 3 | // 4 | // This file may be distributed under terms of the GPL or of the BSD 5 | // license, whichever you choose. The full license notices are 6 | // contained in the files COPYING.GPL and COPYING.BSD, which you 7 | // should have received. If not, contact one of the xosview 8 | // authors for a copy. 9 | // 10 | 11 | #include "intratemeter.h" 12 | #include "kernel.h" 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | IrqRateMeter::IrqRateMeter( XOSView *parent ) 19 | : FieldMeterGraph( parent, 2, "IRQs", "IRQs per sec/IDLE", 1, 1, 0 ) { 20 | if (!BSDIntrInit()) { 21 | warnx("The kernel does not seem to have the symbols needed for the IrqRateMeter."); 22 | warnx("The IrqRateMeter has been disabled."); 23 | disableMeter(); 24 | } 25 | irqcount_ = BSDNumInts(); 26 | irqs_ = (uint64_t *)calloc(irqcount_ + 1, sizeof(uint64_t)); 27 | lastirqs_ = (uint64_t *)calloc(irqcount_ + 1, sizeof(uint64_t)); 28 | } 29 | 30 | IrqRateMeter::~IrqRateMeter( void ) { 31 | free(irqs_); 32 | free(lastirqs_); 33 | } 34 | 35 | void IrqRateMeter::checkResources( void ) { 36 | FieldMeterGraph::checkResources(); 37 | setfieldcolor( 0, parent_->getResource("irqrateUsedColor") ); 38 | setfieldcolor( 1, parent_->getResource("irqrateIdleColor") ); 39 | priority_ = atoi( parent_->getResource("irqratePriority") ); 40 | dodecay_ = parent_->isResourceTrue("irqrateDecay"); 41 | useGraph_ = parent_->isResourceTrue("irqrateGraph"); 42 | SetUsedFormat( parent_->getResource("irqrateUsedFormat") ); 43 | total_ = 2000; 44 | 45 | BSDGetIntrStats(lastirqs_, NULL); 46 | } 47 | 48 | void IrqRateMeter::checkevent( void ) { 49 | getinfo(); 50 | drawfields(); 51 | } 52 | 53 | void IrqRateMeter::getinfo( void ) { 54 | int delta = 0; 55 | 56 | IntervalTimerStop(); 57 | BSDGetIntrStats(irqs_, NULL); 58 | 59 | for (uint i = 0; i <= irqcount_; i++) { 60 | delta += irqs_[i] - lastirqs_[i]; 61 | lastirqs_[i] = irqs_[i]; 62 | } 63 | bzero(irqs_, (irqcount_ + 1) * sizeof(irqs_[0])); 64 | 65 | /* Scale delta by the priority. */ 66 | fields_[0] = delta / IntervalTimeInSecs(); 67 | 68 | // Bump total_, if needed. 69 | if (fields_[0] > total_) 70 | total_ = fields_[0]; 71 | 72 | setUsed(fields_[0], total_); 73 | IntervalTimerStart(); 74 | } 75 | -------------------------------------------------------------------------------- /bsd/intratemeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1999 by Brian Grayson (bgrayson@netbsd.org) 3 | // 4 | // This file may be distributed under terms of the GPL or of the BSD 5 | // license, whichever you choose. The full license notices are 6 | // contained in the files COPYING.GPL and COPYING.BSD, which you 7 | // should have received. If not, contact one of the xosview 8 | // authors for a copy. 9 | // 10 | 11 | #ifndef _IRQRATEMETER_H_ 12 | #define _IRQRATEMETER_H_ 13 | 14 | #include "fieldmetergraph.h" 15 | #include "xosview.h" 16 | 17 | 18 | class IrqRateMeter : public FieldMeterGraph { 19 | public: 20 | IrqRateMeter( XOSView *parent ); 21 | ~IrqRateMeter( void ); 22 | 23 | const char *name( void ) const { return "IrqRateMeter"; } 24 | void checkevent( void ); 25 | void checkResources( void ); 26 | 27 | private: 28 | uint64_t *irqs_, *lastirqs_; 29 | unsigned int irqcount_; 30 | 31 | protected: 32 | void getinfo( void ); 33 | }; 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /bsd/kernel.h: -------------------------------------------------------------------------------- 1 | #ifndef __kernel_h__ 2 | #define __kernel_h__ 3 | 4 | // 5 | // NetBSD port: 6 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 7 | // 8 | // This file was written by Brian Grayson for the NetBSD and xosview 9 | // projects. 10 | // This file may be distributed under terms of the GPL or of the BSD 11 | // license, whichever you choose. The full license notices are 12 | // contained in the files COPYING.GPL and COPYING.BSD, which you 13 | // should have received. If not, contact one of the xosview 14 | // authors for a copy. 15 | // 16 | 17 | #include "defines.h" 18 | 19 | void 20 | BSDInit(); 21 | 22 | void 23 | SetKernelName(const char* kernelName); 24 | 25 | int 26 | BSDGetCPUSpeed(); 27 | 28 | void 29 | BSDPageInit(); 30 | 31 | void 32 | BSDGetPageStats(uint64_t *meminfo, uint64_t *pageinfo); 33 | 34 | void 35 | BSDCPUInit(); 36 | 37 | void 38 | BSDGetCPUTimes(uint64_t *timesArray, unsigned int cpu = 0); 39 | 40 | int 41 | BSDNetInit(); 42 | 43 | void 44 | BSDGetNetInOut(uint64_t *inbytes, uint64_t *outbytes, const char *netIface, bool ignored); 45 | 46 | int 47 | BSDSwapInit(); 48 | 49 | void 50 | BSDGetSwapInfo(uint64_t *total, uint64_t *free); 51 | 52 | int 53 | BSDDiskInit(); 54 | 55 | uint64_t 56 | BSDGetDiskXFerBytes(uint64_t *read_bytes, uint64_t *write_bytes); 57 | 58 | int 59 | BSDIntrInit(); 60 | 61 | int 62 | BSDNumInts(); 63 | 64 | void 65 | BSDGetIntrStats(uint64_t *intrCount, unsigned int *intrNbrs); 66 | 67 | int 68 | BSDCountCpus(void); 69 | 70 | #if defined(__i386__) || defined(__x86_64) 71 | unsigned int 72 | BSDGetCPUTemperature(float *temps, float *tjmax); 73 | #endif 74 | 75 | void 76 | BSDGetSensor(const char *name, const char *valname, float *value, char *unit = NULL); 77 | 78 | bool 79 | BSDHasBattery(); 80 | 81 | void 82 | BSDGetBatteryInfo(int *remaining, unsigned int *state); 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /bsd/loadmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 4 | // 5 | // Most of this code was written by Werner Fink 6 | // Only small changes were made on my part (M.R.) 7 | // And the near-trivial port to NetBSD was by bgrayson. 8 | // 9 | // This file may be distributed under terms of the GPL or of the BSD 10 | // license, whichever you choose. The full license notices are 11 | // contained in the files COPYING.GPL and COPYING.BSD, which you 12 | // should have received. If not, contact one of the xosview 13 | // authors for a copy. 14 | // 15 | 16 | #ifndef _LOADMETER_H_ 17 | #define _LOADMETER_H_ 18 | 19 | #include "fieldmetergraph.h" 20 | #include "xosview.h" 21 | 22 | 23 | class LoadMeter : public FieldMeterGraph { 24 | public: 25 | LoadMeter( XOSView *parent ); 26 | ~LoadMeter( void ); 27 | 28 | const char *name( void ) const { return "LoadMeter"; } 29 | void checkevent( void ); 30 | void checkResources( void ); 31 | 32 | protected: 33 | void getloadinfo( void ); 34 | 35 | private: 36 | unsigned long procloadcol_, warnloadcol_, critloadcol_; 37 | int warnThreshold_, critThreshold_, alarmstate_, lastalarmstate_; 38 | int old_cpu_speed_, cur_cpu_speed_; 39 | bool do_cpu_speed_; 40 | }; 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /bsd/memmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // NetBSD port: 5 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 6 | // 7 | // This file was originally written by Brian Grayson for the NetBSD and 8 | // xosview projects. 9 | // The NetBSD memmeter was improved by Tom Pavel (pavel@slac.stanford.edu) 10 | // to provide active and inactive values, rather than just "used." 11 | // 12 | // This file may be distributed under terms of the GPL or of the BSD 13 | // license, whichever you choose. The full license notices are 14 | // contained in the files COPYING.GPL and COPYING.BSD, which you 15 | // should have received. If not, contact one of the xosview 16 | // authors for a copy. 17 | // 18 | 19 | #include "memmeter.h" 20 | #include "defines.h" 21 | #include "kernel.h" 22 | #include 23 | 24 | 25 | MemMeter::MemMeter( XOSView *parent ) 26 | #if defined(HAVE_UVM) 27 | : FieldMeterGraph( parent, 4, "MEM", "ACT/INACT/WRD/FREE" ) { 28 | #else 29 | : FieldMeterGraph( parent, 5, "MEM", "ACT/INACT/WRD/CA/FREE" ) { 30 | #endif 31 | BSDPageInit(); 32 | } 33 | 34 | MemMeter::~MemMeter( void ) { 35 | 36 | } 37 | 38 | void MemMeter::checkResources( void ) { 39 | FieldMeterGraph::checkResources(); 40 | 41 | setfieldcolor( 0, parent_->getResource("memActiveColor") ); 42 | setfieldcolor( 1, parent_->getResource("memInactiveColor") ); 43 | setfieldcolor( 2, parent_->getResource("memWiredColor") ); 44 | #if defined(HAVE_UVM) 45 | setfieldcolor( 3, parent_->getResource("memFreeColor") ); 46 | #else 47 | setfieldcolor( 3, parent_->getResource("memCacheColor") ); 48 | setfieldcolor( 4, parent_->getResource("memFreeColor") ); 49 | #endif 50 | priority_ = atoi( parent_->getResource("memPriority") ); 51 | dodecay_ = parent_->isResourceTrue("memDecay"); 52 | useGraph_ = parent_->isResourceTrue("memGraph"); 53 | SetUsedFormat( parent_->getResource("memUsedFormat") ); 54 | } 55 | 56 | void MemMeter::checkevent( void ) { 57 | getmeminfo(); 58 | drawfields(); 59 | } 60 | 61 | void MemMeter::getmeminfo( void ) { 62 | BSDGetPageStats(meminfo_, NULL); 63 | fields_[0] = (double)meminfo_[0]; 64 | fields_[1] = (double)meminfo_[1]; 65 | fields_[2] = (double)meminfo_[2]; 66 | #if defined(HAVE_UVM) 67 | fields_[3] = (double)meminfo_[4]; 68 | #else 69 | fields_[3] = (double)meminfo_[3]; 70 | fields_[4] = (double)meminfo_[4]; 71 | #endif 72 | total_ = (double)(meminfo_[0] + meminfo_[1] + meminfo_[2] + meminfo_[3] + meminfo_[4]); 73 | setUsed(total_ - (double)meminfo_[4], total_); 74 | } 75 | -------------------------------------------------------------------------------- /bsd/memmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // NetBSD port: 5 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 6 | // 7 | // This file was written by Brian Grayson for the NetBSD and xosview 8 | // projects. 9 | // This file may be distributed under terms of the GPL or of the BSD 10 | // license, whichever you choose. The full license notices are 11 | // contained in the files COPYING.GPL and COPYING.BSD, which you 12 | // should have received. If not, contact one of the xosview 13 | // authors for a copy. 14 | // 15 | 16 | #ifndef _MEMMETER_H_ 17 | #define _MEMMETER_H_ 18 | 19 | #include "fieldmetergraph.h" 20 | #include "xosview.h" 21 | 22 | 23 | class MemMeter : public FieldMeterGraph { 24 | public: 25 | MemMeter( XOSView *parent ); 26 | ~MemMeter( void ); 27 | 28 | const char *name( void ) const { return "MemMeter"; } 29 | void checkevent( void ); 30 | void checkResources( void ); 31 | 32 | protected: 33 | void getmeminfo( void ); 34 | 35 | private: 36 | uint64_t meminfo_[5]; 37 | }; 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /bsd/netmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // NetBSD port: 5 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 6 | // 7 | // This file was written by Brian Grayson for the NetBSD and xosview 8 | // projects. 9 | // This file may be distributed under terms of the GPL or of the BSD 10 | // license, whichever you choose. The full license notices are 11 | // contained in the files COPYING.GPL and COPYING.BSD, which you 12 | // should have received. If not, contact one of the xosview 13 | // authors for a copy. 14 | // 15 | 16 | #include "netmeter.h" 17 | #include "kernel.h" 18 | #include 19 | #include 20 | 21 | 22 | NetMeter::NetMeter( XOSView *parent, double max ) 23 | : FieldMeterGraph( parent, 3, "NET", "IN/OUT/IDLE" ) { 24 | if (!BSDNetInit()) { 25 | warnx("The kernel does not seem to have the symbols needed for the NetMeter."); 26 | warnx("The NetMeter has been disabled."); 27 | disableMeter (); 28 | } 29 | else { 30 | total_ = netBandwidth_ = max; 31 | lastBytesIn_ = lastBytesOut_ = 0; 32 | netIface_ = "False"; 33 | ignored_ = false; 34 | BSDGetNetInOut(&lastBytesIn_, &lastBytesOut_, netIface_.c_str(), ignored_); 35 | IntervalTimerStart(); 36 | } 37 | } 38 | 39 | NetMeter::~NetMeter( void ) { 40 | } 41 | 42 | void NetMeter::checkResources( void ) { 43 | FieldMeterGraph::checkResources(); 44 | 45 | setfieldcolor( 0, parent_->getResource("netInColor") ); 46 | setfieldcolor( 1, parent_->getResource("netOutColor") ); 47 | setfieldcolor( 2, parent_->getResource("netBackground") ); 48 | priority_ = atoi( parent_->getResource("netPriority") ); 49 | dodecay_ = parent_->isResourceTrue("netDecay"); 50 | useGraph_ = parent_->isResourceTrue("netGraph"); 51 | SetUsedFormat( parent_->getResource("netUsedFormat") ); 52 | netIface_ = parent_->getResource("netIface"); 53 | if (netIface_[0] == '-') { 54 | ignored_ = true; 55 | netIface_.erase(0, netIface_.find_first_not_of("- ")); 56 | } 57 | } 58 | 59 | void NetMeter::checkevent( void ) { 60 | getstats(); 61 | drawfields(); 62 | } 63 | 64 | void NetMeter::getstats(void) { 65 | // Reset total_ to expected maximum. If it is too low, it 66 | // will be adjusted in adjust(). bgrayson 67 | total_ = netBandwidth_; 68 | fields_[0] = fields_[1] = 0; 69 | uint64_t nowBytesIn, nowBytesOut; 70 | 71 | IntervalTimerStop(); 72 | BSDGetNetInOut(&nowBytesIn, &nowBytesOut, netIface_.c_str(), ignored_); 73 | double t = (1.0) / IntervalTimeInSecs(); 74 | IntervalTimerStart(); 75 | 76 | fields_[0] = (double)(nowBytesIn - lastBytesIn_) * t; 77 | lastBytesIn_ = nowBytesIn; 78 | fields_[1] = (double)(nowBytesOut - lastBytesOut_) * t; 79 | lastBytesOut_ = nowBytesOut; 80 | 81 | if (total_ < (fields_[0] + fields_[1])) 82 | total_ = fields_[0] + fields_[1]; 83 | fields_[2] = total_ - fields_[0] - fields_[1]; 84 | /* The fields_ values have already been scaled into bytes/sec by 85 | * the manipulations (* t) above. */ 86 | setUsed(fields_[0] + fields_[1], total_); 87 | } 88 | -------------------------------------------------------------------------------- /bsd/netmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // NetBSD port: 5 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 6 | // 7 | // This file was written by Brian Grayson for the NetBSD and xosview 8 | // projects. 9 | // This file may be distributed under terms of the GPL or of the BSD 10 | // license, whichever you choose. The full license notices are 11 | // contained in the files COPYING.GPL and COPYING.BSD, which you 12 | // should have received. If not, contact one of the xosview 13 | // authors for a copy. 14 | // 15 | 16 | #ifndef _NETMETER_H_ 17 | #define _NETMETER_H_ 18 | 19 | #include "fieldmetergraph.h" 20 | #include "xosview.h" 21 | #include 22 | 23 | 24 | class NetMeter : public FieldMeterGraph { 25 | public: 26 | NetMeter( XOSView *parent, double max ); 27 | ~NetMeter( void ); 28 | 29 | const char *name( void ) const { return "NetMeter"; } 30 | void checkevent( void ); 31 | void checkResources( void ); 32 | 33 | protected: 34 | void getstats(void); 35 | 36 | private: 37 | uint64_t lastBytesIn_, lastBytesOut_; 38 | double netBandwidth_; 39 | std::string netIface_; 40 | bool ignored_; 41 | }; 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /bsd/pagemeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // NetBSD port: 5 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 6 | // 7 | // This file was originally written by Brian Grayson for the NetBSD and 8 | // xosview projects. 9 | // 10 | // This file may be distributed under terms of the GPL or of the BSD 11 | // license, whichever you choose. The full license notices are 12 | // contained in the files COPYING.GPL and COPYING.BSD, which you 13 | // should have received. If not, contact one of the xosview 14 | // authors for a copy. 15 | // 16 | 17 | #include "pagemeter.h" 18 | #include "kernel.h" 19 | #include 20 | 21 | 22 | PageMeter::PageMeter( XOSView *parent, double total ) 23 | : FieldMeterGraph( parent, 3, "PAGE", "IN/OUT/IDLE" ) { 24 | total_ = total; 25 | BSDPageInit(); 26 | BSDGetPageStats(NULL, previnfo_); 27 | } 28 | 29 | PageMeter::~PageMeter( void ) { 30 | } 31 | 32 | void PageMeter::checkResources( void ) { 33 | FieldMeterGraph::checkResources(); 34 | 35 | setfieldcolor( 0, parent_->getResource("pageInColor") ); 36 | setfieldcolor( 1, parent_->getResource("pageOutColor") ); 37 | setfieldcolor( 2, parent_->getResource("pageIdleColor") ); 38 | priority_ = atoi( parent_->getResource("pagePriority") ); 39 | dodecay_ = parent_->isResourceTrue("pageDecay"); 40 | useGraph_ = parent_->isResourceTrue("pageGraph"); 41 | SetUsedFormat( parent_->getResource("pageUsedFormat") ); 42 | } 43 | 44 | void PageMeter::checkevent( void ) { 45 | getpageinfo(); 46 | drawfields(); 47 | } 48 | 49 | void PageMeter::getpageinfo( void ) { 50 | uint64_t info[2]; 51 | BSDGetPageStats(NULL, info); 52 | 53 | fields_[0] = info[0] - previnfo_[0]; 54 | fields_[1] = info[1] - previnfo_[1]; 55 | previnfo_[0] = info[0]; 56 | previnfo_[1] = info[1]; 57 | 58 | if (total_ < fields_[0] + fields_[1]) 59 | total_ = fields_[0] + fields_[1]; 60 | 61 | fields_[2] = total_ - fields_[0] - fields_[1]; 62 | setUsed(total_ - fields_[2], total_); 63 | } 64 | -------------------------------------------------------------------------------- /bsd/pagemeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // NetBSD port: 5 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 6 | // 7 | // This file was written by Brian Grayson for the NetBSD and xosview 8 | // projects. 9 | // This file may be distributed under terms of the GPL or of the BSD 10 | // license, whichever you choose. The full license notices are 11 | // contained in the files COPYING.GPL and COPYING.BSD, which you 12 | // should have received. If not, contact one of the xosview 13 | // authors for a copy. 14 | // 15 | 16 | #ifndef _PAGEMETER_H_ 17 | #define _PAGEMETER_H_ 18 | 19 | #include "fieldmetergraph.h" 20 | #include "xosview.h" 21 | 22 | 23 | class PageMeter : public FieldMeterGraph { 24 | public: 25 | PageMeter( XOSView *parent, double total ); 26 | ~PageMeter( void ); 27 | 28 | const char *name( void ) const { return "PageMeter"; } 29 | void checkevent( void ); 30 | void checkResources( void ); 31 | 32 | protected: 33 | void getpageinfo( void ); 34 | 35 | private: 36 | uint64_t previnfo_[2]; 37 | }; 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /bsd/sensor.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 by Tomi Tapper 3 | // 4 | // File based on linux/lmstemp.* by 5 | // Copyright (c) 2000, 2006 by Leopold Toetsch 6 | // 7 | // This file may be distributed under terms of the GPL 8 | // 9 | // 10 | // 11 | 12 | #include "sensor.h" 13 | #include "kernel.h" 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | BSDSensor::BSDSensor( XOSView *parent, const char *name, const char *high, 22 | const char *low, const char *label, const char *caption, int nbr ) 23 | : SensorFieldMeter( parent, label, caption, 1, 1, 0 ) { 24 | nbr_ = nbr; 25 | highname_[0] = highval_[0] = '\0'; 26 | lowname_[0] = lowval_[0] = '\0'; 27 | std::string n(name), tmp; 28 | tmp = n.substr( 0, n.find_first_of('.') ); 29 | strncpy(name_, tmp.c_str(), NAMESIZE); 30 | tmp = n.substr( n.find_first_of('.') + 1 ); 31 | strncpy(val_, tmp.c_str(), NAMESIZE); 32 | if (high) { 33 | has_high_ = true; 34 | if ( sscanf(high, "%lf", &high_) == 0 ) { // high given as number? 35 | n = high; 36 | tmp = n.substr( 0, n.find_first_of('.') ); 37 | strncpy(highname_, tmp.c_str(), NAMESIZE); 38 | tmp = n.substr( n.find_first_of('.') + 1 ); 39 | strncpy(highval_, tmp.c_str(), NAMESIZE); 40 | } 41 | } 42 | if (low) { 43 | has_low_ = true; 44 | if ( sscanf(low, "%lf", &low_) == 0 ) { // low given as number? 45 | n = low; 46 | tmp = n.substr( 0, n.find_first_of('.') ); 47 | strncpy(lowname_, tmp.c_str(), NAMESIZE); 48 | tmp = n.substr( n.find_first_of('.') + 1 ); 49 | strncpy(lowval_, tmp.c_str(), NAMESIZE); 50 | } 51 | } 52 | } 53 | 54 | BSDSensor::~BSDSensor( void ) { 55 | } 56 | 57 | void BSDSensor::checkResources( void ) { 58 | SensorFieldMeter::checkResources(); 59 | 60 | actcolor_ = parent_->allocColor( parent_->getResource( "bsdsensorActColor" ) ); 61 | highcolor_ = parent_->allocColor( parent_->getResource( "bsdsensorHighColor" ) ); 62 | lowcolor_ = parent_->allocColor( parent_->getResource( "bsdsensorLowColor" ) ); 63 | setfieldcolor( 0, actcolor_ ); 64 | setfieldcolor( 1, parent_->getResource( "bsdsensorIdleColor" ) ); 65 | setfieldcolor( 2, highcolor_ ); 66 | priority_ = atoi( parent_->getResource( "bsdsensorPriority" ) ); 67 | 68 | char s[32]; 69 | const char *tmp = parent_->getResourceOrUseDefault( "bsdsensorHighest", "0" ); 70 | snprintf(s, 32, "bsdsensorHighest%d", nbr_); 71 | total_ = fabs( atof( parent_->getResourceOrUseDefault(s, tmp) ) ); 72 | snprintf(s, 32, "bsdsensorUsedFormat%d", nbr_); 73 | const char *f = parent_->getResourceOrUseDefault(s, NULL); 74 | SetUsedFormat( f ? f : parent_->getResource( "bsdsensorUsedFormat" ) ); 75 | 76 | if (!has_high_) 77 | high_ = total_; 78 | if (!has_low_) 79 | low_ = 0; 80 | 81 | // Get the unit. 82 | float dummy; 83 | BSDGetSensor(name_, val_, &dummy, unit_); 84 | updateLegend(); 85 | } 86 | 87 | void BSDSensor::checkevent( void ) { 88 | getsensor(); 89 | drawfields(); 90 | } 91 | 92 | void BSDSensor::getsensor( void ) { 93 | float value, high = high_, low = low_; 94 | BSDGetSensor(name_, val_, &value); 95 | if ( strlen(highname_) ) 96 | BSDGetSensor(highname_, highval_, &high); 97 | if ( strlen(lowname_) ) 98 | BSDGetSensor(lowname_, lowval_, &low); 99 | 100 | fields_[0] = value; 101 | checkFields(low, high); 102 | } 103 | -------------------------------------------------------------------------------- /bsd/sensor.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 by Tomi Tapper 3 | // 4 | // File based on linux/lmstemp.* by 5 | // Copyright (c) 2000, 2006 by Leopold Toetsch 6 | // 7 | // This file may be distributed under terms of the GPL 8 | // 9 | // 10 | // 11 | #ifndef _BSDSENSOR_H_ 12 | #define _BSDSENSOR_H_ 13 | 14 | #include "sensorfieldmeter.h" 15 | #include "xosview.h" 16 | 17 | #define NAMESIZE 32 18 | 19 | 20 | class BSDSensor : public SensorFieldMeter { 21 | public: 22 | BSDSensor( XOSView *parent, const char *name, const char *high, 23 | const char *low, const char *label, const char *caption, int nbr ); 24 | ~BSDSensor( void ); 25 | 26 | const char *name( void ) const { return "BSDSensor"; } 27 | void checkevent( void ); 28 | void checkResources( void ); 29 | 30 | protected: 31 | void getsensor( void ); 32 | 33 | private: 34 | char name_[NAMESIZE], highname_[NAMESIZE], lowname_[NAMESIZE]; 35 | char val_[NAMESIZE], highval_[NAMESIZE], lowval_[NAMESIZE]; 36 | int nbr_; 37 | }; 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /bsd/swapmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // NetBSD port: 5 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 6 | // 7 | // This file was written by Brian Grayson for the NetBSD and xosview 8 | // projects. 9 | // This file may be distributed under terms of the GPL or of the BSD 10 | // license, whichever you choose. The full license notices are 11 | // contained in the files COPYING.GPL and COPYING.BSD, which you 12 | // should have received. If not, contact one of the xosview 13 | // authors for a copy. 14 | // 15 | 16 | #include "swapmeter.h" 17 | #include "kernel.h" 18 | #include 19 | 20 | 21 | SwapMeter::SwapMeter( XOSView *parent ) 22 | : FieldMeterGraph( parent, 2, "SWAP", "USED/FREE" ) { 23 | BSDSwapInit(); 24 | } 25 | 26 | SwapMeter::~SwapMeter( void ) { 27 | } 28 | 29 | void SwapMeter::checkResources( void ) { 30 | FieldMeterGraph::checkResources(); 31 | 32 | setfieldcolor( 0, parent_->getResource("swapUsedColor") ); 33 | setfieldcolor( 1, parent_->getResource("swapFreeColor") ); 34 | priority_ = atoi( parent_->getResource("swapPriority") ); 35 | dodecay_ = parent_->isResourceTrue("swapDecay"); 36 | useGraph_ = parent_->isResourceTrue("swapGraph"); 37 | SetUsedFormat( parent_->getResource("swapUsedFormat") ); 38 | } 39 | 40 | void SwapMeter::checkevent( void ) { 41 | getswapinfo(); 42 | drawfields(); 43 | } 44 | 45 | void SwapMeter::getswapinfo( void ) { 46 | uint64_t total = 0, used = 0; 47 | 48 | BSDGetSwapInfo(&total, &used); 49 | 50 | total_ = (double)total; 51 | if ( total_ == 0.0 ) 52 | total_ = 1.0; /* We don't want any division by zero, now, do we? :) */ 53 | fields_[0] = (double)used; 54 | fields_[1] = total_; 55 | 56 | setUsed(fields_[0], total_); 57 | } 58 | -------------------------------------------------------------------------------- /bsd/swapmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org) 3 | // 4 | // This file was written by Brian Grayson for the NetBSD and xosview 5 | // projects. 6 | // This file may be distributed under terms of the GPL or of the BSD 7 | // license, whichever you choose. The full license notices are 8 | // contained in the files COPYING.GPL and COPYING.BSD, which you 9 | // should have received. If not, contact one of the xosview 10 | // authors for a copy. 11 | // 12 | 13 | #ifndef _SWAPMETER_H_ 14 | #define _SWAPMETER_H_ 15 | 16 | #include "fieldmetergraph.h" 17 | #include "xosview.h" 18 | 19 | 20 | class SwapMeter : public FieldMeterGraph { 21 | public: 22 | SwapMeter( XOSView *parent ); 23 | ~SwapMeter( void ); 24 | 25 | const char *name( void ) const { return "SwapMeter"; } 26 | void checkevent( void ); 27 | void checkResources( void ); 28 | 29 | protected: 30 | void getswapinfo( void ); 31 | }; 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /defresources.awk: -------------------------------------------------------------------------------- 1 | # 2 | # This is a simple awk program which will generate defaultstring.cc 3 | # from an X resource file. 4 | # 5 | 6 | # 7 | # insert the "header" for defaultstring.cc 8 | # 9 | BEGIN { 10 | print "//"; 11 | print "// Do not edit this file."; 12 | print "// This file is generated automagically from Xdefaults"; 13 | print "// using the awk program found in defresources.awk."; 14 | print "// This file will be rebuilt when Xdefaults is modified."; 15 | print "//\n"; 16 | printf "const char *defaultXResourceString = \""; 17 | } 18 | 19 | # 20 | # Echo each line of input (that is not a comment or empty) to stdout. 21 | # 22 | (! /^!/) && (NF != 0) { printf "%s\\n\\\n", $0 } 23 | 24 | # 25 | # Insert the "tail" for defresources.cc 26 | # 27 | END { 28 | print "\";\n"; 29 | } 30 | -------------------------------------------------------------------------------- /fieldmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _FIELDMETER_H_ 8 | #define _FIELDMETER_H_ 9 | 10 | #include "meter.h" 11 | #include "xosview.h" 12 | #include "timer.h" 13 | 14 | 15 | class FieldMeter : public Meter { 16 | public: 17 | FieldMeter( XOSView *parent, int numfields, 18 | const char *title = "", const char *legend = "", 19 | int docaptions = 0, int dolegends = 0, int dousedlegends = 0 ); 20 | virtual ~FieldMeter( void ); 21 | 22 | virtual void drawfields( int mandatory = 0 ); 23 | void setfieldcolor( int field, const char *color ); 24 | void setfieldcolor( int field, unsigned long color); 25 | void docaptions( int val ) { docaptions_ = val; } 26 | void dolegends( int val ) { dolegends_ = val; } 27 | void dousedlegends( int val ) { dousedlegends_ = val; } 28 | void reset( void ); 29 | void setUsed (double val, double total); 30 | void draw( void ); 31 | void checkevent( void ); 32 | void disableMeter ( void ); 33 | 34 | virtual void checkResources( void ); 35 | 36 | protected: 37 | enum UsedType { INVALID_0, FLOAT, PERCENT, AUTOSCALE, INVALID_TAIL }; 38 | 39 | int numfields_; 40 | double *fields_; 41 | double total_, used_, lastused_; 42 | int *lastvals_, *lastx_; 43 | unsigned long *colors_; 44 | unsigned long usedcolor_; 45 | UsedType print_; 46 | int printedZeroTotalMesg_; 47 | int numWarnings_; 48 | bool metric_; 49 | int usedoffset_; 50 | 51 | void SetUsedFormat ( const char * const str ); 52 | void drawlegend( void ); 53 | void drawused( int mandatory ); 54 | bool checkX(int x, int width) const; 55 | 56 | void setNumFields(int n); 57 | 58 | 59 | private: 60 | Timer _timer; 61 | protected: 62 | void IntervalTimerStart() { _timer.start(); } 63 | void IntervalTimerStop() { _timer.stop(); } 64 | // Before, we simply called _timer.report(), which returns usecs. 65 | // However, it suffers from wrap/overflow/sign-bit problems, so 66 | // instead we use doubles for everything. 67 | double IntervalTimeInMicrosecs() { return _timer.report_usecs(); } 68 | double IntervalTimeInSecs() { return _timer.report_usecs()/1e6; } 69 | }; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /fieldmeterdecay.h: -------------------------------------------------------------------------------- 1 | // 2 | // Original FieldMeter class is Copyright (c) 1994, 2006 by Mike Romberg 3 | // ( mike.romberg@noaa.gov ) 4 | // Modifications from FieldMeter class done in Oct. 1995 5 | // by Brian Grayson ( bgrayson@netbsd.org ) 6 | // 7 | // This file was written by Brian Grayson for the NetBSD and xosview 8 | // projects. 9 | // This file may be distributed under terms of the GPL or of the BSD 10 | // license, whichever you choose. The full license notices are 11 | // contained in the files COPYING.GPL and COPYING.BSD, which you 12 | // should have received. If not, contact one of the xosview 13 | // authors for a copy. 14 | // 15 | 16 | #ifndef _FIELDMETERDECAY_H_ 17 | #define _FIELDMETERDECAY_H_ 18 | 19 | #include "fieldmeter.h" 20 | #include "xosview.h" 21 | 22 | 23 | class FieldMeterDecay : public FieldMeter { 24 | public: 25 | FieldMeterDecay( XOSView *parent, int numfields, 26 | const char *title = "", const char *legend = "", 27 | int docaptions = 0, int dolegends = 0, int dousedlegends = 0 ); 28 | virtual ~FieldMeterDecay( void ); 29 | 30 | virtual void drawfields( int mandatory = 0 ); 31 | 32 | protected: 33 | int dodecay_; 34 | int firsttime_; // Used to set up decaying fields right the first time. 35 | double *decay_; 36 | double *lastDecayval_; 37 | private: 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /fieldmetergraph.h: -------------------------------------------------------------------------------- 1 | // 2 | // Original FieldMeter class is Copyright (c) 1994, 2006 by Mike Romberg 3 | // ( mike.romberg@noaa.gov ) 4 | // 5 | // Modifications from FieldMeter class done in Oct. 1995 6 | // by Brian Grayson ( bgrayson@netbsd.org ) 7 | // 8 | // Modifications from FieldMeterDecay class done in Oct. 1998 9 | // by Scott McNab ( jedi@tartarus.uwa.edu.au ) 10 | // 11 | 12 | #ifndef _FIELDMETERGRAPH_H_ 13 | #define _FIELDMETERGRAPH_H_ 14 | 15 | #include "fieldmeterdecay.h" 16 | #include "xosview.h" 17 | 18 | 19 | class FieldMeterGraph : public FieldMeterDecay { 20 | public: 21 | FieldMeterGraph( XOSView *parent, int numfields, 22 | const char *title = "", const char *legend = "", 23 | int docaptions = 0, int dolegends = 0, int dousedlegends = 0 ); 24 | virtual ~FieldMeterGraph( void ); 25 | 26 | virtual void drawfields( int mandatory = 0 ); 27 | 28 | virtual void checkResources( void ); 29 | 30 | protected: 31 | void setNumCols( int n ); 32 | 33 | int useGraph_; 34 | int graphNumCols_; 35 | int graphpos_; 36 | /* There's some sort of corruption going on -- we can't have 37 | * variables after the heightfield_ below, otherwise they get 38 | * corrupted??? */ 39 | double *heightfield_; 40 | private: 41 | void drawBar( int i ); 42 | enum XOSView::windowVisibilityState lastWinState; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /gnu/MeterMaker.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2002 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org ) 4 | // 5 | // This file may be distributed under terms of the GPL 6 | // 7 | 8 | #include "MeterMaker.h" 9 | #include "xosview.h" 10 | 11 | #include "memmeter.h" 12 | #include "swapmeter.h" 13 | #include "pagemeter.h" 14 | #include "loadmeter.h" 15 | 16 | #include 17 | 18 | 19 | MeterMaker::MeterMaker(XOSView *xos){ 20 | _xos = xos; 21 | } 22 | 23 | void MeterMaker::makeMeters(void){ 24 | if (_xos->isResourceTrue("load")) 25 | push(new LoadMeter(_xos)); 26 | 27 | if (_xos->isResourceTrue("mem")) 28 | push(new MemMeter(_xos)); 29 | if (_xos->isResourceTrue("swap")) 30 | push(new SwapMeter(_xos)); 31 | 32 | if (_xos->isResourceTrue("page")) 33 | push(new PageMeter(_xos, atof(_xos->getResource("pageBandwidth")))); 34 | } 35 | -------------------------------------------------------------------------------- /gnu/MeterMaker.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org ) 4 | // 5 | // This file may be distributed under terms of the GPL 6 | // 7 | 8 | #ifndef _MeterMaker_h 9 | #define _MeterMaker_h 10 | 11 | #include "pllist.h" 12 | 13 | class Meter; 14 | class XOSView; 15 | 16 | class MeterMaker : public PLList { 17 | public: 18 | MeterMaker(XOSView *xos); 19 | 20 | void makeMeters(void); 21 | 22 | private: 23 | XOSView *_xos; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /gnu/get_def_pager.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #define _GNU_SOURCE 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | mach_port_t get_def_pager(void) { 18 | mach_port_t def_pager = MACH_PORT_NULL; 19 | kern_return_t err; 20 | mach_port_t host; 21 | 22 | err = get_privileged_ports (&host, 0); 23 | if (err == EPERM) { 24 | def_pager = file_name_lookup (_SERVERS_DEFPAGER, O_READ, 0); 25 | if (def_pager == MACH_PORT_NULL) 26 | error (0, errno, _SERVERS_DEFPAGER); 27 | return def_pager; 28 | } else if (err) { 29 | error (0, err, "get_privileged_ports"); 30 | return MACH_PORT_NULL; 31 | } else { 32 | err = vm_set_default_memory_manager (host, &def_pager); 33 | mach_port_deallocate (mach_task_self(), host); 34 | if (err) { 35 | error (0, err, "vm_set_default_memory_manager"); 36 | return MACH_PORT_NULL; 37 | } 38 | return def_pager; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /gnu/get_def_pager.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | extern mach_port_t get_def_pager(void); 8 | -------------------------------------------------------------------------------- /gnu/loadmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org ) 4 | // 5 | // This file may be distributed under terms of the GPL 6 | // 7 | // Most of this code was written by Werner Fink . 8 | // Only small changes were made on my part (M.R.) 9 | // 10 | 11 | #include "loadmeter.h" 12 | #include "xosview.h" 13 | #include 14 | #include 15 | #include 16 | 17 | extern "C" { 18 | #include 19 | #include 20 | } 21 | 22 | LoadMeter::LoadMeter( XOSView *parent ) 23 | : FieldMeterGraph( parent, 2, "LOAD", "PROCS/MIN", 1, 1, 0 ){ 24 | lastalarmstate = -1; 25 | total_ = 2.0; 26 | } 27 | 28 | LoadMeter::~LoadMeter( void ){ 29 | } 30 | 31 | void LoadMeter::checkResources( void ){ 32 | FieldMeterGraph::checkResources(); 33 | 34 | procloadcol_ = parent_->allocColor(parent_->getResource( "loadProcColor" )); 35 | warnloadcol_ = parent_->allocColor(parent_->getResource( "loadWarnColor" )); 36 | critloadcol_ = parent_->allocColor(parent_->getResource( "loadCritColor" )); 37 | 38 | setfieldcolor( 0, procloadcol_ ); 39 | setfieldcolor( 1, parent_->getResource( "loadIdleColor" ) ); 40 | priority_ = atoi (parent_->getResource( "loadPriority" ) ); 41 | useGraph_ = parent_->isResourceTrue( "loadGraph" ); 42 | dodecay_ = parent_->isResourceTrue( "loadDecay" ); 43 | SetUsedFormat (parent_->getResource("loadUsedFormat")); 44 | 45 | warnThreshold = atoi (parent_->getResource("loadWarnThreshold")); 46 | critThreshold = atoi (parent_->getResource("loadCritThreshold")); 47 | 48 | 49 | if (dodecay_){ 50 | // Warning: Since the loadmeter changes scale occasionally, old 51 | // decay values need to be rescaled. However, if they are rescaled, 52 | // they could go off the edge of the screen. Thus, for now, to 53 | // prevent this whole problem, the load meter can not be a decay 54 | // meter. The load is a decaying average kind of thing anyway, 55 | // so having a decaying load average is redundant. 56 | std::cerr << "Warning: The loadmeter can not be configured as a decay\n" 57 | << " meter. See the source code (" << __FILE__ << ") for further\n" 58 | << " details.\n"; 59 | dodecay_ = 0; 60 | } 61 | } 62 | 63 | void LoadMeter::checkevent( void ){ 64 | getloadinfo(); 65 | drawfields(); 66 | } 67 | 68 | 69 | void LoadMeter::getloadinfo( void ){ 70 | host_load_info_data_t info; 71 | mach_msg_type_number_t count = HOST_LOAD_INFO_COUNT; 72 | kern_return_t err; 73 | 74 | err = host_info(mach_host_self(), HOST_LOAD_INFO, (host_info_t) &info, &count); 75 | if (err) { 76 | std::cerr << "Can not get host info"; 77 | parent_->done(1); 78 | return; 79 | } 80 | fields_[0] = (float) info.avenrun[0] / LOAD_SCALE; 81 | 82 | if ( fields_[0] < warnThreshold ) alarmstate = 0; 83 | else 84 | if ( fields_[0] >= critThreshold ) alarmstate = 2; 85 | else 86 | /* if fields_[0] >= warnThreshold */ alarmstate = 1; 87 | 88 | if ( alarmstate != lastalarmstate ){ 89 | if ( alarmstate == 0 ) setfieldcolor( 0, procloadcol_ ); 90 | else 91 | if ( alarmstate == 1 ) setfieldcolor( 0, warnloadcol_ ); 92 | else 93 | /* if alarmstate == 2 */ setfieldcolor( 0, critloadcol_ ); 94 | drawlegend(); 95 | lastalarmstate = alarmstate; 96 | } 97 | 98 | if ( fields_[0]*5.0total_ ) 102 | total_ = fields_[0]*5.0; 103 | 104 | if ( total_ < 1.0) 105 | total_ = 1.0; 106 | 107 | fields_[1] = (float) (total_ - fields_[0]); 108 | 109 | setUsed(fields_[0], (float) 1.0); 110 | } 111 | -------------------------------------------------------------------------------- /gnu/loadmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org ) 4 | // 5 | // This file may be distributed under terms of the GPL 6 | // 7 | // Most of this code was written by Werner Fink 8 | // Only small changes were made on my part (M.R.) 9 | // 10 | 11 | #ifndef _LOADMETER_H_ 12 | #define _LOADMETER_H_ 13 | 14 | 15 | #include "fieldmetergraph.h" 16 | 17 | 18 | class LoadMeter : public FieldMeterGraph { 19 | public: 20 | LoadMeter( XOSView *parent ); 21 | ~LoadMeter( void ); 22 | 23 | const char *name( void ) const { return "LoadMeter"; } 24 | void checkevent( void ); 25 | 26 | void checkResources( void ); 27 | protected: 28 | 29 | void getloadinfo( void ); 30 | unsigned long procloadcol_, warnloadcol_, critloadcol_; 31 | private: 32 | int warnThreshold, critThreshold, alarmstate, lastalarmstate; 33 | }; 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /gnu/memmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org ) 4 | // 5 | // This file may be distributed under terms of the GPL 6 | // 7 | 8 | #include "memmeter.h" 9 | #include "xosview.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | extern "C" { 16 | #include 17 | #include 18 | } 19 | 20 | MemMeter::MemMeter( XOSView *parent ) 21 | : FieldMeterGraph( parent, 4, "MEM", "ACT/INACT/WIRE/FREE" ){ 22 | } 23 | 24 | MemMeter::~MemMeter( void ){ 25 | } 26 | 27 | void MemMeter::checkResources( void ){ 28 | FieldMeterGraph::checkResources(); 29 | 30 | setfieldcolor( 0, parent_->getResource( "memActiveColor" ) ); 31 | setfieldcolor( 1, parent_->getResource( "memInactiveColor" ) ); 32 | setfieldcolor( 2, parent_->getResource( "memCacheColor" ) ); 33 | setfieldcolor( 3, parent_->getResource( "memFreeColor" ) ); 34 | priority_ = atoi (parent_->getResource( "memPriority" ) ); 35 | dodecay_ = parent_->isResourceTrue( "memDecay" ); 36 | useGraph_ = parent_->isResourceTrue( "memGraph" ); 37 | SetUsedFormat (parent_->getResource("memUsedFormat")); 38 | } 39 | 40 | void MemMeter::checkevent( void ){ 41 | getmeminfo(); 42 | drawfields(); 43 | } 44 | 45 | void MemMeter::getmeminfo( void ){ 46 | kern_return_t err; 47 | 48 | err = vm_statistics (mach_task_self(), &vmstats); 49 | if (err) { 50 | error (0, err, "vm_statistics"); 51 | parent_->done(1); 52 | return; 53 | } 54 | 55 | fields_[0] = (double) vmstats.active_count * vmstats.pagesize; 56 | fields_[1] = (double) vmstats.inactive_count * vmstats.pagesize;; 57 | fields_[2] = (double) vmstats.wire_count * vmstats.pagesize;; 58 | fields_[3] = (double) vmstats.free_count * vmstats.pagesize;; 59 | total_ = fields_[0] + fields_[1] + fields_[2] + fields_[3]; 60 | 61 | FieldMeterDecay::setUsed (total_ - fields_[3], total_); 62 | } 63 | -------------------------------------------------------------------------------- /gnu/memmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org ) 4 | // 5 | // This file may be distributed under terms of the GPL 6 | // 7 | 8 | #ifndef _MEMMETER_H_ 9 | #define _MEMMETER_H_ 10 | 11 | #include "fieldmetergraph.h" 12 | 13 | extern "C" { 14 | #include 15 | } 16 | 17 | class MemMeter : public FieldMeterGraph { 18 | public: 19 | MemMeter( XOSView *parent ); 20 | ~MemMeter( void ); 21 | 22 | const char *name( void ) const { return "MemMeter"; } 23 | void checkevent( void ); 24 | 25 | void checkResources( void ); 26 | protected: 27 | 28 | void getmeminfo( void ); 29 | private: 30 | 31 | struct vm_statistics vmstats; 32 | }; 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /gnu/pagemeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1996, 2004 by Massimiliano Ghilardi ( ghilardi@cibs.sns.it ) 3 | // 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org ) 4 | // 5 | // This file may be distributed under terms of the GPL 6 | // 7 | 8 | #include "pagemeter.h" 9 | #include "xosview.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | extern "C" { 18 | #include 19 | #include 20 | } 21 | 22 | PageMeter::PageMeter( XOSView *parent, float max ) 23 | : FieldMeterGraph( parent, 3, "PAGE", "IN/OUT/IDLE" ) { 24 | for ( int i = 0 ; i < 2 ; i++ ) 25 | for ( int j = 0 ; j < 2 ; j++ ) 26 | pageinfo_[j][i] = 0; 27 | 28 | maxspeed_ = max; 29 | pageindex_ = 0; 30 | } 31 | 32 | PageMeter::~PageMeter( void ){ 33 | } 34 | 35 | void PageMeter::checkResources( void ){ 36 | FieldMeterGraph::checkResources(); 37 | 38 | setfieldcolor( 0, parent_->getResource( "pageInColor" ) ); 39 | setfieldcolor( 1, parent_->getResource( "pageOutColor" ) ); 40 | setfieldcolor( 2, parent_->getResource( "pageIdleColor" ) ); 41 | priority_ = atoi (parent_->getResource( "pagePriority" ) ); 42 | maxspeed_ *= priority_ / 10.0; 43 | dodecay_ = parent_->isResourceTrue( "pageDecay" ); 44 | useGraph_ = parent_->isResourceTrue( "pageGraph" ); 45 | SetUsedFormat (parent_->getResource("pageUsedFormat")); 46 | } 47 | 48 | void PageMeter::checkevent( void ){ 49 | getpageinfo(); 50 | drawfields(); 51 | } 52 | 53 | void PageMeter::updateinfo(void) 54 | { 55 | int oldindex = (pageindex_+1)%2; 56 | for ( int i = 0; i < 2; i++ ) 57 | { 58 | if ( pageinfo_[oldindex][i] == 0 ) 59 | pageinfo_[oldindex][i] = pageinfo_[pageindex_][i]; 60 | 61 | fields_[i] = pageinfo_[pageindex_][i] - pageinfo_[oldindex][i]; 62 | total_ += fields_[i]; 63 | } 64 | 65 | if ( total_ > maxspeed_ ) 66 | fields_[2] = 0.0; 67 | else 68 | { 69 | fields_[2] = maxspeed_ - total_; 70 | total_ = maxspeed_; 71 | } 72 | 73 | setUsed (total_ - fields_[2], maxspeed_); 74 | pageindex_ = (pageindex_ + 1) % 2; 75 | } 76 | 77 | void PageMeter::getpageinfo(void) { 78 | struct vm_statistics vmstats; 79 | 80 | total_ = 0; 81 | kern_return_t err; 82 | 83 | err = vm_statistics (mach_task_self(), &vmstats); 84 | if (err) { 85 | error (0, err, "vm_statistics"); 86 | parent_->done(1); 87 | return; 88 | } 89 | 90 | pageinfo_[pageindex_][0] = vmstats.pageins; 91 | pageinfo_[pageindex_][1] = vmstats.pageouts; 92 | 93 | updateinfo(); 94 | } 95 | -------------------------------------------------------------------------------- /gnu/pagemeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1996 by Massimiliano Ghilardi ( ghilardi@cibs.sns.it ) 3 | // 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org ) 4 | // 5 | // This file may be distributed under terms of the GPL 6 | // 7 | 8 | #ifndef _PAGEMETER_H_ 9 | #define _PAGEMETER_H_ 10 | 11 | #include "fieldmetergraph.h" 12 | 13 | class PageMeter : public FieldMeterGraph { 14 | public: 15 | PageMeter( XOSView *parent, float max ); 16 | ~PageMeter( void ); 17 | 18 | const char *name( void ) const { return "PageMeter"; } 19 | void checkevent( void ); 20 | 21 | void checkResources( void ); 22 | protected: 23 | float pageinfo_[2][2]; 24 | int pageindex_; 25 | float maxspeed_; 26 | 27 | void getpageinfo( void ); 28 | void updateinfo(void); 29 | private: 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /gnu/swapmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org ) 4 | // 5 | // This file may be distributed under terms of the GPL 6 | // 7 | 8 | #include "swapmeter.h" 9 | #include "xosview.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | extern "C" { 16 | #include 17 | #include 18 | #include 19 | #include "get_def_pager.h" 20 | } 21 | 22 | SwapMeter::SwapMeter( XOSView *parent ) 23 | : FieldMeterGraph( parent, 2, "SWAP", "ACTIVE/USED/FREE" ){ 24 | def_pager = MACH_PORT_NULL; 25 | } 26 | 27 | SwapMeter::~SwapMeter( void ){ 28 | } 29 | 30 | void SwapMeter::checkResources( void ){ 31 | FieldMeterGraph::checkResources(); 32 | 33 | setfieldcolor( 0, parent_->getResource( "swapUsedColor" ) ); 34 | setfieldcolor( 1, parent_->getResource( "swapFreeColor" ) ); 35 | priority_ = atoi (parent_->getResource( "swapPriority" ) ); 36 | dodecay_ = parent_->isResourceTrue( "swapDecay" ); 37 | useGraph_ = parent_->isResourceTrue( "swapGraph" ); 38 | SetUsedFormat (parent_->getResource("swapUsedFormat")); 39 | } 40 | 41 | void SwapMeter::checkevent( void ){ 42 | getswapinfo(); 43 | drawfields(); 44 | } 45 | 46 | 47 | void SwapMeter::getswapinfo( void ){ 48 | kern_return_t err; 49 | 50 | if (def_pager == MACH_PORT_NULL) 51 | def_pager = get_def_pager(); 52 | 53 | if (!MACH_PORT_VALID (def_pager)) { 54 | def_pager = MACH_PORT_DEAD; 55 | parent_->done(1); 56 | return; 57 | } 58 | 59 | err = default_pager_info (def_pager, &def_pager_info); 60 | if (err) { 61 | error (0, err, "default_pager_info"); 62 | parent_->done(1); 63 | return; 64 | } 65 | 66 | total_ = def_pager_info.dpi_total_space; 67 | fields_[1] = def_pager_info.dpi_free_space; 68 | fields_[0] = total_ - fields_[1]; 69 | 70 | if (total_) 71 | setUsed (fields_[0], total_); 72 | } 73 | -------------------------------------------------------------------------------- /gnu/swapmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org ) 4 | // 5 | // This file may be distributed under terms of the GPL 6 | // 7 | 8 | #ifndef _SWAPMETER_H_ 9 | #define _SWAPMETER_H_ 10 | 11 | 12 | #include "fieldmetergraph.h" 13 | 14 | extern "C" { 15 | #include 16 | #include 17 | } 18 | 19 | class SwapMeter : public FieldMeterGraph { 20 | public: 21 | SwapMeter( XOSView *parent ); 22 | ~SwapMeter( void ); 23 | 24 | const char *name( void ) const { return "SwapMeter"; } 25 | void checkevent( void ); 26 | 27 | void checkResources( void ); 28 | protected: 29 | 30 | void getswapinfo( void ); 31 | private: 32 | 33 | struct default_pager_info def_pager_info; 34 | mach_port_t def_pager; 35 | }; 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /hpux/MeterMaker.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #include "MeterMaker.h" 8 | #include "xosview.h" 9 | 10 | #include "cpumeter.h" 11 | #include "memmeter.h" 12 | #include "swapmeter.h" 13 | #include "loadmeter.h" 14 | #include "pagemeter.h" 15 | 16 | #include 17 | 18 | 19 | MeterMaker::MeterMaker(XOSView *xos){ 20 | _xos = xos; 21 | } 22 | 23 | void MeterMaker::makeMeters(void){ 24 | if (_xos->isResourceTrue("load")) 25 | push(new LoadMeter(_xos)); 26 | if (_xos->isResourceTrue("cpu")) 27 | push(new CPUMeter(_xos)); 28 | if (_xos->isResourceTrue("mem")) 29 | push(new MemMeter(_xos)); 30 | if (_xos->isResourceTrue("swap")) 31 | push(new SwapMeter(_xos)); 32 | 33 | if (_xos->isResourceTrue("page")) 34 | push(new PageMeter(_xos, atof(_xos->getResource("pageBandwidth")))); 35 | } 36 | -------------------------------------------------------------------------------- /hpux/MeterMaker.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _MeterMaker_h 8 | #define _MeterMaker_h 9 | 10 | #include "pllist.h" 11 | 12 | class Meter; 13 | class XOSView; 14 | 15 | class MeterMaker : public PLList { 16 | public: 17 | MeterMaker(XOSView *xos); 18 | 19 | void makeMeters(void); 20 | 21 | private: 22 | XOSView *_xos; 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /hpux/cpumeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #include "cpumeter.h" 8 | #include "xosview.h" 9 | #include 10 | #include 11 | 12 | CPUMeter::CPUMeter( XOSView *parent ) 13 | : FieldMeterGraph( parent, 5, "CPU", "USR/NICE/SYS/INT/FREE" ){ 14 | for ( int i = 0 ; i < 2 ; i++ ) 15 | for ( int j = 0 ; j < 5 ; j++ ) 16 | cputime_[i][j] = 0; 17 | cpuindex_ = 0; 18 | } 19 | 20 | CPUMeter::~CPUMeter( void ){ 21 | } 22 | 23 | void CPUMeter::checkResources( void ){ 24 | FieldMeterGraph::checkResources(); 25 | 26 | setfieldcolor( 0, parent_->getResource( "cpuUserColor" ) ); 27 | setfieldcolor( 1, parent_->getResource( "cpuNiceColor" ) ); 28 | setfieldcolor( 2, parent_->getResource( "cpuSystemColor" ) ); 29 | setfieldcolor( 3, parent_->getResource( "cpuInterruptColor" ) ); 30 | setfieldcolor( 4, parent_->getResource( "cpuFreeColor" ) ); 31 | priority_ = atoi (parent_->getResource( "cpuPriority" ) ); 32 | dodecay_ = parent_->isResourceTrue( "cpuDecay" ); 33 | useGraph_ = parent_->isResourceTrue( "cpuGraph" ); 34 | SetUsedFormat( parent_->getResource( "cpuUsedFormat" ) ); 35 | } 36 | 37 | void CPUMeter::checkevent( void ){ 38 | getcputime(); 39 | drawfields(); 40 | } 41 | 42 | void CPUMeter::getcputime( void ){ 43 | total_ = 0; 44 | struct pst_dynamic stats; 45 | 46 | pstat_getdynamic( &stats, sizeof( struct pst_dynamic ), 1, 0 ); 47 | 48 | cputime_[cpuindex_][0] = stats.psd_cpu_time[0]; 49 | cputime_[cpuindex_][1] = stats.psd_cpu_time[1]; 50 | cputime_[cpuindex_][2] = stats.psd_cpu_time[2]; 51 | cputime_[cpuindex_][3] = stats.psd_cpu_time[4]; 52 | cputime_[cpuindex_][4] = stats.psd_cpu_time[3]; 53 | 54 | int oldindex = (cpuindex_+1)%2; 55 | for ( int i = 0 ; i < 5 ; i++ ){ 56 | fields_[i] = cputime_[cpuindex_][i] - cputime_[oldindex][i]; 57 | total_ += fields_[i]; 58 | } 59 | cpuindex_ = (cpuindex_ + 1) % 2; 60 | 61 | if (total_){ 62 | setUsed( total_ - fields_[4], total_ ); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /hpux/cpumeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _CPUMETER_H_ 8 | #define _CPUMETER_H_ 9 | 10 | #include "fieldmetergraph.h" 11 | 12 | class CPUMeter : public FieldMeterGraph { 13 | public: 14 | CPUMeter( XOSView *parent ); 15 | ~CPUMeter( void ); 16 | 17 | const char *name( void ) const { return "CPUMeter"; } 18 | void checkevent( void ); 19 | 20 | void checkResources(void); 21 | protected: 22 | float cputime_[2][5]; 23 | int cpuindex_; 24 | 25 | void getcputime( void ); 26 | private: 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /hpux/loadmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 1997 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #include "loadmeter.h" 8 | #include "xosview.h" 9 | #include 10 | #include 11 | 12 | LoadMeter::LoadMeter( XOSView *parent ) 13 | : FieldMeterDecay( parent, 2, "LOAD", "PROCS/MIN", 1, 0 ){ 14 | } 15 | 16 | LoadMeter::~LoadMeter( void ){ 17 | } 18 | 19 | void LoadMeter::checkResources( void ){ 20 | FieldMeterDecay::checkResources(); 21 | 22 | warnloadcol_ = parent_->allocColor(parent_->getResource( "loadWarnColor" )); 23 | procloadcol_ = parent_->allocColor(parent_->getResource( "loadProcColor" )); 24 | 25 | setfieldcolor( 0, procloadcol_ ); 26 | setfieldcolor( 1, parent_->getResource( "loadIdleColor" ) ); 27 | priority_ = atoi (parent_->getResource( "loadPriority" ) ); 28 | dodecay_ = parent_->isResourceTrue( "loadDecay" ); 29 | SetUsedFormat( parent_->getResource( "loadUsedFormat" )); 30 | 31 | alarmThreshold = atoi (parent_->getResource("loadAlarmThreshold")); 32 | 33 | if (dodecay_){ 34 | // Warning: Since the loadmeter changes scale occasionally, old 35 | // decay values need to be rescaled. However, if they are rescaled, 36 | // they could go off the edge of the screen. Thus, for now, to 37 | // prevent this whole problem, the load meter can not be a decay 38 | // meter. The load is a decaying average kind of thing anyway, 39 | // so having a decaying load average is redundant. 40 | std::cerr << "Warning: The loadmeter can not be configured as a decay\n" 41 | << " meter. See the source code (" << __FILE__ << ") for further\n" 42 | << " details.\n"; 43 | dodecay_ = 0; 44 | } 45 | } 46 | 47 | void LoadMeter::checkevent( void ){ 48 | getloadinfo(); 49 | 50 | drawfields(); 51 | } 52 | 53 | 54 | void LoadMeter::getloadinfo( void ){ 55 | 56 | struct pst_dynamic pstd; 57 | 58 | pstat_getdynamic(&pstd, sizeof(pstd), 1, 0); 59 | 60 | fields_[0] = pstd.psd_avg_1_min; 61 | 62 | if ( fields_[0] > alarmThreshold ) { 63 | if (total_ == alarmThreshold ) { 64 | setfieldcolor( 0, warnloadcol_ ); 65 | drawlegend(); 66 | } 67 | total_ = fields_[1] = 20; 68 | } else { 69 | if (total_ == 20 ) { 70 | setfieldcolor( 0, procloadcol_ ); 71 | drawlegend(); 72 | } 73 | total_ = fields_[1] = alarmThreshold; 74 | } 75 | 76 | setUsed( fields_[0], total_ ); 77 | } 78 | -------------------------------------------------------------------------------- /hpux/loadmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 1997 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _LOADMETER_H_ 8 | #define _LOADMETER_H_ 9 | 10 | 11 | #include "fieldmeterdecay.h" 12 | 13 | class LoadMeter : public FieldMeterDecay { 14 | public: 15 | LoadMeter( XOSView *parent ); 16 | ~LoadMeter( void ); 17 | 18 | const char *name( void ) const { return "LoadMeter"; } 19 | void checkevent( void ); 20 | 21 | void checkResources( void ); 22 | protected: 23 | 24 | void getloadinfo( void ); 25 | unsigned long procloadcol_, warnloadcol_; 26 | private: 27 | int alarmThreshold; 28 | }; 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /hpux/memmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #include "memmeter.h" 8 | #include "xosview.h" 9 | #include 10 | #include 11 | 12 | MemMeter::MemMeter( XOSView *parent ) 13 | : FieldMeterDecay( parent, 4, "MEM", "TEXT/USED/OTHER/FREE" ){ 14 | struct pst_static pststatic; 15 | 16 | pstat_getstatic( &pststatic, sizeof( struct pst_static ), 1, 0); 17 | total_ = pststatic.physical_memory; 18 | _pageSize = (int)pststatic.page_size; 19 | 20 | stats_ = new struct pst_status[pststatic.max_proc]; 21 | } 22 | 23 | void MemMeter::checkResources( void ){ 24 | FieldMeterDecay::checkResources(); 25 | 26 | setfieldcolor( 0, parent_->getResource( "memTextColor" ) ); 27 | setfieldcolor( 1, parent_->getResource( "memUsedColor" ) ); 28 | setfieldcolor( 2, parent_->getResource( "memOtherColor" ) ); 29 | setfieldcolor( 3, parent_->getResource( "memFreeColor" ) ); 30 | priority_ = atoi (parent_->getResource( "memPriority" ) ); 31 | dodecay_ = parent_->isResourceTrue( "memDecay" ); 32 | SetUsedFormat( parent_->getResource( "memUsedFormat" ) ); 33 | } 34 | 35 | MemMeter::~MemMeter( void ){ 36 | delete[] stats_; 37 | } 38 | 39 | void MemMeter::checkevent( void ){ 40 | static int pass = 0; 41 | 42 | pass = (pass + 1)%5; 43 | if ( pass != 0 ) 44 | return; 45 | 46 | getmeminfo(); 47 | drawfields(); 48 | } 49 | 50 | void MemMeter::getmeminfo( void ){ 51 | struct pst_dynamic stats; 52 | 53 | pstat_getdynamic(&stats, sizeof( pst_dynamic ), 1, 0); 54 | 55 | struct pst_vminfo vmstats; 56 | pstat_getvminfo(&vmstats, sizeof(vmstats), 1, 0); 57 | 58 | fields_[0] = stats.psd_rmtxt + stats.psd_arm; 59 | fields_[1] = stats.psd_rm - stats.psd_rmtxt; 60 | fields_[2] = total_ - fields_[0] - fields_[1] - stats.psd_free; 61 | fields_[3] = stats.psd_free; 62 | 63 | FieldMeterDecay::setUsed( (total_ - fields_[3]) * _pageSize , 64 | total_ * _pageSize); 65 | } 66 | 67 | 68 | -------------------------------------------------------------------------------- /hpux/memmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _MEMMETER_H_ 8 | #define _MEMMETER_H_ 9 | 10 | #include "fieldmeterdecay.h" 11 | #include 12 | 13 | class MemMeter : public FieldMeterDecay { 14 | public: 15 | MemMeter( XOSView *parent ); 16 | ~MemMeter( void ); 17 | 18 | const char *name( void ) const { return "MemMeter"; } 19 | void checkevent( void ); 20 | 21 | void checkResources(void); 22 | 23 | protected: 24 | struct pst_status *stats_; 25 | int _pageSize; 26 | 27 | void getmeminfo( void ); 28 | private: 29 | }; 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /hpux/pagemeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1997 by Mike Romberg (romberg@fsl.noaa.gov) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #include "pagemeter.h" 8 | #include "xosview.h" 9 | #include 10 | #include 11 | 12 | PageMeter::PageMeter( XOSView *parent, float max ) 13 | : FieldMeterDecay( parent, 3, "PAGE", "IN/OUT/IDLE" ){ 14 | for ( int i = 0 ; i < 2 ; i++ ) 15 | for ( int j = 0 ; j < 2 ; j++ ) 16 | pageinfo_[j][i] = 0; 17 | 18 | maxspeed_ = max; 19 | pageindex_ = 0; 20 | } 21 | 22 | PageMeter::~PageMeter( void ){ 23 | } 24 | 25 | void PageMeter::checkResources( void ){ 26 | FieldMeterDecay::checkResources(); 27 | 28 | setfieldcolor( 0, parent_->getResource( "pageInColor" ) ); 29 | setfieldcolor( 1, parent_->getResource( "pageOutColor" ) ); 30 | setfieldcolor( 2, parent_->getResource( "pageIdleColor" ) ); 31 | priority_ = atoi (parent_->getResource( "pagePriority" ) ); 32 | maxspeed_ *= priority_ / 10.0; 33 | dodecay_ = parent_->isResourceTrue( "pageDecay" ); 34 | SetUsedFormat( parent_->getResource( "pageUsedFormat" ) ); 35 | } 36 | 37 | void PageMeter::checkevent( void ){ 38 | getpageinfo(); 39 | drawfields(); 40 | } 41 | 42 | void PageMeter::getpageinfo( void ){ 43 | 44 | struct pst_vminfo vminfo; 45 | pstat_getvminfo(&vminfo, sizeof(vminfo), 1, 0); 46 | 47 | total_ = 0; 48 | 49 | pageinfo_[pageindex_][0] = vminfo.psv_spgin; 50 | pageinfo_[pageindex_][1] = vminfo.psv_spgout; 51 | 52 | int oldindex = (pageindex_+1)%2; 53 | 54 | for ( int i = 0; i < 2; i++ ) { 55 | if ( pageinfo_[oldindex][i] == 0 ) 56 | pageinfo_[oldindex][i] = pageinfo_[pageindex_][i]; 57 | 58 | fields_[i] = pageinfo_[pageindex_][i] - pageinfo_[oldindex][i]; 59 | total_ += fields_[i]; 60 | } 61 | 62 | if ( total_ > maxspeed_ ) 63 | fields_[2] = 0.0; 64 | else { 65 | fields_[2] = maxspeed_ - total_; 66 | total_ = maxspeed_; 67 | } 68 | 69 | setUsed (total_ - fields_[2], maxspeed_ ); 70 | pageindex_ = (pageindex_ + 1) % 2; 71 | } 72 | -------------------------------------------------------------------------------- /hpux/pagemeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1997 by Mike Romberg (romberg@fsl.noaa.gov) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _PAGEMETER_H_ 8 | #define _PAGEMETER_H_ 9 | 10 | #include "fieldmeterdecay.h" 11 | 12 | class PageMeter : public FieldMeterDecay { 13 | public: 14 | PageMeter( XOSView *parent, float max ); 15 | ~PageMeter( void ); 16 | 17 | const char *name( void ) const { return "PageMeter"; } 18 | void checkevent( void ); 19 | 20 | void checkResources( void ); 21 | protected: 22 | float pageinfo_[2][2]; 23 | int pageindex_; 24 | float maxspeed_; 25 | 26 | void getpageinfo( void ); 27 | private: 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /hpux/swapmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #include "swapmeter.h" 8 | #include "xosview.h" 9 | #include 10 | #include 11 | 12 | static int MAX_SWAP_AREAS = 16; 13 | 14 | SwapMeter::SwapMeter( XOSView *parent ) 15 | : FieldMeterDecay( parent, 2, "SWAP", "USED/FREE" ){ 16 | } 17 | 18 | SwapMeter::~SwapMeter( void ){ 19 | } 20 | 21 | void SwapMeter::checkResources( void ){ 22 | FieldMeterDecay::checkResources(); 23 | 24 | setfieldcolor( 0, parent_->getResource( "swapUsedColor" ) ); 25 | setfieldcolor( 1, parent_->getResource( "swapFreeColor" ) ); 26 | priority_ = atoi(parent_->getResource( "swapPriority" ) ); 27 | dodecay_ = parent_->isResourceTrue( "swapDecay" ); 28 | SetUsedFormat( parent_->getResource( "swapUsedFormat" ) ); 29 | } 30 | 31 | void SwapMeter::checkevent( void ){ 32 | static int pass = 0; 33 | 34 | pass = (pass + 1)%5; 35 | if ( pass != 0 ) 36 | return; 37 | 38 | getswapinfo(); 39 | drawfields(); 40 | } 41 | 42 | void SwapMeter::getswapinfo( void ){ 43 | struct pst_swapinfo swapinfo; 44 | 45 | total_ = 0; 46 | fields_[1] = 0; 47 | 48 | for (int i = 0 ; i < MAX_SWAP_AREAS ; i++) 49 | { 50 | pstat_getswap(&swapinfo, sizeof(swapinfo), 1, i); 51 | if (swapinfo.pss_idx == (unsigned)i) 52 | { 53 | total_ += (swapinfo.pss_nblksenabled * 1024); 54 | fields_[1] += (swapinfo.pss_nfpgs * 4 * 1024); 55 | } 56 | } 57 | 58 | fields_[0] = total_ - fields_[1]; 59 | setUsed( fields_[0], total_ ); 60 | } 61 | -------------------------------------------------------------------------------- /hpux/swapmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _SWAPMETER_H_ 8 | #define _SWAPMETER_H_ 9 | 10 | #include "fieldmeterdecay.h" 11 | 12 | class SwapMeter : public FieldMeterDecay { 13 | public: 14 | SwapMeter( XOSView *parent ); 15 | ~SwapMeter( void ); 16 | 17 | const char *name( void ) const { return "SwapMeter"; } 18 | void checkevent( void ); 19 | void checkResources(void); 20 | 21 | protected: 22 | 23 | void getswapinfo( void ); 24 | private: 25 | }; 26 | 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /irix65/MeterMaker.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Stefan Eilemann (eilemann@gmail.com) 3 | // 4 | #include "MeterMaker.h" 5 | #include "xosview.h" 6 | 7 | #include "loadmeter.h" 8 | 9 | #include "cpumeter.h" 10 | #include "memmeter.h" 11 | #include "gfxmeter.h" 12 | #include "diskmeter.h" 13 | 14 | #include 15 | 16 | 17 | MeterMaker::MeterMaker(XOSView *xos) 18 | { 19 | _xos = xos; 20 | } 21 | 22 | void MeterMaker::makeMeters(void) 23 | { 24 | if (_xos->isResourceTrue("load")) 25 | push(new LoadMeter(_xos)); 26 | 27 | // Standard meters (usually added, but users could turn them off) 28 | if (_xos->isResourceTrue("cpu")) { 29 | bool any = false; 30 | const int cpuCount = CPUMeter::nCPUs(); 31 | 32 | if( strncmp( _xos->getResource("cpuFormat"), "single", 2) == 0 || 33 | strncmp( _xos->getResource("cpuFormat"), "both", 2) == 0 ) 34 | { 35 | push(new CPUMeter(_xos, -1)); 36 | any = true; 37 | } 38 | 39 | if( strncmp( _xos->getResource("cpuFormat"), "all", 2) == 0 || 40 | strncmp( _xos->getResource("cpuFormat"), "both", 2) == 0 ) 41 | { 42 | for (int i = 0 ; i < cpuCount ; i++) 43 | push(new CPUMeter(_xos, i)); 44 | any = true; 45 | } 46 | 47 | if( strncmp( _xos->getResource("cpuFormat"), "auto", 2) == 0 ) 48 | { 49 | push(new CPUMeter(_xos, -1)); 50 | 51 | if( cpuCount>1 ) 52 | for (int i = 0 ; i < cpuCount ; i++) 53 | push(new CPUMeter(_xos, i)); 54 | any = true; 55 | } 56 | 57 | if( !any ) 58 | { 59 | for (int i = 0 ; i < cpuCount ; i++) 60 | push(new CPUMeter(_xos, i)); 61 | } 62 | 63 | } 64 | 65 | 66 | if( _xos->isResourceTrue("gfx") && GfxMeter::nPipes() > 0 ) 67 | push(new GfxMeter( _xos, atoi( _xos->getResource( "gfxWarnThreshold" )))); 68 | 69 | if (_xos->isResourceTrue("mem")) 70 | push(new MemMeter(_xos)); 71 | 72 | } 73 | 74 | -------------------------------------------------------------------------------- /irix65/MeterMaker.h: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Stefan Eilemann (eilemann@gmail.com) 3 | // 4 | #ifndef _MeterMaker_h 5 | #define _MeterMaker_h 6 | 7 | #include "pllist.h" 8 | 9 | class Meter; 10 | class XOSView; 11 | 12 | class MeterMaker : public PLList { 13 | public: 14 | MeterMaker(XOSView *xos); 15 | 16 | void makeMeters(void); 17 | 18 | private: 19 | XOSView *_xos; 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /irix65/cpumeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Stefan Eilemann (eilemann@gmail.com) 3 | // 4 | #include "cpumeter.h" 5 | #include "xosview.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | CPUMeter::CPUMeter(XOSView *parent, int cpuid) 13 | : FieldMeterGraph(parent, USED_CPU_STATES, toUpper(cpuStr(cpuid)), 14 | "USER/SYS/INTR/WAIT/IDLE") 15 | { 16 | for (int i = 0 ; i < 2 ; i++) 17 | for (int j = 0 ; j < USED_CPU_STATES ; j++) 18 | cputime_[i][j] = 0; 19 | 20 | if ((sinfosz = sysmp(MP_SASZ, MPSA_SINFO)) < 0) { 21 | std::cerr << "sysinfo scall interface not supported" << endl; 22 | parent_->done(1); 23 | return; 24 | } 25 | cpuid_ = cpuid; 26 | cpuindex_ = 0; 27 | } 28 | 29 | CPUMeter::~CPUMeter(void) 30 | { 31 | } 32 | 33 | void CPUMeter::checkResources(void) 34 | { 35 | FieldMeterGraph::checkResources(); 36 | 37 | setfieldcolor(0, parent_->getResource("cpuUserColor")); 38 | setfieldcolor(1, parent_->getResource("cpuSystemColor")); 39 | setfieldcolor(2, parent_->getResource("cpuInterruptColor")); 40 | setfieldcolor(3, parent_->getResource("cpuWaitColor")); 41 | setfieldcolor(4, parent_->getResource("cpuFreeColor")); 42 | priority_ = atoi(parent_->getResource("cpuPriority")); 43 | dodecay_ = parent_->isResourceTrue("cpuDecay"); 44 | useGraph_ = parent_->isResourceTrue("cpuGraph"); 45 | SetUsedFormat(parent_->getResource("cpuUsedFormat")); 46 | } 47 | 48 | void CPUMeter::checkevent(void) 49 | { 50 | getcputime(); 51 | drawfields(); 52 | } 53 | 54 | void CPUMeter::getcputime(void) 55 | { 56 | total_ = 0; 57 | 58 | if(cpuid_==-1) 59 | sysmp(MP_SAGET, MPSA_SINFO, (char *) &tsp, sinfosz); 60 | else 61 | sysmp(MP_SAGET1, MPSA_SINFO, (char *) &tsp, sinfosz, cpuid_); 62 | 63 | tsp.cpu[CPU_WAIT] -= (tsp.wait[W_GFXF] + tsp.wait[W_GFXC]); 64 | 65 | cputime_[cpuindex_][0] = tsp.cpu[CPU_USER]; 66 | cputime_[cpuindex_][1] = tsp.cpu[CPU_KERNEL]; 67 | cputime_[cpuindex_][2] = tsp.cpu[CPU_INTR]; 68 | cputime_[cpuindex_][3] = tsp.cpu[CPU_WAIT]; 69 | cputime_[cpuindex_][4] = tsp.cpu[CPU_IDLE] + tsp.cpu[CPU_SXBRK]; 70 | 71 | int oldindex = (cpuindex_ + 1) % 2; 72 | for (int i = 0 ; i < USED_CPU_STATES ; i++) { 73 | fields_[i] = cputime_[cpuindex_][i] - cputime_[oldindex][i]; 74 | total_ += fields_[i]; 75 | } 76 | cpuindex_ = (cpuindex_ + 1) % 2; 77 | 78 | if (total_) 79 | setUsed(total_ - fields_[3] - fields_[4], total_); // wait doesn't count 80 | // as used 81 | } 82 | 83 | const char *CPUMeter::toUpper(const char *str) 84 | { 85 | static char buffer[256]; 86 | strncpy(buffer, str, 256); 87 | for (char *tmp = buffer ; *tmp != '\0' ; tmp++) 88 | *tmp = toupper(*tmp); 89 | 90 | return buffer; 91 | } 92 | 93 | const char *CPUMeter::cpuStr(int num) 94 | { 95 | static char buffer[32]; 96 | const int nCPU = nCPUs(); 97 | 98 | if( nCPU==1 || num==-1 ) 99 | { 100 | snprintf(buffer, 32, "CPU"); 101 | } 102 | else if( nCPU<=10 ) 103 | { 104 | snprintf(buffer, 32, "#%d", num); 105 | } 106 | else if ( nCPU<=100 ) 107 | { 108 | snprintf(buffer, 32, "#%02d", num); 109 | } 110 | else if ( nCPU<=1000 ) 111 | { 112 | snprintf(buffer, 32, "#%03d", num); 113 | } 114 | else 115 | { 116 | snprintf(buffer, 32, "%4.1d", num); 117 | } 118 | return buffer; 119 | } 120 | 121 | int CPUMeter::nCPUs() 122 | { 123 | return sysmp(MP_NPROCS); // FIXME: use NAPROCS + identify 'unused procs' 124 | } 125 | -------------------------------------------------------------------------------- /irix65/cpumeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Stefan Eilemann (eilemann@gmail.com) 3 | // 4 | #ifndef _CPUMETER_H_ 5 | #define _CPUMETER_H_ 6 | 7 | #include "fieldmetergraph.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #define USED_CPU_STATES (CPU_STATES-1) // SXBRK + IDLE merged 14 | 15 | class CPUMeter : public FieldMeterGraph { 16 | public: 17 | CPUMeter(XOSView *parent, const int cpuid = 0); 18 | ~CPUMeter(void); 19 | 20 | const char *name(void) const { return "CPUMeter"; } 21 | void checkevent(void); 22 | 23 | void checkResources(void); 24 | 25 | static int nCPUs(); 26 | static const char *cpuStr(int num); 27 | 28 | protected: 29 | time_t cputime_[2][USED_CPU_STATES]; 30 | int cpuindex_; 31 | 32 | void getcputime(void); 33 | const char *toUpper(const char *str); 34 | 35 | private: 36 | struct sysinfo tsp; 37 | int sinfosz; 38 | int cpuid_; 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /irix65/diskmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Stefan Eilemann (eilemann@gmail.com) 3 | // 4 | 5 | #include "diskmeter.h" 6 | #include "xosview.h" 7 | #include "sarmeter.h" 8 | 9 | #include 10 | 11 | 12 | DiskMeter::DiskMeter( XOSView *parent, float max ) : FieldMeterGraph( 13 | parent, 3, "DISK", "READ/WRITE/IDLE") 14 | { 15 | maxspeed_ = max; 16 | getdiskinfo(); 17 | } 18 | 19 | DiskMeter::~DiskMeter( void ) 20 | { 21 | } 22 | 23 | void DiskMeter::checkResources( void ) 24 | { 25 | FieldMeterGraph::checkResources(); 26 | 27 | setfieldcolor( 0, parent_->getResource("diskReadColor") ); 28 | setfieldcolor( 1, parent_->getResource("diskWriteColor") ); 29 | setfieldcolor( 2, parent_->getResource("diskIdleColor") ); 30 | priority_ = atoi (parent_->getResource( "diskPriority" ) ); 31 | dodecay_ = parent_->isResourceTrue("diskDecay" ); 32 | useGraph_ = parent_->isResourceTrue( "diskGraph" ); 33 | SetUsedFormat(parent_->getResource("diskUsedFormat")); 34 | } 35 | 36 | void DiskMeter::checkevent( void ) 37 | { 38 | getdiskinfo(); 39 | drawfields(); 40 | } 41 | 42 | void DiskMeter::getdiskinfo( void ) 43 | { 44 | SarMeter::DiskInfo *di = SarMeter::Instance()->getDiskInfo(); 45 | 46 | // new data 47 | total_ = maxspeed_; 48 | 49 | if (fields_[0] + fields_[1] > total_) 50 | total_ = fields_[0] + fields_[1]; 51 | 52 | fields_[2] = total_ - (fields_[0] + fields_[1]); 53 | 54 | setUsed((fields_[0]+fields_[1]), total_); 55 | IntervalTimerStart(); 56 | } 57 | 58 | -------------------------------------------------------------------------------- /irix65/diskmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Stefan Eilemann (eilemann@gmail.com) 3 | // 4 | 5 | #ifndef _DISKMETER_H_ 6 | #define _DISKMETER_H_ 7 | 8 | #include "fieldmetergraph.h" 9 | 10 | class DiskMeter : public FieldMeterGraph 11 | { 12 | public: 13 | DiskMeter( XOSView *parent, float max ); 14 | ~DiskMeter( void ); 15 | 16 | const char *name( void ) const { return "DiskMeter"; } 17 | void checkevent( void ); 18 | 19 | void checkResources( void ); 20 | protected: 21 | 22 | void getdiskinfo( void ); 23 | private: 24 | float maxspeed_; 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /irix65/gfxmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Stefan Eilemann (eilemann@gmail.com) 3 | // 4 | 5 | #include "gfxmeter.h" 6 | #include "xosview.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | // GfxMeter display swapbuffers per second. max is base rate for one gfx pipe. 16 | 17 | GfxMeter::GfxMeter(XOSView *parent, int max) 18 | : FieldMeterGraph(parent, 2, "GFX","SWAPBUF/S", 1, 1, 0 ) 19 | { 20 | lastalarmstate = -1; 21 | total_ = 0; 22 | _nPipes = nPipes(); 23 | total_ = _nPipes * max; 24 | 25 | if ( total_==0 ) { 26 | parent_->done(1); 27 | return; 28 | } 29 | } 30 | 31 | GfxMeter::~GfxMeter(void) 32 | { 33 | } 34 | 35 | int GfxMeter::nPipes(void) 36 | { 37 | int _nPipes = 0; 38 | 39 | setinvent(); 40 | for( inventory_t *inv = getinvent(); inv != NULL; inv = getinvent() ) 41 | { 42 | if ( inv->inv_class==INV_GRAPHICS ) 43 | { 44 | _nPipes++; 45 | } 46 | } 47 | return _nPipes; 48 | } 49 | 50 | void GfxMeter::checkResources(void) 51 | { 52 | FieldMeterGraph::checkResources(); 53 | 54 | swapgfxcol_ = parent_->allocColor(parent_->getResource( "gfxSwapColor" )); 55 | warngfxcol_ = parent_->allocColor(parent_->getResource( "gfxWarnColor" )); 56 | critgfxcol_ = parent_->allocColor(parent_->getResource( "gfxCritColor" )); 57 | 58 | setfieldcolor(0, parent_->getResource( "gfxSwapColor" )); 59 | setfieldcolor(1, parent_->getResource("gfxIdleColor")); 60 | priority_ = atoi (parent_->getResource("gfxPriority")); 61 | useGraph_ = parent_->isResourceTrue("gfxGraph"); 62 | dodecay_ = parent_->isResourceTrue( "gfxDecay" ); 63 | SetUsedFormat(parent_->getResource("gfxUsedFormat")); 64 | 65 | warnThreshold = atoi (parent_->getResource("gfxWarnThreshold")) * _nPipes; 66 | critThreshold = atoi (parent_->getResource("gfxCritThreshold")) * _nPipes; 67 | 68 | if (dodecay_){ 69 | // Warning: Since the gfxmeter changes scale occasionally, old 70 | // decay values need to be rescaled. However, if they are rescaled, 71 | // they could go off the edge of the screen. Thus, for now, to 72 | // prevent this whole problem, the gfx meter can not be a decay 73 | // meter. The gfx is a decaying average kind of thing anyway, 74 | // so having a decaying gfx average is redundant. 75 | std::cerr << "Warning: The gfxmeter can not be configured as a decay\n" 76 | << " meter. See the source code (" <<__FILE__<< ") for further\n" 77 | << " details.\n"; 78 | dodecay_ = 0; 79 | } 80 | } 81 | 82 | void GfxMeter::checkevent(void) 83 | { 84 | getgfxinfo(); 85 | drawfields(); 86 | } 87 | 88 | void GfxMeter::getgfxinfo(void) 89 | { 90 | SarMeter::GfxInfo *gi = SarMeter::Instance()->getGfxInfo(); 91 | 92 | fields_[0] = (float)gi->swapBuf; 93 | 94 | if ( fields_[0] < warnThreshold ) 95 | alarmstate = 0; 96 | else 97 | if ( fields_[0] >= critThreshold ) 98 | alarmstate = 2; 99 | else 100 | alarmstate = 1; 101 | 102 | if ( alarmstate != lastalarmstate ) 103 | { 104 | if ( alarmstate == 0 ) 105 | setfieldcolor( 0, swapgfxcol_ ); 106 | else 107 | if ( alarmstate == 1 ) 108 | setfieldcolor( 0, warngfxcol_ ); 109 | else 110 | setfieldcolor( 0, critgfxcol_ ); 111 | drawlegend(); 112 | lastalarmstate = alarmstate; 113 | } 114 | 115 | if ( fields_[0]*5.0total_ ) 119 | total_ = fields_[0]*5.0; 120 | 121 | if ( total_ < 1.0) 122 | total_ = 1.0; 123 | 124 | fields_[1] = (float) (total_ - fields_[0]); 125 | 126 | setUsed(fields_[0], (float) 1.0); 127 | } 128 | -------------------------------------------------------------------------------- /irix65/gfxmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Stefan Eilemann (eilemann@gmail.com) 3 | // 4 | 5 | #ifndef _GFXMETER_H_ 6 | #define _GFXMETER_H_ 7 | 8 | #include "sarmeter.h" 9 | 10 | #include 11 | 12 | class GfxMeter : public FieldMeterGraph 13 | { 14 | public: 15 | GfxMeter(XOSView *parent, int max); 16 | ~GfxMeter(void); 17 | 18 | const char *name(void) const { return "GfxMeter"; } 19 | void checkevent(void); 20 | 21 | void checkResources(void); 22 | 23 | static int nPipes( void ); 24 | protected: 25 | void getgfxinfo(void); 26 | 27 | unsigned long swapgfxcol_, warngfxcol_, critgfxcol_; 28 | 29 | private: 30 | int warnThreshold, critThreshold, alarmstate, lastalarmstate; 31 | int _nPipes; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /irix65/loadmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | // Most of this code was written by Werner Fink . 7 | // Only small changes were made on my part (M.R.) 8 | // Small changes for Irix 6.5 port Stefan Eilemann 9 | // 10 | 11 | #include "loadmeter.h" 12 | #include "xosview.h" 13 | #include 14 | #include 15 | #include 16 | 17 | #ifndef FSCALE 18 | #define FSCALE (1 << 8) 19 | #endif 20 | 21 | using namespace std; 22 | 23 | LoadMeter::LoadMeter(XOSView *parent) 24 | : FieldMeterGraph( parent, 2, "LOAD", "PROCS/MIN", 1, 1, 0 ) 25 | { 26 | lastalarmstate = -1; 27 | total_ = 2.0; 28 | 29 | if (gethostname (hostname, 255) != 0) { 30 | perror ("gethostname"); 31 | parent_->done(1); 32 | return; 33 | } 34 | } 35 | 36 | LoadMeter::~LoadMeter(void) 37 | { 38 | } 39 | 40 | void LoadMeter::checkResources(void) 41 | { 42 | FieldMeterGraph::checkResources(); 43 | 44 | procloadcol_ = parent_->allocColor(parent_->getResource( "loadProcColor" )); 45 | warnloadcol_ = parent_->allocColor(parent_->getResource( "loadWarnColor" )); 46 | critloadcol_ = parent_->allocColor(parent_->getResource( "loadCritColor" )); 47 | 48 | setfieldcolor(0, parent_->getResource( "loadProcColor" )); 49 | setfieldcolor(1, parent_->getResource("loadIdleColor")); 50 | priority_ = atoi (parent_->getResource("loadPriority")); 51 | useGraph_ = parent_->isResourceTrue("loadGraph"); 52 | dodecay_ = parent_->isResourceTrue( "loadDecay" ); 53 | SetUsedFormat(parent_->getResource("loadUsedFormat")); 54 | 55 | warnThreshold = atoi (parent_->getResource("loadWarnThreshold")); 56 | critThreshold = atoi (parent_->getResource("loadCritThreshold")); 57 | 58 | 59 | if (dodecay_){ 60 | // Warning: Since the loadmeter changes scale occasionally, old 61 | // decay values need to be rescaled. However, if they are rescaled, 62 | // they could go off the edge of the screen. Thus, for now, to 63 | // prevent this whole problem, the load meter can not be a decay 64 | // meter. The load is a decaying average kind of thing anyway, 65 | // so having a decaying load average is redundant. 66 | std::cerr << "Warning: The loadmeter can not be configured as a decay\n" 67 | << " meter. See the source code (" <<__FILE__<< ") for further\n" 68 | << " details.\n"; 69 | dodecay_ = 0; 70 | } 71 | } 72 | 73 | void LoadMeter::checkevent(void) 74 | { 75 | getloadinfo(); 76 | drawfields(); 77 | } 78 | 79 | void LoadMeter::getloadinfo(void) 80 | { 81 | if (rstat (hostname, &res) != 0) { 82 | std::cerr << hostname <= critThreshold ) 93 | alarmstate = 2; 94 | else 95 | alarmstate = 1; 96 | 97 | if ( alarmstate != lastalarmstate ) 98 | { 99 | if ( alarmstate == 0 ) 100 | setfieldcolor( 0, procloadcol_ ); 101 | else 102 | if ( alarmstate == 1 ) 103 | setfieldcolor( 0, warnloadcol_ ); 104 | else 105 | setfieldcolor( 0, critloadcol_ ); 106 | drawlegend(); 107 | lastalarmstate = alarmstate; 108 | } 109 | 110 | if ( fields_[0]*5.0total_ ) 114 | total_ = fields_[0]*5.0; 115 | 116 | if ( total_ < 1.0) 117 | total_ = 1.0; 118 | 119 | fields_[1] = (float) (total_ - fields_[0]); 120 | 121 | setUsed(fields_[0], (float) 1.0); 122 | } 123 | -------------------------------------------------------------------------------- /irix65/loadmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Stefan Eilemann (eilemann@gmail.com) 3 | // 4 | #ifndef _LOADMETER_H_ 5 | #define _LOADMETER_H_ 6 | 7 | #include "fieldmetergraph.h" 8 | #include 9 | 10 | class LoadMeter : public FieldMeterGraph { 11 | public: 12 | LoadMeter(XOSView *parent); 13 | ~LoadMeter(void); 14 | 15 | const char *name(void) const { return "LoadMeter"; } 16 | void checkevent(void); 17 | 18 | void checkResources(void); 19 | 20 | protected: 21 | void getloadinfo(void); 22 | 23 | unsigned long procloadcol_, warnloadcol_, critloadcol_; 24 | private: 25 | int warnThreshold, critThreshold, alarmstate, lastalarmstate; 26 | char hostname[256]; 27 | struct statstime res; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /irix65/memmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Stefan Eilemann (eilemann@gmail.com) 3 | // 4 | #include "memmeter.h" 5 | #include "xosview.h" 6 | #include 7 | #include 8 | #include 9 | 10 | MemMeter::MemMeter(XOSView *parent) 11 | : FieldMeterGraph(parent, 4, "MEM","KERNEL/FS/USER/FREE") 12 | { 13 | inventory_t *inv; 14 | _pageSize = getpagesize(); 15 | minfosz = sysmp(MP_SASZ, MPSA_RMINFO); 16 | 17 | total_ = 0; 18 | setinvent(); 19 | for( inv = getinvent(); inv != NULL; inv = getinvent() ) 20 | { 21 | if ( inv->inv_class==INV_MEMORY && inv->inv_type == INV_MAIN_MB ) 22 | { 23 | total_ = inv->inv_state*1024/_pageSize*1024; 24 | break; 25 | } 26 | } 27 | if ( total_==0 ) { 28 | parent_->done(1); 29 | return; 30 | } 31 | } 32 | 33 | void MemMeter::checkResources(void) 34 | { 35 | FieldMeterGraph::checkResources(); 36 | 37 | setfieldcolor(0, parent_->getResource("memKernelColor")); 38 | setfieldcolor(1, parent_->getResource("memCacheColor")); 39 | setfieldcolor(2, parent_->getResource("memUsedColor")); 40 | setfieldcolor(3, parent_->getResource("memFreeColor")); 41 | priority_ = atoi (parent_->getResource("memPriority")); 42 | dodecay_ = parent_->isResourceTrue("memDecay"); 43 | useGraph_ = parent_->isResourceTrue("memGraph"); 44 | SetUsedFormat(parent_->getResource("memUsedFormat")); 45 | } 46 | 47 | MemMeter::~MemMeter(void) 48 | { 49 | } 50 | 51 | void MemMeter::checkevent(void) 52 | { 53 | getmeminfo(); 54 | drawfields(); 55 | } 56 | 57 | void MemMeter::getmeminfo(void) 58 | { 59 | 60 | sysmp(MP_SAGET, MPSA_RMINFO, (char *) &mp, minfosz); 61 | 62 | fields_[0] = total_ - (mp.availrmem + mp.bufmem); 63 | 64 | fields_[1] = mp.bufmem + 65 | mp.dchunkpages + mp.dpages + 66 | mp.chunkpages - mp.dchunkpages; 67 | 68 | fields_[2] = mp.availrmem - 69 | (mp.freemem + mp.chunkpages + mp.dpages); 70 | 71 | fields_[3] = mp.freemem; 72 | 73 | FieldMeterDecay::setUsed( (fields_[0]+fields_[1]+fields_[2]) * _pageSize, 74 | total_ * _pageSize); 75 | } 76 | -------------------------------------------------------------------------------- /irix65/memmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Stefan Eilemann (eilemann@gmail.com) 3 | // 4 | #ifndef _MEMMETER_H_ 5 | #define _MEMMETER_H_ 6 | 7 | #include "fieldmetergraph.h" 8 | #include 9 | #include 10 | #include /* for SAGET and MINFO structures */ 11 | 12 | class MemMeter : public FieldMeterGraph { 13 | public: 14 | MemMeter(XOSView *parent); 15 | ~MemMeter(void); 16 | 17 | const char *name(void) const { return "MemMeter"; } 18 | void checkevent( void ); 19 | 20 | void checkResources(void); 21 | 22 | protected: 23 | // struct pst_status *stats_; 24 | int _pageSize; 25 | 26 | void getmeminfo( void ); 27 | 28 | private: 29 | struct rminfo mp; 30 | int minfosz; 31 | }; 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /irix65/sarmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Stefan Eilemann (eilemann@gmail.com) 3 | // 4 | 5 | #ifndef _SARMETER_H_ 6 | #define _SARMETER_H_ 7 | 8 | #include "fieldmetergraph.h" 9 | #include 10 | #include 11 | #include 12 | 13 | // some structs 14 | typedef struct { 15 | unsigned int recsize; 16 | unsigned int numrec; 17 | } 18 | header; 19 | 20 | typedef struct { 21 | char name[12]; 22 | char pad1[68]; 23 | struct iotime stat; 24 | char pad2[4]; 25 | } 26 | diskinfo; 27 | 28 | #define MAX_DISKS 16 29 | #define BUFSIZE 0x2000 30 | 31 | // common function for all sar based graphs 32 | class SarMeter 33 | { 34 | public: 35 | static SarMeter *Instance(); 36 | 37 | struct GfxInfo { 38 | unsigned int swapBuf; 39 | }; 40 | 41 | struct DiskInfo { 42 | unsigned int nDevices; 43 | 44 | unsigned int read[MAX_DISKS]; 45 | unsigned int write[MAX_DISKS]; 46 | }; 47 | 48 | GfxInfo *getGfxInfo( void ) 49 | { 50 | checkSadc(); 51 | return &_gi.info; 52 | } 53 | 54 | DiskInfo *getDiskInfo( void ) 55 | { 56 | checkSadc(); 57 | return &_di.info; 58 | } 59 | 60 | private: 61 | SarMeter(); 62 | ~SarMeter(void) {} 63 | 64 | int setupSadc( void ); 65 | 66 | void checkSadc( void ); 67 | 68 | bool readLine( void ); 69 | void parseBuffer( void ); 70 | void forwardBufferTo( char *ptr ); 71 | 72 | void newGfxInfo( void ); 73 | void newDiskInfo( void ); 74 | 75 | 76 | static SarMeter *_instance; 77 | int _input; 78 | off_t _bufSize; 79 | char _buf[BUFSIZE]; 80 | 81 | struct { 82 | gfxinfo current; 83 | gfxinfo last; 84 | GfxInfo info; 85 | } _gi; 86 | 87 | struct { 88 | diskinfo current[MAX_DISKS]; 89 | diskinfo last[MAX_DISKS]; 90 | DiskInfo info; 91 | } _di; 92 | }; 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /linux/MeterMaker.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _MeterMaker_h 8 | #define _MeterMaker_h 9 | 10 | #include "pllist.h" 11 | #include "meter.h" 12 | #include "xosview.h" 13 | 14 | 15 | class MeterMaker : public PLList { 16 | public: 17 | MeterMaker(XOSView *xos); 18 | 19 | void makeMeters(void); 20 | 21 | private: 22 | XOSView *_xos; 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /linux/acpitemp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 by Tomi Tapper 3 | // 4 | // File based on lmstemp.* by 5 | // Copyright (c) 2000, 2006 by Leopold Toetsch 6 | // 7 | // This file may be distributed under terms of the GPL 8 | // 9 | // 10 | // 11 | #ifndef _ACPITEMP_H_ 12 | #define _ACPITEMP_H_ 13 | 14 | 15 | #include "fieldmeter.h" 16 | #include "xosview.h" 17 | 18 | #define PATH_SIZE 128 19 | 20 | 21 | class ACPITemp : public FieldMeter { 22 | public: 23 | ACPITemp( XOSView *parent, const char *tempfile, const char *highfile, const char *label, const char * caption); 24 | ~ACPITemp( void ); 25 | 26 | const char *name( void ) const { return "ACPITemp"; } 27 | void checkevent( void ); 28 | 29 | void checkResources( void ); 30 | protected: 31 | 32 | void getacpitemp( void ); 33 | int checkacpi(const char* tempfile, const char* highfile); 34 | private: 35 | char _tempfile[PATH_SIZE]; 36 | char _highfile[PATH_SIZE]; 37 | int _high; 38 | bool _usesysfs; 39 | unsigned long _actcolor, _highcolor; 40 | }; 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /linux/btrymeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1997, 2005, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _BTRYMETER_H_ 8 | #define _BTRYMETER_H_ 9 | 10 | #include "fieldmeter.h" 11 | #include "xosview.h" 12 | #include 13 | 14 | 15 | class BtryMeter : public FieldMeter { 16 | public: 17 | BtryMeter( XOSView *parent ); 18 | ~BtryMeter( void ); 19 | 20 | const char *name( void ) const { return "BtryMeter"; } 21 | void checkevent( void ); 22 | 23 | void checkResources( void ); 24 | 25 | // some basic fields of 'info','alarm','state' 26 | // XXX: should be private 27 | struct acpi_batt { 28 | int alarm; // in mWh 29 | int design_capacity; // in mWh 30 | int last_full_capacity; // in mWh 31 | int charging_state; // charged=0,discharging=-1,charging=1 32 | int present_rate; // in mW, 0=unknown 33 | int remaining_capacity; // in mW 34 | }; 35 | acpi_batt battery; 36 | 37 | static bool has_source( void ); 38 | protected: 39 | 40 | void getpwrinfo( void ); 41 | private: 42 | 43 | bool getapminfo( void ); 44 | bool getacpi_or_sys_info( void ); 45 | 46 | bool use_apm; 47 | bool use_acpi; 48 | bool use_syspower; 49 | 50 | bool acpi_battery_present(const std::string& filename); 51 | bool acpi_parse_battery(const std::string& filename); 52 | bool sys_battery_present(const std::string& filename); 53 | bool sys_parse_battery(const std::string& filename); 54 | 55 | static bool has_acpi(void); 56 | static bool has_apm(void); 57 | static bool has_syspower(void); 58 | 59 | void handle_apm_state(void); 60 | void handle_acpi_state(void); 61 | 62 | int apm_battery_state; 63 | int old_apm_battery_state; 64 | 65 | int acpi_charge_state; 66 | int old_acpi_charge_state; 67 | 68 | int acpi_sum_cap; 69 | int acpi_sum_remain; 70 | int acpi_sum_rate; 71 | int acpi_sum_alarm; 72 | 73 | }; 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /linux/coretemp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2008-2014 by Tomi Tapper 3 | // 4 | // File based on linux/lmstemp.* by 5 | // Copyright (c) 2000, 2006 by Leopold Toetsch 6 | // 7 | // This file may be distributed under terms of the GPL 8 | // 9 | // 10 | 11 | #ifndef _CORETEMP_H_ 12 | #define _CORETEMP_H_ 13 | 14 | #include "fieldmeter.h" 15 | #include "xosview.h" 16 | #include 17 | #include 18 | 19 | 20 | class CoreTemp : public FieldMeter { 21 | public: 22 | CoreTemp( XOSView *parent, const char *label, const char *caption, int pkg, int cpu); 23 | ~CoreTemp( void ); 24 | 25 | const char *name( void ) const { return "CoreTemp"; } 26 | void checkevent( void ); 27 | void checkResources( void ); 28 | 29 | static unsigned int countCores( unsigned int pkg ); 30 | static unsigned int countCpus( void ); 31 | 32 | protected: 33 | void getcoretemp( void ); 34 | 35 | private: 36 | void findSysFiles( void ); 37 | int _pkg, _cpu, _high; 38 | std::vector _cpus; 39 | unsigned long _actcolor, _highcolor; 40 | }; 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /linux/cpumeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2004, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _CPUMETER_H_ 8 | #define _CPUMETER_H_ 9 | 10 | #include "fieldmetergraph.h" 11 | #include "xosview.h" 12 | 13 | 14 | class CPUMeter : public FieldMeterGraph { 15 | public: 16 | CPUMeter(XOSView *parent, const char *cpuID = "cpu"); 17 | ~CPUMeter(void); 18 | 19 | const char *name(void) const { return "CPUMeter"; } 20 | void checkevent(void); 21 | 22 | void checkResources(void); 23 | 24 | static int countCPUs(void); 25 | static const char *cpuStr(int num); 26 | static int getkernelversion(void); 27 | protected: 28 | int _lineNum; 29 | unsigned long long cputime_[2][10]; 30 | int cpuindex_; 31 | int kernel_; 32 | int statfields_; 33 | 34 | void getcputime(void); 35 | int findLine(const char *cpuID); 36 | const char *toUpper(const char *str); 37 | private: 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /linux/diskmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1999, 2006 by Mike Romberg (mike.romberg@noaa.gov) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _DISKMETER_H_ 8 | #define _DISKMETER_H_ 9 | 10 | #include "fieldmetergraph.h" 11 | #include "xosview.h" 12 | #include 13 | #include 14 | 15 | typedef std::map diskmap; 16 | 17 | 18 | class DiskMeter : public FieldMeterGraph 19 | { 20 | public: 21 | DiskMeter( XOSView *parent, float max ); 22 | ~DiskMeter( void ); 23 | 24 | const char *name( void ) const { return "DiskMeter"; } 25 | void checkevent( void ); 26 | 27 | void checkResources( void ); 28 | protected: 29 | 30 | // sysfs: 31 | void update_info(const diskmap &reads, const diskmap &writes); 32 | void getsysfsdiskinfo( void ); 33 | 34 | void getdiskinfo( void ); 35 | void getvmdiskinfo( void ); 36 | void updateinfo(unsigned long one, unsigned long two, 37 | int fudgeFactor); 38 | private: 39 | 40 | // sysfs: 41 | diskmap sysfs_read_prev_, sysfs_write_prev_; 42 | bool _sysfs; 43 | 44 | unsigned long int read_prev_; 45 | unsigned long int write_prev_; 46 | float maxspeed_; 47 | bool _vmstat; 48 | const char *_statFileName; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /linux/intmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _INTMETER_H_ 8 | #define _INTMETER_H_ 9 | 10 | #include "bitmeter.h" 11 | #include "xosview.h" 12 | #include "cpumeter.h" 13 | 14 | 15 | class IntMeter : public BitMeter { 16 | public: 17 | IntMeter( XOSView *parent, int cpu = 0 ); 18 | ~IntMeter( void ); 19 | 20 | void checkevent( void ); 21 | void checkResources( void ); 22 | static int countCPUs( void ) { return CPUMeter::countCPUs(); } 23 | 24 | private: 25 | unsigned long *_irqs, *_lastirqs; 26 | int _cpu; 27 | bool _separate; 28 | 29 | void getirqs( void ); 30 | void updateirqcount( int n, bool init ); 31 | void initirqcount( void ); 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /linux/intratemeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 by Tomi Tapper (tomi.o.tapper@jyu.fi) 3 | // 4 | // Based on bsd/intratemeter.* by 5 | // Copyright (c) 1999 by Brian Grayson (bgrayson@netbsd.org) 6 | // and on linux/intmeter.* by 7 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 8 | // 9 | // This file may be distributed under terms of the GPL 10 | // 11 | 12 | #include "intratemeter.h" 13 | #include "cpumeter.h" 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | static const char *INTFILE = "/proc/interrupts"; 20 | 21 | 22 | IrqRateMeter::IrqRateMeter( XOSView *parent ) 23 | : FieldMeterGraph( parent, 2, "IRQs", "IRQs per sec/IDLE", 1, 1, 0 ) { 24 | _lastirqs = 0; 25 | _cpucount = CPUMeter::countCPUs(); 26 | } 27 | 28 | IrqRateMeter::~IrqRateMeter( void ) { 29 | } 30 | 31 | void IrqRateMeter::checkResources( void ) { 32 | FieldMeterGraph::checkResources(); 33 | setfieldcolor( 0, parent_->getResource("irqrateUsedColor") ); 34 | setfieldcolor( 1, parent_->getResource("irqrateIdleColor") ); 35 | priority_ = atoi( parent_->getResource("irqratePriority") ); 36 | dodecay_ = parent_->isResourceTrue("irqrateDecay"); 37 | useGraph_ = parent_->isResourceTrue("irqrateGraph"); 38 | SetUsedFormat( parent_->getResource("irqrateUsedFormat") ); 39 | total_ = 2000; 40 | } 41 | 42 | void IrqRateMeter::checkevent( void ) { 43 | getinfo(); 44 | drawfields(); 45 | } 46 | 47 | void IrqRateMeter::getinfo( void ) { 48 | std::ifstream intfile(INTFILE); 49 | std::string line; 50 | unsigned long long count = 0; 51 | unsigned long tmp; 52 | const char *cur = NULL; 53 | char *end = NULL; 54 | 55 | if (!intfile) { 56 | std::cerr << "Can not open file : " << INTFILE << std::endl; 57 | parent_->done(1); 58 | return; 59 | } 60 | 61 | IntervalTimerStop(); 62 | intfile.ignore(1024, '\n'); 63 | 64 | // sum all interrupts on all cpus 65 | while ( !intfile.eof() ) { 66 | unsigned int i = 0; 67 | std::getline(intfile, line); 68 | if ( line.find_first_of("0123456789") > line.find_first_of(':') ) 69 | break; // reached non-numeric interrupts 70 | tmp = strtoul(line.c_str(), &end, 10); 71 | cur = end + 1; 72 | while (*cur && i++ < _cpucount) { 73 | tmp = strtoul(cur, &end, 10); 74 | count += tmp; 75 | cur = end; 76 | } 77 | } 78 | if (_lastirqs == 0) // first run 79 | _lastirqs = count; 80 | fields_[0] = (count - _lastirqs) / IntervalTimeInSecs(); 81 | IntervalTimerStart(); 82 | _lastirqs = count; 83 | 84 | // Bump total, if needed. 85 | if (fields_[0] > total_) 86 | total_ = fields_[0]; 87 | 88 | setUsed(fields_[0], total_); 89 | } 90 | -------------------------------------------------------------------------------- /linux/intratemeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 by Tomi Tapper (tomi.o.tapper@jyu.fi) 3 | // 4 | // Based on bsd/intratemeter.* by 5 | // Copyright (c) 1999 by Brian Grayson (bgrayson@netbsd.org) 6 | // and on linux/intmeter.* by 7 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 8 | // 9 | // This file may be distributed under terms of the GPL 10 | // 11 | 12 | #ifndef _IRQRATEMETER_H_ 13 | #define _IRQRATEMETER_H_ 14 | 15 | #include "fieldmetergraph.h" 16 | #include "xosview.h" 17 | 18 | 19 | class IrqRateMeter : public FieldMeterGraph { 20 | public: 21 | IrqRateMeter( XOSView *parent ); 22 | ~IrqRateMeter( void ); 23 | 24 | const char *name( void ) const { return "IrqRateMeter"; } 25 | void checkevent( void ); 26 | void checkResources( void ); 27 | 28 | protected: 29 | void getinfo( void ); 30 | 31 | private: 32 | unsigned long long _lastirqs; 33 | unsigned int _cpucount; 34 | }; 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /linux/lmstemp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000, 2006 by Leopold Toetsch 3 | // 4 | // File based on btrymeter.* by 5 | // Copyright (c) 1997 by Mike Romberg ( mike.romberg@noaa.gov ) 6 | // 7 | // This file may be distributed under terms of the GPL 8 | // 9 | // 10 | // 11 | #ifndef _LMSTEMP_H_ 12 | #define _LMSTEMP_H_ 13 | 14 | #include "sensorfieldmeter.h" 15 | #include "xosview.h" 16 | #include 17 | 18 | 19 | class LmsTemp : public SensorFieldMeter { 20 | public: 21 | LmsTemp( XOSView *parent, const char *name, const char *tempfile, 22 | const char *highfile, const char *lowfile, const char *label, 23 | const char *caption, unsigned int nbr ); 24 | ~LmsTemp( void ); 25 | 26 | const char *name( void ) const { return "LmsTemp"; } 27 | void checkevent( void ); 28 | void checkResources( void ); 29 | 30 | protected: 31 | void getlmstemp( void ); 32 | bool checksensors( const char *name, const char *tempfile, 33 | const char *highfile, const char *lowfile ); 34 | private: 35 | void determineScale( void ); 36 | void determineUnit( void ); 37 | std::string _tempfile, _highfile, _lowfile; 38 | unsigned int _nbr; 39 | double _scale; 40 | bool _isproc, _name_found, _temp_found, _high_found, _low_found; 41 | }; 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /linux/loadmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | // Most of this code was written by Werner Fink 7 | // Only small changes were made on my part (M.R.) 8 | // 9 | 10 | #ifndef _LOADMETER_H_ 11 | #define _LOADMETER_H_ 12 | 13 | #include "fieldmetergraph.h" 14 | #include "xosview.h" 15 | 16 | 17 | class LoadMeter : public FieldMeterGraph { 18 | public: 19 | LoadMeter( XOSView *parent ); 20 | ~LoadMeter( void ); 21 | 22 | const char *name( void ) const { return "LoadMeter"; } 23 | void checkevent( void ); 24 | 25 | void checkResources( void ); 26 | protected: 27 | 28 | void getloadinfo( void ); 29 | unsigned long procloadcol_, warnloadcol_, critloadcol_; 30 | void getspeedinfo( void ); 31 | 32 | private: 33 | int warnThreshold, critThreshold, alarmstate, lastalarmstate; 34 | int old_cpu_speed_, cur_cpu_speed_; 35 | int do_cpu_speed; 36 | }; 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /linux/memmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // Copyright (c) 2015 Framestore 4 | // 5 | // This file may be distributed under terms of the GPL 6 | // 7 | 8 | #include "memmeter.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define MEMFILENAME "/proc/meminfo" 15 | 16 | #define KB(x) ((double)((x) * 1024)) 17 | 18 | 19 | MemMeter::MemMeter( XOSView *parent ) 20 | : FieldMeterGraph( parent, 5, "MEM", "USED/BUFF/SLAB/CACHE/FREE" ){ 21 | } 22 | 23 | void MemMeter::checkResources( void ){ 24 | FieldMeterGraph::checkResources(); 25 | 26 | setfieldcolor( 0, parent_->getResource( "memUsedColor" ) ); 27 | setfieldcolor( 1, parent_->getResource( "memBufferColor" ) ); 28 | setfieldcolor( 2, parent_->getResource( "memSlabColor" ) ); 29 | setfieldcolor( 3, parent_->getResource( "memCacheColor" ) ); 30 | setfieldcolor( 4, parent_->getResource( "memFreeColor" ) ); 31 | priority_ = atoi (parent_->getResource( "memPriority" ) ); 32 | dodecay_ = parent_->isResourceTrue( "memDecay" ); 33 | useGraph_ = parent_->isResourceTrue( "memGraph" ); 34 | SetUsedFormat (parent_->getResource("memUsedFormat")); 35 | } 36 | 37 | void MemMeter::checkevent( void ){ 38 | getstats(); 39 | drawfields(); 40 | } 41 | 42 | void MemMeter::getstats() { 43 | FILE *f; 44 | 45 | f = fopen(MEMFILENAME, "r"); 46 | if (!f) { 47 | perror(MEMFILENAME); 48 | exit(1); 49 | } 50 | 51 | /* 52 | * The kernel's "unsigned long" values vary in size on 64-bit and 53 | * 32-bit implementations. 54 | * 55 | * But there's nothing saying userland will match the kernel; we 56 | * must pretty much accomodate anything in ASCII that /proc gives 57 | * us, so 64-bit integers are always used. 58 | */ 59 | 60 | unsigned long long mem_total = 0, 61 | mem_free = 0, 62 | buffers = 0, 63 | slab = 0, 64 | cached = 0; 65 | 66 | for (;;) { 67 | char line[128]; 68 | char *c, *endptr; 69 | unsigned long long kb = 0; 70 | 71 | /* 72 | * Parse lines in the format: "FieldName: 12345678 kB" 73 | * 74 | * We prefer to not use scanf because it's harder with variable 75 | * number of fields; the 'kB' is not present if value is 0 76 | */ 77 | 78 | if (!fgets(line, sizeof line, f)) 79 | break; 80 | 81 | c = strchr(line, ':'); 82 | if (!c) { 83 | fprintf(stderr, MEMFILENAME ": parse error, ':' expected at '%s'\n", line); 84 | exit(1); 85 | } 86 | 87 | *c = '\0'; 88 | c++; 89 | 90 | kb = strtoull(c, &endptr, 10); 91 | if (kb == ULLONG_MAX) { 92 | fprintf(stderr, MEMFILENAME ": parse error, '%s' is out of range\n", c); 93 | exit(1); 94 | } 95 | 96 | if (strcmp(line, "MemTotal") == 0) 97 | mem_total = kb; 98 | else if (strcmp(line, "MemFree") == 0) 99 | mem_free = kb; 100 | else if (strcmp(line, "Buffers") == 0) 101 | buffers = kb; 102 | else if (strcmp(line, "Cached") == 0) 103 | cached = kb; 104 | else if (strcmp(line, "Slab") == 0) 105 | slab = kb; 106 | } 107 | 108 | if (fclose(f) != 0) 109 | abort(); 110 | 111 | /* Don't do arithmetic on the fields_ themselves; these are floating 112 | * point and when memory is large are affected by inaccuracy */ 113 | 114 | fields_[1] = KB(buffers); 115 | fields_[2] = KB(slab); 116 | fields_[3] = KB(cached); 117 | fields_[4] = KB(mem_free); 118 | 119 | fields_[0] = KB(mem_total - mem_free - buffers - cached - slab); 120 | total_ = KB(mem_total); 121 | 122 | setUsed(KB(mem_total - mem_free), KB(mem_total)); 123 | } 124 | -------------------------------------------------------------------------------- /linux/memmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _MEMMETER_H_ 8 | #define _MEMMETER_H_ 9 | 10 | #include "fieldmetergraph.h" 11 | #include "xosview.h" 12 | #include 13 | 14 | 15 | class MemMeter : public FieldMeterGraph { 16 | public: 17 | MemMeter( XOSView *parent ); 18 | 19 | const char *name( void ) const { return "MemMeter"; } 20 | void checkevent( void ); 21 | void checkResources( void ); 22 | 23 | private: 24 | void getstats( void ); 25 | }; 26 | 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /linux/netmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _NETMETER_H_ 8 | #define _NETMETER_H_ 9 | 10 | #include "fieldmetergraph.h" 11 | #include "xosview.h" 12 | #include 13 | 14 | 15 | class NetMeter : public FieldMeterGraph { 16 | public: 17 | NetMeter(XOSView *parent, float max); 18 | ~NetMeter( void ); 19 | 20 | const char *name( void ) const { return "NetMeter"; } 21 | void checkevent( void ); 22 | void checkResources( void ); 23 | 24 | private: 25 | void getProcStats( unsigned long long &totin, unsigned long long &totout ); 26 | void getSysStats( unsigned long long &totin, unsigned long long &totout ); 27 | float _maxpackets; 28 | std::string _netIface; 29 | bool _usesysfs, _ignored; 30 | unsigned long long _lastBytesIn, _lastBytesOut; 31 | }; 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /linux/nfsmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // This file may be distributed under terms of the GPL 4 | // 5 | 6 | #ifndef _NFSMETER_H_ 7 | #define _NFSMETER_H_ 8 | 9 | #include "fieldmetergraph.h" 10 | #include "xosview.h" 11 | #include "timer.h" 12 | 13 | 14 | class NFSMeter : public FieldMeterGraph { 15 | public: 16 | NFSMeter( 17 | XOSView *parent, 18 | const char *name, 19 | int nfields, 20 | const char *files, 21 | const char *statfile); 22 | ~NFSMeter( void ); 23 | 24 | const char *name( void ) const { return _statname; } 25 | void checkResources( void ); 26 | void starttimer(void) { return _timer.start(); }; 27 | void stoptimer(void) { return _timer.stop(); }; 28 | double usecs(void) { return _timer.report_usecs(); }; 29 | 30 | protected: 31 | const char *_statname; 32 | const char *_statfile; 33 | 34 | private: 35 | Timer _timer; 36 | 37 | }; 38 | 39 | class NFSStats : public NFSMeter { 40 | public: 41 | NFSStats(XOSView *parent); 42 | ~NFSStats(void); 43 | 44 | void checkevent( void ); 45 | 46 | void checkResources( void ); 47 | private: 48 | unsigned long _lastcalls, _lastretrns, _lastauthrefresh; 49 | }; 50 | 51 | class NFSDStats : public NFSMeter { 52 | public: 53 | NFSDStats(XOSView *parent); 54 | ~NFSDStats(void); 55 | 56 | void checkevent( void ); 57 | 58 | void checkResources( void ); 59 | 60 | protected: 61 | float maxpackets_; 62 | 63 | private: 64 | unsigned long _lastTcp, _lastUdp, _lastNetCnt, _lastBad; 65 | }; 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /linux/pagemeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1996, 2004 by Massimiliano Ghilardi ( ghilardi@cibs.sns.it ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #include "pagemeter.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #define MAX_PROCSTAT_LENGTH 4096 16 | 17 | 18 | PageMeter::PageMeter( XOSView *parent, float max ) 19 | : FieldMeterGraph( parent, 3, "PAGE", "IN/OUT/IDLE" ), 20 | _vmstat(false), _statFileName("/proc/stat"){ 21 | for ( int i = 0 ; i < 2 ; i++ ) 22 | for ( int j = 0 ; j < 2 ; j++ ) 23 | pageinfo_[j][i] = 0; 24 | 25 | maxspeed_ = max; 26 | pageindex_ = 0; 27 | 28 | struct stat buf; 29 | if (stat("/proc/vmstat", &buf) == 0 30 | && buf.st_mode & S_IFREG) 31 | { 32 | _vmstat = true; 33 | _statFileName = "/proc/vmstat"; 34 | } 35 | } 36 | 37 | PageMeter::~PageMeter( void ){ 38 | } 39 | 40 | void PageMeter::checkResources( void ){ 41 | FieldMeterGraph::checkResources(); 42 | 43 | setfieldcolor( 0, parent_->getResource( "pageInColor" ) ); 44 | setfieldcolor( 1, parent_->getResource( "pageOutColor" ) ); 45 | setfieldcolor( 2, parent_->getResource( "pageIdleColor" ) ); 46 | priority_ = atoi (parent_->getResource( "pagePriority" ) ); 47 | maxspeed_ *= priority_ / 10.0; 48 | dodecay_ = parent_->isResourceTrue( "pageDecay" ); 49 | useGraph_ = parent_->isResourceTrue( "pageGraph" ); 50 | SetUsedFormat (parent_->getResource("pageUsedFormat")); 51 | } 52 | 53 | void PageMeter::checkevent( void ){ 54 | if (_vmstat) 55 | getvmpageinfo(); 56 | else 57 | getpageinfo(); 58 | drawfields(); 59 | } 60 | 61 | void PageMeter::updateinfo(void) 62 | { 63 | int oldindex = (pageindex_+1)%2; 64 | for ( int i = 0; i < 2; i++ ) 65 | { 66 | if ( pageinfo_[oldindex][i] == 0 ) 67 | pageinfo_[oldindex][i] = pageinfo_[pageindex_][i]; 68 | 69 | fields_[i] = pageinfo_[pageindex_][i] - pageinfo_[oldindex][i]; 70 | total_ += fields_[i]; 71 | } 72 | 73 | if ( total_ > maxspeed_ ) 74 | fields_[2] = 0.0; 75 | else 76 | { 77 | fields_[2] = maxspeed_ - total_; 78 | total_ = maxspeed_; 79 | } 80 | 81 | setUsed (total_ - fields_[2], maxspeed_); 82 | pageindex_ = (pageindex_ + 1) % 2; 83 | } 84 | 85 | void PageMeter::getvmpageinfo(void) 86 | { 87 | total_ = 0; 88 | char buf[MAX_PROCSTAT_LENGTH]; 89 | bool found_in = false, found_out = false; 90 | std::ifstream stats(_statFileName); 91 | if (!stats) 92 | { 93 | std::cerr <<"Cannot open file : " << _statFileName << std::endl; 94 | exit(1); 95 | } 96 | while (!stats.eof() && !(found_in && found_out)) 97 | { 98 | stats.getline(buf, MAX_PROCSTAT_LENGTH); 99 | if (!strncmp(buf, "pswpin", 6)) 100 | { 101 | pageinfo_[pageindex_][0] = strtoul(buf+7, NULL, 10); 102 | found_in = true; 103 | } 104 | if (!strncmp(buf, "pswpout", 7)) 105 | { 106 | pageinfo_[pageindex_][1] = strtoul(buf+8, NULL, 10); 107 | found_out = true; 108 | } 109 | } 110 | updateinfo(); 111 | } 112 | 113 | void PageMeter::getpageinfo( void ){ 114 | total_ = 0; 115 | char buf[MAX_PROCSTAT_LENGTH]; 116 | std::ifstream stats(_statFileName); 117 | 118 | if ( !stats ){ 119 | std::cerr <<"Cannot open file : " << _statFileName << std::endl; 120 | exit( 1 ); 121 | } 122 | 123 | do { 124 | stats >>buf; 125 | } while (!stats.eof() && strncasecmp(buf, "swap", 5)); 126 | 127 | stats >>pageinfo_[pageindex_][0] >>pageinfo_[pageindex_][1]; 128 | 129 | updateinfo(); 130 | } 131 | -------------------------------------------------------------------------------- /linux/pagemeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1996, 2007 by Massimiliano Ghilardi ( ghilardi@cibs.sns.it ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _PAGEMETER_H_ 8 | #define _PAGEMETER_H_ 9 | 10 | #include "fieldmetergraph.h" 11 | #include "xosview.h" 12 | 13 | 14 | class PageMeter : public FieldMeterGraph { 15 | public: 16 | PageMeter( XOSView *parent, float max ); 17 | ~PageMeter( void ); 18 | 19 | const char *name( void ) const { return "PageMeter"; } 20 | void checkevent( void ); 21 | 22 | void checkResources( void ); 23 | protected: 24 | unsigned long pageinfo_[2][2]; 25 | int pageindex_; 26 | float maxspeed_; 27 | bool _vmstat; 28 | const char *_statFileName; 29 | 30 | void getpageinfo( void ); 31 | void getvmpageinfo( void ); 32 | void updateinfo(void); 33 | private: 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /linux/raidmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1999, 2006 Thomas Waldmann ( ThomasWaldmann@gmx.de ) 3 | // based on work of Mike Romberg ( mike.romberg@noaa.gov ) 4 | // 5 | // This file may be distributed under terms of the GPL 6 | // 7 | #ifndef _RAIDMETER_H_ 8 | #define _RAIDMETER_H_ 9 | 10 | #include "bitfieldmeter.h" 11 | #include "xosview.h" 12 | 13 | #define MAX_MD 8 14 | 15 | class RAIDMeter : public BitFieldMeter { 16 | public: 17 | RAIDMeter( XOSView *parent, int raiddev = 0); 18 | ~RAIDMeter( void ); 19 | 20 | void checkevent( void ); 21 | 22 | void checkResources( void ); 23 | 24 | static int countRAIDs( void ); 25 | 26 | protected: 27 | 28 | int _raiddev; 29 | static int mdnum; 30 | 31 | char state[20], 32 | type[20], 33 | working_map[20], 34 | resync_state[20]; 35 | int disknum; 36 | 37 | unsigned long doneColor_, todoColor_, completeColor_; 38 | 39 | int find1(const char *key, const char *findwhat, int num1); 40 | int find2(const char *key, const char *findwhat, int num1, int num2); 41 | 42 | int raidparse(char *cp); 43 | 44 | void getRAIDstate( void ); 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /linux/serialmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _SERIALMETER_H_ 8 | #define _SERIALMETER_H_ 9 | 10 | // hack for not having linux/serial_reg.h, (Debian bug #427599) 11 | #define UART_LSR 5 12 | #define UART_MSR 6 13 | 14 | #include "bitmeter.h" 15 | #include "xosview.h" 16 | 17 | 18 | class SerialMeter : public BitMeter { 19 | public: 20 | enum Device { S0, S1, S2, S3, S4, S5, S6, S7, S8, S9 }; 21 | static int numDevices(void) { return 10; } 22 | 23 | SerialMeter( XOSView *parent, Device device); 24 | ~SerialMeter( void ); 25 | 26 | static const char *getResourceName(Device dev); 27 | 28 | void checkevent( void ); 29 | 30 | void checkResources( void ); 31 | 32 | private: 33 | unsigned short int _port; 34 | Device _device; 35 | 36 | void getserial( void ); 37 | bool getport(unsigned short int port); 38 | const char *getTitle(Device dev) const; 39 | unsigned short int getPortBase(Device dev) const; 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /linux/swapmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #include "swapmeter.h" 8 | #include 9 | #include 10 | 11 | 12 | SwapMeter::SwapMeter( XOSView *parent ) 13 | : FieldMeterGraph( parent, 2, "SWAP", "USED/FREE" ){ 14 | 15 | } 16 | 17 | SwapMeter::~SwapMeter( void ){ 18 | } 19 | 20 | void SwapMeter::checkResources( void ){ 21 | FieldMeterGraph::checkResources(); 22 | 23 | setfieldcolor( 0, parent_->getResource( "swapUsedColor" ) ); 24 | setfieldcolor( 1, parent_->getResource( "swapFreeColor" ) ); 25 | priority_ = atoi (parent_->getResource( "swapPriority" ) ); 26 | dodecay_ = parent_->isResourceTrue( "swapDecay" ); 27 | useGraph_ = parent_->isResourceTrue( "swapGraph" ); 28 | SetUsedFormat (parent_->getResource("swapUsedFormat")); 29 | } 30 | 31 | void SwapMeter::checkevent( void ){ 32 | getswapinfo(); 33 | drawfields(); 34 | } 35 | 36 | void SwapMeter::getswapinfo( void ){ 37 | struct sysinfo sinfo; 38 | typeof (sinfo.mem_unit) unit; 39 | 40 | sysinfo(&sinfo); 41 | unit = (sinfo.mem_unit ? sinfo.mem_unit : 1); 42 | total_ = (double)sinfo.totalswap * unit; 43 | fields_[0] = (double)(sinfo.totalswap - sinfo.freeswap) * unit; 44 | 45 | if ( total_ == 0 ){ 46 | total_ = 1; 47 | fields_[0] = 0; 48 | } 49 | 50 | if (total_) 51 | setUsed (fields_[0], total_); 52 | } 53 | -------------------------------------------------------------------------------- /linux/swapmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _SWAPMETER_H_ 8 | #define _SWAPMETER_H_ 9 | 10 | #include "fieldmetergraph.h" 11 | #include "xosview.h" 12 | 13 | 14 | class SwapMeter : public FieldMeterGraph { 15 | public: 16 | SwapMeter( XOSView *parent ); 17 | ~SwapMeter( void ); 18 | 19 | const char *name( void ) const { return "SwapMeter"; } 20 | void checkevent( void ); 21 | 22 | void checkResources( void ); 23 | protected: 24 | 25 | void getswapinfo( void ); 26 | private: 27 | }; 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /linux/wirelessmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2001 by Tim Ehlers ( tehlers@gwdg.de ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | // 7 | 8 | #include "wirelessmeter.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | WirelessMeter::WirelessMeter( XOSView *parent, int ID, const char *wlID) 17 | : FieldMeterGraph ( parent, 2, wlID, "LINK/LEVEL", 1, 1, 0 ), _number(ID) { 18 | _lastquality = -1; 19 | _lastlink = true; 20 | total_ = 0; 21 | } 22 | 23 | WirelessMeter::~WirelessMeter( void ){ 24 | } 25 | 26 | void WirelessMeter::checkResources( void ){ 27 | FieldMeterGraph::checkResources(); 28 | 29 | _poorqualcol = parent_->allocColor(parent_->getResource( "PoorQualityColor" )); 30 | _fairqualcol = parent_->allocColor(parent_->getResource( "FairQualityColor" )); 31 | _goodqualcol = parent_->allocColor(parent_->getResource( "GoodQualityColor" )); 32 | setfieldcolor( 1, parent_->getResource( "wirelessUsedColor" ) ); 33 | 34 | priority_ = atoi(parent_->getResource( "wirelessPriority" ) ); 35 | dodecay_ = parent_->isResourceTrue( "wirelessDecay" ); 36 | SetUsedFormat(parent_->getResource( "wirelessUsedFormat" ) ); 37 | } 38 | 39 | void WirelessMeter::checkevent( void ){ 40 | getpwrinfo(); 41 | 42 | drawfields(); 43 | } 44 | 45 | void WirelessMeter::getpwrinfo( void ){ 46 | std::ifstream loadinfo( WLFILENAME ); 47 | if ( !loadinfo ){ 48 | std::cerr << "Can not open file : " << WLFILENAME << std::endl; 49 | parent_->done(1); 50 | return; 51 | } 52 | 53 | char buff[16]; 54 | int linkq = 0, quality = 0; 55 | bool link = false; 56 | 57 | // skip the two header rows 58 | loadinfo.ignore(1024, '\n'); 59 | loadinfo.ignore(1024, '\n'); 60 | 61 | if ( _devname.empty() ) { // find devname on first run 62 | for (int i = 0; i < _number; i++) 63 | loadinfo.ignore(1024, '\n'); 64 | if ( loadinfo.good() ) 65 | loadinfo >> _devname >> buff >> linkq; 66 | } 67 | else { 68 | while ( !loadinfo.eof() ) { 69 | loadinfo >> buff; 70 | if ( _devname == buff ) { 71 | loadinfo >> buff >> linkq; 72 | link = true; 73 | break; 74 | } 75 | loadinfo.ignore(1024, '\n'); 76 | } 77 | } 78 | 79 | if ( linkq >= 250 ) 80 | linkq = 0; 81 | 82 | fields_[0] = linkq; 83 | if ( fields_[0] >= 15 ) 84 | quality = 2; 85 | else if ( fields_[0] >= 7 ) 86 | quality = 1; 87 | else 88 | quality = 0; 89 | 90 | if ( link && !_lastlink ) { 91 | legend("LINK/LEVEL"); 92 | drawlegend(); 93 | _lastlink = link; 94 | } 95 | else if ( !link && _lastlink ) { 96 | legend("NONE/LEVEL"); 97 | drawlegend(); 98 | _lastlink = link; 99 | } 100 | 101 | if ( quality != _lastquality ){ 102 | if ( quality == 0 ) 103 | setfieldcolor( 0, _poorqualcol ); 104 | else if ( quality == 1 ) 105 | setfieldcolor( 0, _fairqualcol ); 106 | else 107 | setfieldcolor( 0, _goodqualcol ); 108 | 109 | drawlegend(); 110 | _lastquality = quality; 111 | } 112 | 113 | if (fields_[0] >= total_) 114 | total_ = 30 * (int)(fields_[0] / 30 + 1); 115 | fields_[1] = total_ - fields_[0]; 116 | setUsed(fields_[0], total_); 117 | } 118 | 119 | int WirelessMeter::countdevices(void){ 120 | glob_t gbuf; 121 | glob("/sys/class/net/*/wireless", 0, NULL, &gbuf); 122 | int count = gbuf.gl_pathc; 123 | globfree(&gbuf); 124 | return count; 125 | } 126 | 127 | const char *WirelessMeter::wirelessStr(int num) { 128 | static char buffer[8] = "WL"; 129 | snprintf(buffer + 2, 5, "%d", num); 130 | buffer[7] = '\0'; 131 | return buffer; 132 | } 133 | -------------------------------------------------------------------------------- /linux/wirelessmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1997 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | // 7 | 8 | #ifndef _WIRELESSMETER_H_ 9 | #define _WIRELESSMETER_H_ 10 | 11 | #include "fieldmetergraph.h" 12 | #include "xosview.h" 13 | #include 14 | 15 | static const char WLFILENAME[] = "/proc/net/wireless"; 16 | 17 | 18 | class WirelessMeter : public FieldMeterGraph { 19 | public: 20 | WirelessMeter( XOSView *parent, int ID = 0, const char *wlID = "WL"); 21 | ~WirelessMeter( void ); 22 | 23 | const char *name( void ) const { return "WirelessMeter"; } 24 | void checkevent( void ); 25 | 26 | void checkResources( void ); 27 | static int countdevices(void); 28 | static const char *wirelessStr(int num); 29 | 30 | protected: 31 | void getpwrinfo( void ); 32 | 33 | private: 34 | unsigned long _poorqualcol, _fairqualcol, _goodqualcol; 35 | int _lastquality, _number; 36 | std::string _devname; 37 | bool _lastlink; 38 | }; 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /main.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006, 2007 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #include "xosview.h" 8 | #include 9 | 10 | int main( int argc, char *argv[] ) { 11 | /* Icky. Need to check for -name option here. */ 12 | char** argp = argv; 13 | const char* instanceName = "xosview"; // Default value. 14 | while (argp && *argp) 15 | { 16 | if (!strncmp(*argp, "-name", 6)) 17 | instanceName = argp[1]; 18 | argp++; 19 | } // instanceName will end up pointing to the last such -name option. 20 | XOSView xosview( instanceName, argc, argv ); 21 | 22 | xosview.run(); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /meter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #include "meter.h" 8 | #include 9 | 10 | 11 | Meter::Meter( XOSView *parent, const char *title, const char *legend, 12 | int docaptions, int dolegends, int dousedlegends ) { 13 | title_ = legend_ = NULL; 14 | Meter::title( title ); 15 | Meter::legend( legend ); 16 | parent_ = parent; 17 | docaptions_ = docaptions; 18 | dolegends_ = dolegends; 19 | dousedlegends_ = dousedlegends; 20 | priority_ = 1; 21 | counter_ = 0; 22 | resize( parent->xoff(), parent->newypos(), parent->width() - 10, 10 ); 23 | 24 | } 25 | 26 | Meter::~Meter( void ){ 27 | if ( title_ ) 28 | delete[] title_; 29 | if ( legend_ ) 30 | delete[] legend_; 31 | } 32 | 33 | void Meter::checkResources( void ){ 34 | textcolor_ = parent_->allocColor( parent_->getResource( "meterLabelColor") ); 35 | } 36 | 37 | void Meter::title( const char *title ){ 38 | 39 | if ( title_ ) 40 | delete[] title_; 41 | 42 | int len = strlen(title); 43 | title_ = new char[len + 1]; 44 | memcpy( title_, title, len + 1 ); 45 | } 46 | 47 | void Meter::legend( const char *legend ){ 48 | 49 | if ( legend_ ) 50 | delete[] legend_; 51 | 52 | int len = strlen(legend); 53 | legend_ = new char[len + 1]; 54 | memcpy( legend_, legend, len + 1 ); 55 | } 56 | 57 | void Meter::resize( int x, int y, int width, int height ){ 58 | x_ = x; 59 | y_ = y; 60 | width_ = (width>=0) ? width : 0; // fix for cosmetical bug: 61 | height_ = (height>=0) ? height : 0; // beware of values < 0 ! 62 | width_ &= ~1; // only allow even width_ values 63 | } 64 | 65 | double Meter::scaleValue( double value, char *scale, bool metric ){ 66 | double scaled = ( value < 0 ? -value : value ); 67 | 68 | if (scaled >= 999.5*1e15){ 69 | scale[0] = 'E'; 70 | scaled = value / ( metric ? 1e18 : 1ULL<<60 ); 71 | } 72 | else if (scaled >= 999.5*1e12){ 73 | scale[0] = 'P'; 74 | scaled = value / ( metric ? 1e15 : 1ULL<<50 ); 75 | } 76 | else if (scaled >= 999.5*1e9){ 77 | scale[0] = 'T'; 78 | scaled = value / ( metric ? 1e12 : 1ULL<<40 ); 79 | } 80 | else if (scaled >= 999.5*1e6){ 81 | scale[0] = 'G'; 82 | scaled = value / ( metric ? 1e9 : 1UL<<30 ); 83 | } 84 | else if (scaled >= 999.5*1e3){ 85 | scale[0] = 'M'; 86 | scaled = value / ( metric ? 1e6 : 1UL<<20 ); 87 | } 88 | else if (scaled >= 999.5){ 89 | scale[0] = ( metric ? 'k' : 'K' ); 90 | scaled = value / ( metric ? 1e3 : 1UL<<10 ); 91 | } 92 | else if (scaled < 0.9995 && metric){ 93 | if (scaled >= 0.9995/1e3){ 94 | scale[0] = 'm'; 95 | scaled = value * 1e3; 96 | } 97 | else if (scaled >= 0.9995/1e6){ 98 | scale[0] = '\265'; 99 | scaled = value * 1e6; 100 | } 101 | else { 102 | scale[0] = 'n'; 103 | scaled = value * 1e9; 104 | } 105 | // add more if needed 106 | } 107 | else { 108 | scale[0] = '\0'; 109 | scaled = value; 110 | } 111 | scale[1] = '\0'; 112 | return scaled; 113 | } 114 | -------------------------------------------------------------------------------- /meter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _METER_H_ 8 | #define _METER_H_ 9 | 10 | #include "xosview.h" 11 | #include 12 | 13 | 14 | class Meter { 15 | public: 16 | Meter( XOSView *parent, const char *title = "", const char *legend ="", 17 | int docaptions = 0, int dolegends = 0, int dousedlegends = 0 ); 18 | virtual ~Meter( void ); 19 | 20 | virtual const char *name( void ) const { return "Meter"; } 21 | void resize( int x, int y, int width, int height ); 22 | virtual void checkevent( void ) = 0; 23 | virtual void draw( void ) = 0; 24 | void title( const char *title ); 25 | const char *title( void ) { return title_; } 26 | void legend( const char *legend ); 27 | const char *legend( void ) { return legend_; } 28 | void docaptions( int val ) { docaptions_ = val; } 29 | void dolegends( int val ) { dolegends_ = val; } 30 | void dousedlegends( int val ) { dousedlegends_ = val; } 31 | int requestevent( void ){ 32 | if (priority_ == 0) { 33 | std::cerr << "Warning: meter " << name() << " had an invalid priority " 34 | << "of 0. Resetting to 1..." << std::endl; 35 | priority_ = 1; 36 | } 37 | int rval = counter_ % priority_; 38 | counter_ = (counter_ + 1) % priority_; 39 | return !rval; 40 | } 41 | 42 | int getX() const { return x_; } 43 | int getY() const { return y_; } 44 | int getWidth() const { return width_; } 45 | int getHeight() const { return height_; } 46 | 47 | virtual void checkResources( void ); 48 | 49 | static double scaleValue( double value, char *scale, bool metric ); 50 | 51 | protected: 52 | XOSView *parent_; 53 | int x_, y_, width_, height_, docaptions_, dolegends_, dousedlegends_; 54 | int priority_, counter_; 55 | char *title_, *legend_; 56 | unsigned long textcolor_; 57 | double samplesPerSecond() { return 1.0*MAX_SAMPLES_PER_SECOND/priority_; } 58 | double secondsPerSample() { return 1.0/samplesPerSecond(); } 59 | 60 | private: 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /mkdist: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Make an xosview distribution from a Git repo 4 | # 5 | 6 | set -e 7 | 8 | V=`git describe` 9 | D="xosview-$V" 10 | 11 | mkdir -p dist 12 | A="dist/$D.tar.gz" 13 | git archive --prefix="$D/" HEAD | gzip --best > "$A" 14 | 15 | echo "Created $A" >&2 16 | exit 0 17 | -------------------------------------------------------------------------------- /pllist.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _pllist_h 8 | #define _pllist_h 9 | 10 | #include "llist.h" 11 | 12 | //------------------------------------------------------------------------- 13 | // 14 | // Pointer Linked list. T is some pointer type. 15 | // 16 | //------------------------------------------------------------------------- 17 | 18 | template 19 | class PLList : public LList 20 | { 21 | public: 22 | PLList(void) : LList(){} 23 | // PLList(int(*cmp_fun)(T data, K key)) : LList(cmp_fun){} 24 | 25 | int push(const T data) { return LList::push((void *)data); } 26 | T pop(void) { return (T)LList::pop(); } 27 | 28 | int enqueue(const T data) { return LList::enqueue((void *)data); } 29 | T dequeue(void) { return (T)LList::dequeue(); } 30 | 31 | // int insert(const T data, const K key) 32 | // { return LList::insert((void *)data, (void *)key); } 33 | // T find(const K key) { return (T)LList::find((void *)key); } 34 | // T removematch(const K key) 35 | // { return (T)LList::removematch((void *)key); } 36 | 37 | int putontop(const T data) { return LList::putontop((void *)data); } 38 | void remove(const T data) { LList::remove((void *)data); } 39 | T findn(int n) { return (T)LList::findn(n); } 40 | T operator[](int n) { return findn(n); } 41 | int index(const T data) { return LList::index((void *)data); } 42 | 43 | T findc(int which = 0) { return (T)LList::findc(which); } 44 | }; 45 | 46 | 47 | //------------------------------------------------------------------------- 48 | // 49 | // Sorted Pointer List. T is some type of pointer and K is a pointer to 50 | // the key type for this list. 51 | // 52 | //------------------------------------------------------------------------- 53 | template 54 | class PSLList : public LList 55 | { 56 | public: 57 | PSLList(void) : LList(){} 58 | PSLList(int(*cmp_fun)(T data, K key)) : LList(cmp_fun){} 59 | 60 | int push(const T data) { return LList::push((void *)data); } 61 | T pop(void) { return (T)LList::pop(); } 62 | 63 | int enqueue(const T data) { return LList::enqueue((void *)data); } 64 | T dequeue(void) { return (T)LList::dequeue(); } 65 | 66 | int insert(const T data, const K key) 67 | { return LList::insert((void *)data, (void *)key); } 68 | T find(const K key) { return (T)LList::find((void *)key); } 69 | T removematch(const K key) 70 | { return (T)LList::removematch((void *)key); } 71 | 72 | int putontop(const T data) { return LList::putontop((void *)data); } 73 | void remove(const T data) { LList::remove((void *)data); } 74 | T findn(int n) { return (T)LList::findn(n); } 75 | T operator[](int n) { return findn(n); } 76 | int index(const T data) { return LList::index((void *)data); } 77 | 78 | T findc(int which = 0) { return (T)LList::findc(which); } 79 | }; 80 | 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /sensorfieldmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 by Tomi Tapper 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | // Put code common to *BSD and Linux sensor meters here. 7 | // 8 | 9 | #ifndef _SENSORFIELDMETER_H_ 10 | #define _SENSORFIELDMETER_H_ 11 | 12 | #include "fieldmeter.h" 13 | #include "xosview.h" 14 | 15 | 16 | class SensorFieldMeter : public FieldMeter { 17 | public: 18 | SensorFieldMeter( XOSView *parent, const char *title = "", 19 | const char *legend = "", int docaptions = 0, 20 | int dolegends = 0, int dousedlegends = 0 ); 21 | ~SensorFieldMeter( void ); 22 | 23 | protected: 24 | void updateLegend( void ); 25 | void checkFields( double low, double high ); 26 | char unit_[8]; 27 | double high_, low_; 28 | bool has_high_, has_low_, negative_; 29 | unsigned long actcolor_, highcolor_, lowcolor_; 30 | 31 | private: 32 | 33 | }; 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /stringutils.cc: -------------------------------------------------------------------------------- 1 | #include "stringutils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void snprintf_or_abort(char* str, size_t size, const char* format, ...) { 9 | va_list args; 10 | va_start(args, format); 11 | int needed = vsnprintf(str, size, format, args); 12 | va_end(args); 13 | if (needed < 0) { 14 | std::cerr << "Internal error: vsnprintf returned an error in " 15 | "snprintf_or_abort" << std::endl; 16 | abort(); 17 | } 18 | if ((size_t)needed >= size) { 19 | std::cerr << "Internal error: Buffer to snprintf_or_abort too small, " 20 | "required " << needed << " but got " << size << std::endl; 21 | abort(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /stringutils.h: -------------------------------------------------------------------------------- 1 | #ifndef _STRINGUTILS_H_ 2 | #define _STRINGUTILS_H_ 3 | 4 | #include 5 | 6 | /** Like snprintf, except that instead of truncating the string, it 7 | * will print an error message and abort(). 8 | */ 9 | void snprintf_or_abort(char* str, size_t size, const char* format, ...); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /sunos5/MeterMaker.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Greg Onufer (exodus@cheers.bungi.com) 3 | // 4 | 5 | #include "MeterMaker.h" 6 | #include "xosview.h" 7 | #include "kstats.h" 8 | #include "cpumeter.h" 9 | #include "memmeter.h" 10 | #include "swapmeter.h" 11 | #include "loadmeter.h" 12 | #include "pagemeter.h" 13 | #include "diskmeter.h" 14 | #include "netmeter.h" 15 | #include "intratemeter.h" 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | MeterMaker::MeterMaker(XOSView *xos) 22 | { 23 | _xos = xos; 24 | } 25 | 26 | void MeterMaker::makeMeters(void) 27 | { 28 | kstat_ctl_t *kc; 29 | 30 | kc = kstat_open(); 31 | if (kc == NULL) 32 | return; 33 | 34 | if (_xos->isResourceTrue("load")) 35 | push(new LoadMeter(_xos, kc)); 36 | 37 | // Standard meters (usually added, but users could turn them off) 38 | if (_xos->isResourceTrue("cpu")) { 39 | bool single, both, all; 40 | int cpuCount = sysconf(_SC_NPROCESSORS_ONLN); 41 | 42 | single = (strncmp(_xos->getResource("cpuFormat"), "single", 2) == 0); 43 | both = (strncmp(_xos->getResource("cpuFormat"), "both", 2) == 0); 44 | all = (strncmp(_xos->getResource("cpuFormat"), "all", 2) == 0); 45 | 46 | if (strncmp(_xos->getResource("cpuFormat"), "auto", 2) == 0) { 47 | if (cpuCount == 1 || cpuCount > 4) 48 | single = true; 49 | else 50 | all = true; 51 | } 52 | 53 | if (single || both) 54 | push(new CPUMeter(_xos, kc, -1)); 55 | 56 | if (all || both) { 57 | KStatList *cpulist = KStatList::getList(kc, KStatList::CPU_STAT); 58 | for (unsigned int i = 0; i < cpulist->count(); i++) 59 | push(new CPUMeter(_xos, kc, (*cpulist)[i]->ks_instance)); 60 | } 61 | } 62 | 63 | if (_xos->isResourceTrue("mem")) 64 | push(new MemMeter(_xos, kc)); 65 | 66 | if (_xos->isResourceTrue("disk")) 67 | push(new DiskMeter(_xos, kc, atof(_xos->getResource("diskBandwidth")))); 68 | 69 | if (_xos->isResourceTrue("swap")) 70 | push(new SwapMeter(_xos, kc)); 71 | 72 | if (_xos->isResourceTrue("page")) 73 | push(new PageMeter(_xos, kc, atof(_xos->getResource("pageBandwidth")))); 74 | 75 | if (_xos->isResourceTrue("net")) 76 | push(new NetMeter(_xos, kc, atof(_xos->getResource("netBandwidth")))); 77 | 78 | if (_xos->isResourceTrue("irqrate")) 79 | push(new IrqRateMeter(_xos, kc)); 80 | } 81 | -------------------------------------------------------------------------------- /sunos5/MeterMaker.h: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Greg Onufer (exodus@cheers.bungi.com) 3 | // 4 | #ifndef _MeterMaker_h 5 | #define _MeterMaker_h 6 | 7 | #include "pllist.h" 8 | 9 | class Meter; 10 | class XOSView; 11 | 12 | class MeterMaker : public PLList { 13 | public: 14 | MeterMaker(XOSView *xos); 15 | 16 | void makeMeters(void); 17 | 18 | private: 19 | XOSView *_xos; 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /sunos5/cpumeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Greg Onufer (exodus@cheers.bungi.com) 3 | // 4 | 5 | #include "cpumeter.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | CPUMeter::CPUMeter(XOSView *parent, kstat_ctl_t *_kc, int cpuid) 13 | : FieldMeterGraph(parent, CPU_STATES, cpuStr(cpuid), "USER/SYS/WAIT/IDLE") 14 | { 15 | kc = _kc; 16 | aggregate = ( cpuid < 0 ); 17 | for (int i = 0 ; i < 2 ; i++) 18 | for (int j = 0 ; j < CPU_STATES ; j++) 19 | cputime_[i][j] = 0; 20 | cpuindex_ = 0; 21 | cpustats = KStatList::getList(kc, KStatList::CPU_STAT); 22 | 23 | if (!aggregate) 24 | for (unsigned int i = 0; i < cpustats->count(); i++) 25 | if ((*cpustats)[i]->ks_instance == cpuid) 26 | ksp = (*cpustats)[i]; 27 | } 28 | 29 | CPUMeter::~CPUMeter(void) 30 | { 31 | } 32 | 33 | void CPUMeter::checkResources(void) 34 | { 35 | FieldMeterGraph::checkResources(); 36 | 37 | setfieldcolor(0, parent_->getResource("cpuUserColor")); 38 | setfieldcolor(1, parent_->getResource("cpuSystemColor")); 39 | setfieldcolor(2, parent_->getResource("cpuInterruptColor")); 40 | setfieldcolor(3, parent_->getResource("cpuFreeColor")); 41 | priority_ = atoi(parent_->getResource("cpuPriority")); 42 | dodecay_ = parent_->isResourceTrue("cpuDecay"); 43 | useGraph_ = parent_->isResourceTrue("cpuGraph"); 44 | SetUsedFormat(parent_->getResource("cpuUsedFormat")); 45 | } 46 | 47 | void CPUMeter::checkevent(void) 48 | { 49 | getcputime(); 50 | drawfields(); 51 | } 52 | 53 | void CPUMeter::getcputime(void) 54 | { 55 | total_ = 0; 56 | cpu_stat_t cs; 57 | 58 | if (aggregate) { 59 | cpustats->update(kc); 60 | bzero(cputime_[cpuindex_], CPU_STATES * sizeof(cputime_[cpuindex_][0])); 61 | for (unsigned int i = 0; i < cpustats->count(); i++) { 62 | if (kstat_read(kc, (*cpustats)[i], &cs) == -1) { 63 | parent_->done(1); 64 | return; 65 | } 66 | cputime_[cpuindex_][0] += cs.cpu_sysinfo.cpu[CPU_USER]; 67 | cputime_[cpuindex_][1] += cs.cpu_sysinfo.cpu[CPU_KERNEL]; 68 | cputime_[cpuindex_][2] += cs.cpu_sysinfo.cpu[CPU_WAIT]; 69 | cputime_[cpuindex_][3] += cs.cpu_sysinfo.cpu[CPU_IDLE]; 70 | } 71 | } 72 | else { 73 | if (kstat_read(kc, ksp, &cs) == -1) { 74 | parent_->done(1); 75 | return; 76 | } 77 | cputime_[cpuindex_][0] = cs.cpu_sysinfo.cpu[CPU_USER]; 78 | cputime_[cpuindex_][1] = cs.cpu_sysinfo.cpu[CPU_KERNEL]; 79 | cputime_[cpuindex_][2] = cs.cpu_sysinfo.cpu[CPU_WAIT]; 80 | cputime_[cpuindex_][3] = cs.cpu_sysinfo.cpu[CPU_IDLE]; 81 | } 82 | 83 | int oldindex = (cpuindex_ + 1) % 2; 84 | for (int i = 0 ; i < CPU_STATES ; i++) { 85 | fields_[i] = cputime_[cpuindex_][i] - cputime_[oldindex][i]; 86 | total_ += fields_[i]; 87 | } 88 | cpuindex_ = (cpuindex_ + 1) % 2; 89 | 90 | if (total_) 91 | setUsed(total_ - fields_[3], total_); 92 | } 93 | 94 | const char *CPUMeter::cpuStr(int num) 95 | { 96 | static char buffer[8] = "CPU"; 97 | if (num >= 0) 98 | snprintf(buffer + 3, 4, "%d", num); 99 | buffer[7] = '\0'; 100 | return buffer; 101 | } 102 | -------------------------------------------------------------------------------- /sunos5/cpumeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Greg Onufer (exodus@cheers.bungi.com) 3 | // 4 | #ifndef _CPUMETER_H_ 5 | #define _CPUMETER_H_ 6 | 7 | #include "fieldmetergraph.h" 8 | #include "xosview.h" 9 | #include "kstats.h" 10 | #include 11 | #include 12 | 13 | 14 | class CPUMeter : public FieldMeterGraph { 15 | public: 16 | CPUMeter(XOSView *parent, kstat_ctl_t *kcp, int cpuid = 0); 17 | ~CPUMeter(void); 18 | 19 | const char *name(void) const { return "CPUMeter"; } 20 | void checkevent(void); 21 | void checkResources(void); 22 | static const char *cpuStr(int num); 23 | 24 | protected: 25 | float cputime_[2][CPU_STATES]; 26 | int cpuindex_; 27 | 28 | void getcputime(void); 29 | 30 | private: 31 | KStatList *cpustats; 32 | bool aggregate; 33 | kstat_ctl_t *kc; 34 | kstat_t *ksp; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /sunos5/diskmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Rewritten for Solaris by Arno Augustin 1999 3 | // augustin@informatik.uni-erlangen.de 4 | // 5 | 6 | #include "diskmeter.h" 7 | #include 8 | 9 | 10 | DiskMeter::DiskMeter( XOSView *parent, kstat_ctl_t *kc, float max ) 11 | : FieldMeterGraph( parent, 3, "DISK", "READ/WRITE/IDLE" ) 12 | { 13 | _kc = kc; 14 | _read_prev = _write_prev = 0; 15 | _maxspeed = max; 16 | _disks = KStatList::getList(_kc, KStatList::DISKS); 17 | } 18 | 19 | DiskMeter::~DiskMeter( void ) 20 | { 21 | } 22 | 23 | void DiskMeter::checkResources( void ) 24 | { 25 | FieldMeterGraph::checkResources(); 26 | 27 | setfieldcolor( 0, parent_->getResource("diskReadColor") ); 28 | setfieldcolor( 1, parent_->getResource("diskWriteColor") ); 29 | setfieldcolor( 2, parent_->getResource("diskIdleColor") ); 30 | priority_ = atoi( parent_->getResource("diskPriority") ); 31 | dodecay_ = parent_->isResourceTrue("diskDecay"); 32 | useGraph_ = parent_->isResourceTrue("diskGraph"); 33 | SetUsedFormat( parent_->getResource("diskUsedFormat") ); 34 | } 35 | 36 | void DiskMeter::checkevent( void ) 37 | { 38 | getdiskinfo(); 39 | drawfields(); 40 | } 41 | 42 | void DiskMeter::getdiskinfo( void ) 43 | { 44 | total_ = _maxspeed; 45 | kstat_io_t kio; 46 | uint64_t read_curr = 0, write_curr = 0; 47 | _disks->update(_kc); 48 | 49 | IntervalTimerStop(); 50 | for (unsigned int i = 0; i < _disks->count(); i++) { 51 | if ( kstat_read(_kc, (*_disks)[i], &kio) == -1 ) 52 | continue; 53 | XOSDEBUG("%s: %llu bytes read %llu bytes written.\n", 54 | (*_disks)[i]->ks_name, kio.nread, kio.nwritten); 55 | read_curr += kio.nread; 56 | write_curr += kio.nwritten; 57 | } 58 | if (_read_prev == 0) 59 | _read_prev = read_curr; 60 | if (_write_prev == 0) 61 | _write_prev = write_curr; 62 | 63 | double t = IntervalTimeInSecs(); 64 | fields_[0] = (double)(read_curr - _read_prev) / t; 65 | fields_[1] = (double)(write_curr - _write_prev) / t; 66 | 67 | IntervalTimerStart(); 68 | _read_prev = read_curr; 69 | _write_prev = write_curr; 70 | 71 | if (fields_[0] < 0) 72 | fields_[0] = 0; 73 | if (fields_[1] < 0) 74 | fields_[1] = 0; 75 | if (fields_[0] + fields_[1] > total_) 76 | total_ = fields_[0] + fields_[1]; 77 | fields_[2] = total_ - (fields_[0] + fields_[1]); 78 | setUsed(fields_[0] + fields_[1], total_); 79 | } 80 | -------------------------------------------------------------------------------- /sunos5/diskmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1999 by Mike Romberg (romberg@fsl.noaa.gov) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _DISKMETER_H_ 8 | #define _DISKMETER_H_ 9 | 10 | #include "fieldmetergraph.h" 11 | #include "xosview.h" 12 | #include "kstats.h" 13 | #include 14 | 15 | 16 | class DiskMeter : public FieldMeterGraph { 17 | public: 18 | DiskMeter( XOSView *parent, kstat_ctl_t *kc, float max ); 19 | ~DiskMeter( void ); 20 | 21 | const char *name( void ) const { return "DiskMeter"; } 22 | void checkevent( void ); 23 | void checkResources( void ); 24 | 25 | protected: 26 | void getdiskinfo( void ); 27 | 28 | private: 29 | uint64_t _read_prev, _write_prev; 30 | float _maxspeed; 31 | kstat_ctl_t *_kc; 32 | KStatList *_disks; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /sunos5/intratemeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 by Tomi Tapper 3 | // 4 | // File based on bsd/intratemeter.* by 5 | // Copyright (c) 1999 by Brian Grayson (bgrayson@netbsd.org) 6 | // 7 | // This file may be distributed under terms of the GPL 8 | // 9 | // 10 | 11 | #include "intratemeter.h" 12 | #include 13 | 14 | 15 | IrqRateMeter::IrqRateMeter(XOSView *parent, kstat_ctl_t *kc) 16 | : FieldMeterGraph(parent, 2, "IRQs", "IRQs per sec/IDLE", 1, 1, 0) 17 | { 18 | _lastirqcount = 0; 19 | _kc = kc; 20 | _cpus = KStatList::getList(_kc, KStatList::CPU_SYS); 21 | } 22 | 23 | IrqRateMeter::~IrqRateMeter(void) 24 | { 25 | } 26 | 27 | void IrqRateMeter::checkResources(void) 28 | { 29 | FieldMeterGraph::checkResources(); 30 | setfieldcolor(0, parent_->getResource("irqrateUsedColor")); 31 | setfieldcolor(1, parent_->getResource("irqrateIdleColor")); 32 | priority_ = atoi(parent_->getResource("irqratePriority")); 33 | dodecay_ = parent_->isResourceTrue("irqrateDecay"); 34 | useGraph_ = parent_->isResourceTrue("irqrateGraph"); 35 | SetUsedFormat(parent_->getResource("irqrateUsedFormat")); 36 | total_ = 2000; 37 | } 38 | 39 | void IrqRateMeter::checkevent(void) 40 | { 41 | getinfo(); 42 | drawfields(); 43 | } 44 | 45 | void IrqRateMeter::getinfo(void) 46 | { 47 | kstat_named_t *k; 48 | uint64_t irqcount = 0; 49 | 50 | _cpus->update(_kc); 51 | IntervalTimerStop(); 52 | for (size_t i = 0; i < _cpus->count(); i++) { 53 | if (kstat_read(_kc, (*_cpus)[i], NULL) == -1) { 54 | parent_->done(1); 55 | return; 56 | } 57 | k = (kstat_named_t *)kstat_data_lookup((*_cpus)[i], "intr"); 58 | if (k == NULL) { 59 | parent_->done(1); 60 | return; 61 | } 62 | irqcount += kstat_to_ui64(k); 63 | } 64 | if (_lastirqcount == 0) 65 | _lastirqcount = irqcount; 66 | 67 | fields_[0] = (irqcount - _lastirqcount) / IntervalTimeInSecs(); 68 | _lastirqcount = irqcount; 69 | IntervalTimerStart(); 70 | 71 | if (fields_[0] > total_) 72 | total_ = fields_[0]; 73 | 74 | setUsed(fields_[0], total_); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /sunos5/intratemeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 by Tomi Tapper 3 | // 4 | // File based on bsd/intratemeter.* by 5 | // Copyright (c) 1999 by Brian Grayson (bgrayson@netbsd.org) 6 | // 7 | // This file may be distributed under terms of the GPL 8 | // 9 | // 10 | 11 | #ifndef _IRQRATEMETER_H_ 12 | #define _IRQRATEMETER_H_ 13 | 14 | #include "fieldmetergraph.h" 15 | #include "xosview.h" 16 | #include "kstats.h" 17 | #include 18 | 19 | 20 | class IrqRateMeter : public FieldMeterGraph { 21 | public: 22 | IrqRateMeter(XOSView *parent, kstat_ctl_t *kc); 23 | ~IrqRateMeter(void); 24 | 25 | const char *name(void) const { return "IrqRateMeter"; } 26 | void checkevent(void); 27 | void checkResources(void); 28 | 29 | protected: 30 | void getinfo(void); 31 | 32 | private: 33 | uint64_t _lastirqcount; 34 | kstat_ctl_t *_kc; 35 | KStatList *_cpus; 36 | }; 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /sunos5/loadmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Greg Onufer (exodus@cheers.bungi.com) 3 | // 4 | #ifndef _LOADMETER_H_ 5 | #define _LOADMETER_H_ 6 | 7 | #include "fieldmetergraph.h" 8 | #include "xosview.h" 9 | #include "kstats.h" 10 | #include 11 | 12 | 13 | class LoadMeter : public FieldMeterGraph { 14 | public: 15 | LoadMeter(XOSView *parent, kstat_ctl_t *kcp); 16 | ~LoadMeter(void); 17 | 18 | const char *name(void) const { return "LoadMeter"; } 19 | void checkevent(void); 20 | void checkResources(void); 21 | 22 | protected: 23 | void getloadinfo(void); 24 | void getspeedinfo(void); 25 | 26 | private: 27 | unsigned long procloadcol, warnloadcol, critloadcol; 28 | unsigned int warnThreshold, critThreshold; 29 | unsigned int old_cpu_speed, cur_cpu_speed; 30 | int lastalarmstate; 31 | bool do_cpu_speed; 32 | KStatList *cpulist; 33 | kstat_ctl_t *kc; 34 | #ifdef NO_GETLOADAVG 35 | kstat_t *ksp; 36 | #endif 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /sunos5/memmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Greg Onufer (exodus@cheers.bungi.com) 3 | // 4 | 5 | #include "memmeter.h" 6 | #include "kstats.h" 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | MemMeter::MemMeter(XOSView *parent, kstat_ctl_t *_kc) 13 | : FieldMeterGraph(parent, 4, "MEM", "SYS/ZFS/OTHER/FREE") 14 | { 15 | kc = _kc; 16 | pageSize = sysconf(_SC_PAGESIZE); 17 | total_ = sysconf(_SC_PHYS_PAGES); 18 | 19 | ksp_sp = kstat_lookup(kc, "unix", 0, "system_pages"); 20 | ksp_zfs = kstat_lookup(kc, "vmem", -1, "zfs_file_data_buf"); 21 | if (ksp_sp == NULL) { // ZFS cache may be missing 22 | std::cerr << "Can not find unix:0:system_pages kstat." << std::endl; 23 | parent_->done(1); 24 | return; 25 | } 26 | } 27 | 28 | void MemMeter::checkResources(void) 29 | { 30 | FieldMeterGraph::checkResources(); 31 | 32 | setfieldcolor(0, parent_->getResource("memKernelColor")); 33 | setfieldcolor(1, parent_->getResource("memCacheColor")); 34 | setfieldcolor(2, parent_->getResource("memUsedColor")); 35 | setfieldcolor(3, parent_->getResource("memFreeColor")); 36 | priority_ = atoi(parent_->getResource("memPriority")); 37 | dodecay_ = parent_->isResourceTrue("memDecay"); 38 | useGraph_ = parent_->isResourceTrue("memGraph"); 39 | SetUsedFormat(parent_->getResource("memUsedFormat")); 40 | } 41 | 42 | MemMeter::~MemMeter(void) 43 | { 44 | } 45 | 46 | void MemMeter::checkevent(void) 47 | { 48 | getmeminfo(); 49 | drawfields(); 50 | } 51 | 52 | void MemMeter::getmeminfo(void) 53 | { 54 | kstat_named_t *k; 55 | 56 | fields_[1] = 0; 57 | if (ksp_zfs) { 58 | if (kstat_read(kc, ksp_zfs, NULL) == -1) { 59 | std::cerr << "Can not read vmem::zfs_file_data_buf kstat." << std::endl; 60 | parent_->done(1); 61 | return; 62 | } 63 | k = (kstat_named_t *)kstat_data_lookup(ksp_zfs, "mem_inuse"); 64 | if (k == NULL) { 65 | std::cerr << "Can not read vmem::zfs_file_data_buf:mem_inuse kstat." << std::endl; 66 | parent_->done(1); 67 | return; 68 | } 69 | fields_[1] = kstat_to_double(k) / pageSize; 70 | } 71 | 72 | if (kstat_read(kc, ksp_sp, NULL) == -1) { 73 | std::cerr << "Can not read unix:0:system_pages kstat." << std::endl; 74 | parent_->done(1); 75 | return; 76 | } 77 | k = (kstat_named_t *)kstat_data_lookup(ksp_sp, "pp_kernel"); 78 | if (k == NULL) { 79 | std::cerr << "Can not read unix:0:system_pages:pp_kernel kstat." << std::endl; 80 | parent_->done(1); 81 | return; 82 | } 83 | fields_[0] = kstat_to_double(k) - fields_[1]; 84 | k = (kstat_named_t *)kstat_data_lookup(ksp_sp, "freemem"); 85 | if (k == NULL) { 86 | std::cerr << "Can not read unix:0:system_pages:freemem kstat." << std::endl; 87 | parent_->done(1); 88 | return; 89 | } 90 | fields_[3] = kstat_to_double(k); 91 | fields_[2] = total_ - (fields_[0] + fields_[1] + fields_[3]); 92 | 93 | XOSDEBUG("kernel: %llu kB zfs: %llu kB other: %llu kB free: %llu kB\n", 94 | (unsigned long long)(fields_[0] * pageSize / 1024), 95 | (unsigned long long)(fields_[1] * pageSize / 1024), 96 | (unsigned long long)(fields_[2] * pageSize / 1024), 97 | (unsigned long long)(fields_[3] * pageSize / 1024)); 98 | 99 | setUsed((fields_[0] + fields_[1] + fields_[2]) * pageSize, total_ * pageSize); 100 | } 101 | 102 | -------------------------------------------------------------------------------- /sunos5/memmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Greg Onufer (exodus@cheers.bungi.com) 3 | // 4 | #ifndef _MEMMETER_H_ 5 | #define _MEMMETER_H_ 6 | 7 | #include "fieldmetergraph.h" 8 | #include "xosview.h" 9 | #include 10 | 11 | 12 | class MemMeter : public FieldMeterGraph { 13 | public: 14 | MemMeter(XOSView *parent, kstat_ctl_t *kcp); 15 | ~MemMeter(void); 16 | 17 | const char *name(void) const { return "MemMeter"; } 18 | void checkevent( void ); 19 | void checkResources(void); 20 | 21 | protected: 22 | void getmeminfo( void ); 23 | 24 | private: 25 | int pageSize; 26 | kstat_ctl_t *kc; 27 | kstat_t *ksp_sp, *ksp_zfs; 28 | }; 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /sunos5/netmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _NETMETER_H_ 8 | #define _NETMETER_H_ 9 | 10 | #include "fieldmetergraph.h" 11 | #include "xosview.h" 12 | #include "kstats.h" 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | class NetMeter : public FieldMeterGraph { 19 | public: 20 | NetMeter( XOSView *parent, kstat_ctl_t *kc, float max ); 21 | ~NetMeter( void ); 22 | 23 | const char *name( void ) const { return "NetMeter"; } 24 | void checkevent( void ); 25 | void checkResources( void ); 26 | 27 | protected: 28 | void getnetstats( void ); 29 | 30 | private: 31 | float _maxpackets; 32 | uint64_t _lastBytesIn, _lastBytesOut; 33 | kstat_ctl_t *_kc; 34 | KStatList *_nets; 35 | std::string _netIface; 36 | bool _ignored; 37 | struct lifreq _lfr; 38 | int _socket; 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /sunos5/pagemeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Greg Onufer (exodus@cheers.bungi.com) 3 | // 4 | 5 | #include "pagemeter.h" 6 | #include 7 | #include 8 | 9 | 10 | PageMeter::PageMeter(XOSView *parent, kstat_ctl_t *_kc, float max) 11 | : FieldMeterGraph( parent, 3, "PAGE", "IN/OUT/IDLE") 12 | { 13 | kc = _kc; 14 | 15 | for (int i = 0 ; i < 2 ; i++) 16 | for (int j = 0 ; j < 2 ; j++) 17 | pageinfo_[j][i] = 0; 18 | 19 | maxspeed_ = max; 20 | pageindex_ = 0; 21 | cpustats = KStatList::getList(kc, KStatList::CPU_STAT); 22 | } 23 | 24 | PageMeter::~PageMeter(void) 25 | { 26 | } 27 | 28 | void PageMeter::checkResources(void) 29 | { 30 | FieldMeterGraph::checkResources(); 31 | 32 | setfieldcolor(0, parent_->getResource("pageInColor")); 33 | setfieldcolor(1, parent_->getResource("pageOutColor")); 34 | setfieldcolor(2, parent_->getResource("pageIdleColor")); 35 | priority_ = atoi(parent_->getResource("pagePriority")); 36 | maxspeed_ *= priority_ / 10.0; 37 | dodecay_ = parent_->isResourceTrue("pageDecay"); 38 | useGraph_ = parent_->isResourceTrue("pageGraph"); 39 | SetUsedFormat(parent_->getResource("pageUsedFormat")); 40 | } 41 | 42 | void PageMeter::checkevent(void) 43 | { 44 | getpageinfo(); 45 | drawfields(); 46 | } 47 | 48 | void PageMeter::getpageinfo(void) 49 | { 50 | cpu_stat_t cs; 51 | total_ = 0; 52 | pageinfo_[pageindex_][0] = 0; // pgin 53 | pageinfo_[pageindex_][1] = 0; // pgout 54 | cpustats->update(kc); 55 | 56 | for (unsigned int i = 0; i < cpustats->count(); i++) { 57 | if (kstat_read(kc, (*cpustats)[i], &cs) == -1) 58 | continue; 59 | pageinfo_[pageindex_][0] += cs.cpu_vminfo.pgpgin; 60 | pageinfo_[pageindex_][1] += cs.cpu_vminfo.pgpgout; 61 | } 62 | 63 | int oldindex = (pageindex_ + 1) % 2; 64 | for (int i = 0; i < 2; i++) { 65 | if (pageinfo_[oldindex][i] == 0) 66 | pageinfo_[oldindex][i] = pageinfo_[pageindex_][i]; 67 | 68 | fields_[i] = pageinfo_[pageindex_][i] - pageinfo_[oldindex][i]; 69 | total_ += fields_[i]; 70 | } 71 | 72 | if (total_ > maxspeed_) 73 | fields_[2] = 0.0; 74 | else { 75 | fields_[2] = maxspeed_ - total_; 76 | total_ = maxspeed_; 77 | } 78 | 79 | setUsed(total_ - fields_[2], maxspeed_); 80 | pageindex_ = (pageindex_ + 1) % 2; 81 | } 82 | -------------------------------------------------------------------------------- /sunos5/pagemeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Greg Onufer (exodus@cheers.bungi.com) 3 | // 4 | #ifndef _PAGEMETER_H_ 5 | #define _PAGEMETER_H_ 6 | 7 | #include "fieldmetergraph.h" 8 | #include "xosview.h" 9 | #include "kstats.h" 10 | #include 11 | 12 | 13 | class PageMeter : public FieldMeterGraph { 14 | public: 15 | PageMeter(XOSView *parent, kstat_ctl_t *kcp, float max); 16 | ~PageMeter(void); 17 | 18 | const char *name(void) const { return "PageMeter"; } 19 | void checkevent(void); 20 | void checkResources(void); 21 | 22 | protected: 23 | float pageinfo_[2][2]; 24 | int pageindex_; 25 | float maxspeed_; 26 | 27 | void getpageinfo(void); 28 | 29 | private: 30 | KStatList *cpustats; 31 | kstat_ctl_t *kc; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /sunos5/swapmeter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Greg Onufer (exodus@cheers.bungi.com) 3 | // 4 | #include "swapmeter.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | SwapMeter::SwapMeter(XOSView *parent, kstat_ctl_t *_kc) 14 | : FieldMeterGraph(parent, 2, "SWAP", "USED/FREE") 15 | { 16 | pagesize = sysconf(_SC_PAGESIZE); 17 | } 18 | 19 | SwapMeter::~SwapMeter(void) 20 | { 21 | } 22 | 23 | void SwapMeter::checkResources(void) 24 | { 25 | FieldMeterGraph::checkResources(); 26 | 27 | setfieldcolor(0, parent_->getResource("swapUsedColor")); 28 | setfieldcolor(1, parent_->getResource("swapFreeColor")); 29 | priority_ = atoi(parent_->getResource("swapPriority")); 30 | dodecay_ = parent_->isResourceTrue("swapDecay"); 31 | useGraph_ = parent_->isResourceTrue("swapGraph"); 32 | SetUsedFormat(parent_->getResource("swapUsedFormat")); 33 | } 34 | 35 | void SwapMeter::checkevent(void) 36 | { 37 | getswapinfo(); 38 | drawfields(); 39 | } 40 | 41 | void SwapMeter::getswapinfo(void) 42 | { 43 | swaptbl_t *swaps; 44 | char *names; 45 | 46 | total_ = fields_[0] = fields_[1] = 0; 47 | int numswap = swapctl(SC_GETNSWP, NULL); 48 | if (numswap < 0) { 49 | std::cerr << "Can not determine number of swap spaces." << std::endl; 50 | parent_->done(1); 51 | return; 52 | } 53 | if (numswap > 0) { 54 | swaps = (swaptbl_t *)malloc(sizeof(swaptbl_t) + numswap * sizeof(swapent_t)); 55 | names = (char *)calloc(numswap + 1, PATH_MAX); 56 | if (!swaps || !names) { 57 | std::cerr << "malloc failed." << std::endl; 58 | parent_->done(1); 59 | return; 60 | } 61 | swaps->swt_n = numswap; 62 | for (int i = 0; i <= numswap; i++) 63 | swaps->swt_ent[i].ste_path = names + (i * PATH_MAX); 64 | 65 | if (swapctl(SC_LIST, swaps) < 0) { 66 | std::cerr << "Can not get list of swap spaces." << std::endl; 67 | parent_->done(1); 68 | return; 69 | } 70 | for (int i = 0; i < numswap; i++) { 71 | total_ += swaps->swt_ent[i].ste_pages; 72 | fields_[1] += swaps->swt_ent[i].ste_free; 73 | XOSDEBUG("%s: %ld kB (%ld kB free)\n", 74 | swaps->swt_ent[i].ste_path, 75 | swaps->swt_ent[i].ste_pages * (pagesize / 1024), 76 | swaps->swt_ent[i].ste_free * (pagesize / 1024)); 77 | } 78 | fields_[0] = total_ - fields_[1]; 79 | free(swaps); 80 | free(names); 81 | } 82 | 83 | setUsed(fields_[0] * pagesize, total_ * pagesize); 84 | } 85 | -------------------------------------------------------------------------------- /sunos5/swapmeter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Initial port performed by Greg Onufer (exodus@cheers.bungi.com) 3 | // 4 | #ifndef _SWAPMETER_H_ 5 | #define _SWAPMETER_H_ 6 | 7 | #include "fieldmetergraph.h" 8 | #include "xosview.h" 9 | #include 10 | 11 | 12 | class SwapMeter : public FieldMeterGraph { 13 | public: 14 | SwapMeter(XOSView *parent, kstat_ctl_t *kcp); 15 | ~SwapMeter(void); 16 | 17 | const char *name(void) const { return "SwapMeter"; } 18 | void checkevent(void); 19 | void checkResources(void); 20 | 21 | protected: 22 | void getswapinfo(void); 23 | 24 | private: 25 | size_t pagesize; 26 | }; 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /targets/dragonflybsd: -------------------------------------------------------------------------------- 1 | PLATFORM = bsd 2 | CPPFLAGS += -I/usr/pkg/include -I/usr/local/include 3 | LDLIBS += -lkvm -lkinfo -ldevstat -L/usr/pkg/lib -L/usr/local/lib 4 | -------------------------------------------------------------------------------- /targets/freebsd: -------------------------------------------------------------------------------- 1 | PLATFORM = bsd 2 | CXX = c++ 3 | CPPFLAGS += -I/usr/local/include 4 | LDFLAGS += -ldevstat -lkvm -L/usr/local/lib 5 | -------------------------------------------------------------------------------- /targets/netbsd: -------------------------------------------------------------------------------- 1 | PLATFORM = bsd 2 | CPPFLAGS += -I/usr/X11R7/include 3 | LDLIBS += -lkvm -lprop -L/usr/X11R7/lib -Wl,--rpath=/usr/X11R7/lib 4 | -------------------------------------------------------------------------------- /targets/openbsd: -------------------------------------------------------------------------------- 1 | PLATFORM = bsd 2 | CPPFLAGS += -I/usr/X11R6/include 3 | LDLIBS += -lkvm -L/usr/X11R6/lib 4 | -------------------------------------------------------------------------------- /timer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov ) 3 | // 4 | // This file may be distributed under terms of the GPL 5 | // 6 | 7 | #ifndef _TIMER_H_ 8 | #define _TIMER_H_ 9 | 10 | // 11 | // General purpose interval timer class 12 | // 13 | // Implemented using BSD derived function gettimeofday for greater resolution 14 | // 15 | // Author : Mike Romberg 16 | 17 | #include "timeval.h" 18 | #include 19 | #include 20 | 21 | 22 | class Timer { 23 | public: 24 | Timer( int start = 0 ) { if ( start ) Timer::start(); } 25 | ~Timer( void ){} 26 | 27 | void start( void ) { gettimeofday( &starttime_, NULL ); } 28 | void stop( void ) { gettimeofday( &stoptime_, NULL ); } 29 | 30 | // This one uses doubles as the return value, to avoid 31 | // overflow/sign problems. 32 | double report_usecs(void) const { 33 | return (stoptime_.tv_sec - starttime_.tv_sec) * 1000000.0 34 | + stoptime_.tv_usec - starttime_.tv_usec; 35 | } 36 | 37 | std::ostream &printOn(std::ostream &os) const { 38 | return os <<"Timer : [" 39 | <<"starttime_ = " < 11 | #include 12 | 13 | class TimeVal { 14 | public: 15 | TimeVal(unsigned long sec = 0, unsigned long usec = 0) { 16 | _val.tv_sec = (int)sec; 17 | _val.tv_usec = usec; 18 | } 19 | TimeVal(const struct timeval &val) { _val = val; } 20 | 21 | unsigned long sec(void) const { return _val.tv_sec; } 22 | unsigned long usec(void) const { return _val.tv_usec; } 23 | void sec(unsigned long s) { _val.tv_sec = (int)s; } 24 | void usec(unsigned long us) { _val.tv_usec = us; } 25 | 26 | operator struct timeval(void) const { return _val; } 27 | 28 | std::ostream &printOn(std::ostream &os) const { 29 | return os <<"(" < 13 | 14 | /* Take at most n samples per second (default of 10) */ 15 | extern double MAX_SAMPLES_PER_SECOND; 16 | 17 | class Meter; 18 | 19 | class XOSView : public XWin { 20 | public: 21 | XOSView( const char* instName, int argc, char *argv[] ); 22 | ~XOSView( void ); 23 | 24 | void figureSize ( void ); 25 | void resize( void ); 26 | void draw ( void ); 27 | void run( void ); 28 | const char *winname( void ); 29 | 30 | // used by meter makers 31 | int xoff(void) const { return xoff_; } 32 | int newypos( void ); 33 | 34 | enum windowVisibilityState { FULLY_VISIBLE, PARTIALLY_VISIBILE, OBSCURED }; 35 | enum windowVisibilityState getWindowVisibilityState(void) { return windowVisibility; } 36 | 37 | protected: 38 | 39 | Xrm xrm; 40 | void checkArgs (int argc, char** argv) const; 41 | class MeterNode { 42 | public: 43 | MeterNode( Meter *fm ) { meter_ = fm; next_ = NULL; } 44 | 45 | Meter *meter_; 46 | MeterNode *next_; 47 | }; 48 | 49 | MeterNode *meters_; 50 | 51 | int caption_, legend_, xoff_, yoff_, nummeters_, usedlabels_; 52 | int hmargin_, vmargin_, vspacing_; 53 | unsigned long sleeptime_, usleeptime_; 54 | 55 | void usleep_via_select( unsigned long usec ); 56 | void addmeter( Meter *fm ); 57 | void checkMeterResources( void ); 58 | 59 | int findx( void ); 60 | int findy( void ); 61 | void dolegends( void ); 62 | 63 | void checkOverallResources(); 64 | void resizeEvent( XConfigureEvent &event ); 65 | void exposeEvent( XExposeEvent &event ); 66 | void keyPressEvent( XKeyEvent &event ); 67 | void visibilityEvent( XVisibilityEvent &event ); 68 | void unmapEvent( XUnmapEvent &event); 69 | void checkVersion(int argc, char *argv[]) const; 70 | 71 | private: 72 | 73 | bool _deferred_resize; 74 | bool _deferred_redraw; 75 | enum windowVisibilityState windowVisibility; 76 | }; 77 | 78 | #ifdef DEBUG 79 | #define XOSDEBUG(...) { \ 80 | fprintf(stderr, "%s:%d: ", __func__, __LINE__); \ 81 | fprintf(stderr, __VA_ARGS__); \ 82 | } 83 | #else 84 | #define XOSDEBUG(...) 85 | #endif 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /xosview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hills/xosview/0af72a3cba4f55a7aa58ac2988cda6c3a1fe2a36/xosview.png --------------------------------------------------------------------------------