Compare commits

...

30 Commits

Author SHA1 Message Date
David Lindes f949537280 Add time.h include to ttyload.h
Not sure why this ever worked; now works on Raspberry Pi.
2013-10-24 20:39:17 -07:00
David Lindes e9cf5ae0d6 0.5.3: Fix issue#1, time display for large -i
Plus a tiny bit of re-factoring, while I was there.
2013-03-12 14:51:48 +01:00
David Lindes f03201fd7d Removing code that by visual inspection can't happen.
(And wasn't supposed to, it was just a paranoid check.)
2013-03-11 11:40:26 +01:00
David Lindes 4750954345 add Flattr linkage 2012-08-09 22:15:14 +02:00
David Lindes b443a7011f fix indending, now that this is markdown 2012-08-09 22:15:00 +02:00
David Lindes b3e8738ce4 converting README to README.md (markdown) 2012-08-09 22:11:57 +02:00
David Lindes c4b6c48674 updated HISTORY to reflect 0.5.2 release 2012-06-06 14:01:57 +02:00
David Lindes 9c0ada5727 a couple quick ideas 2011-02-19 02:56:26 -08:00
David Lindes af4e7f7881 bumping revision for a new release 2011-02-13 23:49:25 -08:00
David Lindes 9c1783c05b fixed bug in time display
how have I failed to notice this?  It's apparently been broken since
2001.  Would display a time such as 23:48:19 as 3:48:19.  Oops.
2011-02-13 23:44:56 -08:00
David Lindes 7dcee4c59d removed $Id$, not relevant in git 2011-02-06 15:28:01 -08:00
David Lindes 0dfc80c502 Version 0.5.1; updated README, created HISTORY and .gitattributes 2011-02-06 01:21:48 -08:00
David Lindes 90c835047c Merge branch 'newexport' 2011-02-06 01:16:07 -08:00
David Lindes f8928d715f re-wrote exportit to use git 2011-02-06 01:15:40 -08:00
David Lindes 5a7c09aa24 ignore *.o and arch/[symlinks] 2010-03-04 16:46:41 -08:00
David Lindes 1abc690bb0 shorten usage string to be <= 509 bytes (maximum constant string length
required to be supported by C90 standard, per gcc)
2010-03-04 16:43:48 -08:00
David Lindes 30d928b0bc add use -Werror 2010-03-04 16:38:38 -08:00
lindes c72ca55e7d remove things more verbosely; remove .cvsignore, too. 2008-09-17 02:52:44 +00:00
lindes 9b6b97ca09 a bit of cleanup of export script... Hopefully now works, even off vax. 2008-09-17 02:49:14 +00:00
lindes 7f15375ba1 use ksh, for test -e 2008-09-17 02:35:28 +00:00
lindes 048e85775d updates to usage statement. 2008-09-17 02:30:45 +00:00
lindes 330c663f80 initial version of a ttyload man page 2008-09-17 02:30:12 +00:00
lindes 80b66b87c3 finally releasing version 0.5 -- not the curses re-write I might have
hoped for, but it has a few improvements.  And I'm now licensing in
something based on the ISC license, which is pretty open... should
qualify this as OSS.
2008-09-17 02:05:10 +00:00
lindes 66aea37c27 late checkin of a stab at a jamfile 2005-11-08 04:50:31 +00:00
lindes eb9b8a0867 make a thisarch symlink 2005-09-09 19:52:11 +00:00
lindes dd71ab20ad add Version to archtest output 2005-09-07 00:14:23 +00:00
lindes 788e34dd8e added Isilon arch, plus cleanup of how archlinks stuff is done (only
link once, etc)...  partially untested, because my nodes are acting up
in strange ways, but I think it works -- haven't broken FreeBSD, anyway.
2005-07-30 22:52:46 +00:00
lindes 1571acae74 Don't need ascftime, we've already converted to using strftime, as it
should have been in the first place, I suspect... so getting rid of old
cruft related to that.
2005-07-30 22:32:19 +00:00
lindes cfe7ba5339 mostly minor makefile cleanup, but of note: added archlinks concept 2005-07-30 22:26:11 +00:00
lindes d9bf7098ca found a bug while showing this to someone at USENIX 2004-07-01 19:13:13 +00:00
19 changed files with 385 additions and 187 deletions

View File

@ -1,3 +0,0 @@
ttyload
archtest
loader

3
.gitattributes vendored Normal file
View File

@ -0,0 +1,3 @@
exportit export-ignore
.gitignore export-ignore
.gitattributes export-ignore

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
ttyload
archtest
loader
*.o
arch/Darwin
arch/Isilon-OneFS
arch/thisarch

15
HISTORY Normal file
View File

@ -0,0 +1,15 @@
0.5.3
Fixed up time display more, especially for e.g. -i 120
(see https://github.com/lindes/ttyload/issues/1 )
0.5.2
Fixed a bug in time display
0.5.1
Converted to Git; uploaded to GitHub; documentation tweaks
0.5, and prior
See http://www.daveltd.com/src/util/ttyload/changelog.html
for history further back; this is currently maintained in a
separate repository for my website, though I'll likely move
it into this tree at some point.

28
Jamfile Normal file
View File

@ -0,0 +1,28 @@
# where to find headers (note: we still depend on Makefile to make
# arch/thisarch -- for the moment):
HDRS = . arch/thisarch arch/default ;
EXEMODE = 755 ;
# get our version information (hmm, maybe this would be cleaner if I
# made a version.h from Version? I'd have to figure out how to do that
# in Jam, too, of course)
# CCFLAGS = -DVERSION="\\\"`cat Version`\\\"" ;
ObjectCcFlags ttyload.c archtest.c : -DVERSION="\\\"`cat Version`\\\"" ;
ARCH_SOURCES =
arch/thisarch/getload.c
arch/thisarch/terminfo.c
;
# Alas, this doesn't work:
# SoftLink arch/thisarch : arch/`uname -s | sed -e 's/ /-/g'` ;
# main program:
Main ttyload : ttyload.c $(ARCH_SOURCES) ;
# XXX note: this re-builds the .o versions of $(ARCH_SOURCES), even
# though they're already built for ttyload. I don't grok why, or how to
# fix it. sigh.
# archtest program:
Main archtest : archtest.c $(ARCH_SOURCES) ;

35
LICENSE
View File

@ -1,25 +1,26 @@
The following license and related info applies to ttyload and
all of the supporting components:
ttyload
Copyright 1996-2001 by David Lindes, All rights reserved.
* ttyload *
Copyright 1996-2008 by David Lindes, All rights reserved.
This is an early "release" of ttyload. You're welcome to use it
how you will, and submit any patches you like back to me, but
please do not redistribute it. You may tell others about it,
and have them refer to http://www.daveltd.com/src/util/ttyload/
to get more information and/or the latest download, but please
don't distribute it directly.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
I expect to release it under a different license sometime in the
future, time TBD.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Note: there is absolutely no warranty of any kind on any
software contained herein. Use at your own risk, etc.
It is requested, without requirement, that any enhancements to this
software be submitted back to the author, whose contact information can
be found at the official web page for this software:
Thanks,
http://www.daveltd.com/src/util/ttyload/
David Lindes
P.S. Send feedback to: <src/ttyload@daveltd.com>, or whatever
method, if any, is given on the web page mentioned above.
(Note: the above is a modified version of the "ISC License", as
extracted from http://en.wikipedia.org/wiki/ISC_license 2008-09-16.)

View File

@ -6,15 +6,15 @@
# somewhere else:
INSTALLDIR = /usr/local/bin
ARCH = `uname -s`
ARCH = `uname -s | sed -e 's/ /-/g'`
LDFLAGS = `./ldflags`
OBJS = arch/${ARCH}/getload.o \
arch/${ARCH}/terminfo.o \
arch/default/homebrews.o
${NULL}
# this is what I use most places...
CC=gcc -pedantic -Wall
CC=gcc -pedantic -Wall -Werror
# for the things in the sub-directory:
INCLUDES = -I$${PWD:-.} \
@ -34,11 +34,35 @@ PROGRAMS = archbuild
default: $(PROGRAMS)
test: archbuild
test: $(PROGRAMS)
./ttyload -i 1
archbuild:
make ttyload archtest ARCH=`uname -s`
# which architechtures are just symlinks?
ARCHLINKS_FREEBSD = \
arch/Darwin \
arch/Isilon-OneFS \
${NULL}
ARCHLINKS_THISARCH = \
arch/thisarch \
${NULL}
ARCHLINKS = \
$(ARCHLINKS_FREEBSD) \
$(ARCHLINKS_THISARCH) \
${NULL}
# Some architechtures mimic eachother:
$(ARCHLINKS_FREEBSD):
ln -s FreeBSD $@
$(ARCHLINKS_THISARCH):
ln -s ${ARCH} $@
archlinks: $(ARCHLINKS)
archbuild: archlinks
make archtest ttyload ARCH=$(ARCH)
ttyload.c: ttyload.h Version
touch ttyload.c
@ -54,10 +78,10 @@ clean:
rm -f *.o $(OBJS) core a.out
clobber: clean
rm -f loader ttyload archtest
rm -f loader ttyload archtest $(ARCHLINKS)
# install, gently. not much to it:
install: archbuild
install: $(PROGRAMS)
/bin/cp ttyload ${INSTALLDIR}/ttyload
# because different systems' make have different behaviors on how they

View File

@ -1,6 +1,7 @@
****************
* INTRODUCTION *
****************
Home page: http://www.daveltd.com/src/util/ttyload/
GitHub: https://github.com/lindes/ttyload/
## INTRODUCTION
Hi there,
@ -26,7 +27,7 @@ And I know of no other utilities that perform quite this task.
For a while, I only needed it on one platform, and so I simply
recompiled it from time to time as I moved from one machine to
another. But, eventually, I stopped having such a homogeneous
environment, and wanted it for other platforms. But different
environment, and wanted it for other platforms. And different
platforms required different methods of getting data about the
load averages... For a while, I didn't feel quite enough of a
desire to have it elsewhere to make it work. But eventually I
@ -52,11 +53,9 @@ versions as they become available, point your browser towards:
Thanks,
David Lindes
David Lindes
****************
* PLATFORMS... *
****************
## PLATFORMS...
ttyload has been shown to run on systems running, at least:
@ -66,14 +65,13 @@ ttyload has been shown to run on systems running, at least:
- FreeBSD (some version or other, I'm not familiar with their
numbering system... 4.4, I think.)
- Solaris 2.x and later (at least 2.6 and 8)
- Isilon OneFS
Feel free, if you like, to submit patches to add more platforms
(or other versions of existing platforms), and please let me
know also if it runs unmodified on any other platforms.
****************
* INSTALLATION *
****************
## INSTALLATION
to build ttyload, in theory all you need to is type 'make'. If
you want to also install it, 'make install' should do the trick,
@ -81,9 +79,7 @@ which will copy it to /usr/local/bin (or another directory if
you edit the INSTALLDIR setting in the Makefile or do
'make install INSTALLDIR=whatever').
****************
* RUN-TIME FOO *
****************
## RUN-TIME FOO
After building, you can run ttyload with './ttyload' (or just
'ttyload' if either '.' is in your $PATH, or you did the make
@ -103,9 +99,7 @@ and then simultaneously press the "c" key), or whatever you have
'stty intr' set to. If and when I have a curses mode,
presumably 'q' and/or '<esc>' will work too.
****************
* OTHER THINGS *
****************
## OTHER THINGS
- ttyload -h gives you usage info.
@ -139,3 +133,7 @@ presumably 'q' and/or '<esc>' will work too.
at <src/ttyload@daveltd.com> (yes, '/' is valid in an e-mail address!
If your mailer can't hack it, though, you can substitute '-' for it,
if you must).
- Feel free to
[![Flattr this project](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=lindes&url=https://github.com/lindes/ttyload&title=ttyload&tags=github&category=software),
if you find it useful. Your support would be appreciated. :)

5
TODO
View File

@ -6,3 +6,8 @@ Lots of stuff todo... here are a few big items:
Also, see http://www.daveltd.com/src/util/ttyload/ for other
stuff that may be on my list.
And some small stuff:
- add color to load numbers at the top of the screen
- add an option to suppress the Legend

View File

@ -1 +1 @@
0.5-pre1
0.5.3

View File

@ -1,4 +0,0 @@
/* This file contains platform settings for Linux */
/* at least my Linux box doesn't have ascftime, so we've got to fall back to asctime() */
#undef HAVE_ASCFTIME

View File

@ -1,53 +0,0 @@
/* some function replacements for platforms that don't have the
* real things... *sigh* */
#include <string.h>
#include <time.h>
#include <stdio.h>
/**********************/
/***** ascftime() *****/
/**********************/
#ifndef HAVE_ASCFTIME
/* our own version of ascftime, since Linux (and others?)
* doesn't (don't) seem to have it. For now, this is done in a
* very klugey way, and it will certainly need to be re-written
* (to be useful, anyway) if and when there ever become new
* format strings used by our caller(s). */
int ascftime(char *s, const char *format, const struct tm *timeptr)
{
int ret;
/* if we don't have arguments, bail now. */
if(!s || !format || !timeptr)
{
return(0);
}
*s = '\0';
if(strncmp(format, "^%H:%M", 6) == 0)
{
ret = sprintf(s, "^%02d:%02d",
timeptr->tm_hour, timeptr->tm_min);
}
else if(strncmp(format, "%T", 2) == 0)
{
ret = sprintf(s, "^%02d:%02d:%02d",
timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec);
}
else
{
/* indicate failure, since we don't have generic
* compliance for any old format: */
ret = 0;
}
return(ret);
}
#endif /* HAVE_ASCFTIME */

View File

@ -1,4 +0,0 @@
/* This file contains default platform settings */
/* do we have ascftime()? */
#define HAVE_ASCFTIME

View File

@ -23,5 +23,7 @@ int main(int argc, char *argv[])
(loads.five_minute / 1024.0),
(loads.fifteen_minute / 1024.0));
printf("Version: %s\n", VERSION);
return(0);
}

View File

@ -1,15 +1,17 @@
#!/bin/sh
#!/bin/ksh
# exportit -- a simple little script to export something from a
# CVS repository and create a "release" tarbal of it, in mostly
# automated fasion. Could probably stand do more error
# checking, but if things are happy, it works. :-) Note that
# people getting this with ttyload will have no reason to use it
# in conjunction with ttyload.
# git repository and create a "release" tarbal of it, in mostly
# automated fasion. Re-written from an earlier CVS version.
# Copyright 2001 by David Lindes, All Rights Reserved.
# Distributed under the license described in the file LICENSE
# that comes with ttyload.
# Note that people getting this with ttyload will presumably have no
# reason to use it in conjunction with ttyload, unless they're forking
# their own version. I'd much prefer to get patches or pull requests
# (e.g. on GitHub, though from your own git repo is fine, too).
# Copyright 2001-2011 by David Lindes, All Rights Reserved.
# Distributed under the license described in the file LICENSE that
# comes with ttyload.
# if you're wanting to use this script for some other project,
# and you want to call your release something other than the
@ -30,13 +32,12 @@ else
fi
# automagical settings for things:
path="`cat CVS/Repository`"
name="${name:-`basename "$path"`}"
name="${name:-ttyload}" # this used to be automatic, from CVS info. Skipping that now.
version="`cat Version`"
cvsvers="${name}_`echo \"$version\" | sed -e 's/[ \.]/_/g'`"
tagname="${name}_`echo \"$version\" | sed -e 's/[ \.]/_/g'`"
dirname="$name-$version"
for item in "$dirname" "$dirname.tar" "$dirname.tar.gz"
for item in "$dirname.tar" "$dirname.tar.gz" "$dirname.tar.bz2"
do
if [ -e "$item" ]
then
@ -47,11 +48,10 @@ do
done
# let the user know what the settings came up with:
echo "Creating export of $name version $version (CVS: $cvsvers)"
echo "Creating export of $name version $version (tag: $tagname)"
# export, and if that fails, bail.
cvs export -d "$dirname" -r "$cvsvers" $path || exit 1
git archive --prefix=$dirname/ -o $dirname.tar $tagname || exit 1
# then tar and gzip:
tar cvf "$dirname.tar" "$dirname"
gzip -9fv "$dirname.tar"
# then bzip:
bzip2 -9fv "$dirname.tar"

65
exportit_cvs Executable file
View File

@ -0,0 +1,65 @@
#!/bin/ksh
# exportit -- a simple little script to export something from a
# CVS repository and create a "release" tarbal of it, in mostly
# automated fasion. Could probably stand do more error
# checking, but if things are happy, it works. :-) Note that
# people getting this with ttyload will have no reason to use it
# in conjunction with ttyload.
# Copyright 2001 by David Lindes, All Rights Reserved.
# Distributed under the license described in the file LICENSE
# that comes with ttyload.
# if you're wanting to use this script for some other project,
# and you want to call your release something other than the
# name of the directory above this one (.., but by name), change
# the "false" below to "true", and the "xyzprod" to whatever you
# want to call things. Note that your tagging will have to also
# be changed appropriately.
if false
then
# override the name of what to call stuff:
name="xyzprod"
else
# make sure name is unset, so that the ${name:-blah}
# expansion below doesn't get stuff from your environment
# accidentally
unset name
fi
# automagical settings for things:
path="`cat CVS/Repository`"
root="`cat CVS/Root`"
localroot="${root##*:}"
localpath="${path##${localroot}/}"
name="${name:-`basename "$path"`}"
version="`cat Version`"
cvsvers="${name}_`echo \"$version\" | sed -e 's/[ \.]/_/g'`"
dirname="$name-$version"
for item in "$dirname" "$dirname.tar" "$dirname.tar.gz"
do
if [ -e "$item" ]
then
echo "Sorry, $item exists, and I need it not to." >&2
echo "Please remove it or update your Version file to proceed." >&2
exit 1
fi
done
# let the user know what the settings came up with:
echo "Creating export of $name version $version (CVS: $cvsvers)"
# export, and if that fails, bail.
cvs export -d "$dirname" -r "$cvsvers" $localpath || exit 1
for file in `cat NOEXPORT`
do
(set -x; rm -rf "$dirname"/"$file")
done
# then tar and gzip:
tar cvf "$dirname.tar" "$dirname"
gzip -9fv "$dirname.tar"

102
ttyload.1 Normal file
View File

@ -0,0 +1,102 @@
.TH "ttyload" "1" "2001-08-24" "" ""
.SH "NAME"
ttyload \- a tty-based xload equivalent
.SH "SYNOPSIS"
.PP
ttyload [options]
.PP
.SH "DESCRIPTION"
.PP
ttyload is a "tty" based load monitoring tool\&. Not entirely unlike
xload, it plots a graph of a system's "load average" data\&. Unlike
xload, it uses 3 line graphs to plot things, instead of a single fill
graph, so that it can show you not only the 1-minute load average, but
also the 5-minute and 15-minute averages\&. Also unlike xload, it uses
a basic terminal (tty) to display the information, instead of an X
window\&. ANSI escape sequences are used (optionally) for colorization
and screen manipulation\&.
.PP
A few of the main features of ttyload are:
.PP
.IP o
graphs load averages (all 3 numbers) over time
.IP o
uses ANSI escape sequences to colorize graphs
.IP o
works without requiring X11 libraries, in a Terminal window
.IP o
automatically determines screen size by default
.PP
\" .SH "GENERAL"
\" .PP
\" See DESCRIPTION\&.
\" .PP
.SH "USAGE"
.PP
The easiest way to use ttyload is just to invoke the command, with no
additional options\&.
.PP
Additional options are described below\&.
.PP
To quit ttyload, enter the terminal's interrupt character (typically
control-C)\&.
.PP
\" .SH "EXAMPLES"
\" .PP
\" Here are some examples of how I use ttyload\&.
\" .PP
\" No examples written\&.
\" .RE
.PP
.SH "OPTIONS"
.PP
ttyload uses standard getopt() style options processing\&.
Available options are:
.PP
.DS
.PP
.IP "\fB-h\fP"
Display a brief usage statement ("help")\&.
.IP "\fB-v\fP"
show version info, then exit
.IP "\fB-m\fP"
monochrome mode (no ANSI escapes)
.IP "\fB-c <cols>\fP"
Sets the number of columns wide to make the display
.IP "\fB-r <rows>\fP"
Sets the number of rows high to make the display
(these two options combine to override the default behavior of
auto-determining screen size)
.IP "\fB-i <seconds>\fP"
Alter the number of seconds in the interval between
refreshes\&. The default is 4, and the minimum is 1, which is silently
clamped\&.
.DE
.PP
.PP
.SH "SEE ALSO"
.PP
getopt(3)
.PP
.PP
.SH "VERSION"
This man page is current for version 0\&.5 of ttyload
.PP
.SH "THANKS"
.PP
Thanks to several my friends for testing things out on various
platforms, or lending me accounts on their machines upon which
to do porting\&.
.PP
.SH "AUTHOR"
.PP
ttyload was written by David Lindes\&. Please send any feedback,
including bug reports and patches, to me\&. My contact information (as
well as updates and other information) can be found on the ttyload web
page at:
http://www\&.daveltd\&.com/src/util/ttyload/
.PP

128
ttyload.c
View File

@ -3,10 +3,11 @@
*
* tty equivalent to xload
*
* Copyright 1996 by David Lindes
* all right reserved.
* Copyright 1996-2011 by David Lindes
* All rights reserved.
*
* Version information: $Id: ttyload.c,v 1.22 2001-08-28 01:03:31 lindes Exp $
* Version information... stored in git now. Hopefully you're looking
* at this file from a git repo, and don't care. :)
*
*/
@ -33,24 +34,25 @@
#define MINROWS (HEIGHTPAD + 6)
#define MINCOLS (WIDTHPAD + 6)
char *c="$Id: ttyload.c,v 1.22 2001-08-28 01:03:31 lindes Exp $";
char strbuf[BUFSIZ],
*optstring = "i:hvmr:c:",
*usage =
"Usage: %s [-i secs]\n"
"Usage: %s [<options>]\n"
"\n"
" Available options:\n"
" -h -- show this help, then exit\n"
" -v -- show version info, then exit\n"
" -m -- monochrome mode\n"
" -c cols -- how many cols wide is the screen?\n"
" -r rows -- how many rows high is the screen?\n"
" -m -- monochrome mode (no ANSI escapes)\n"
" -c cols -- how wide is the screen?\n"
" -r rows -- and how high?\n"
" (these override the default auto-detect)\n"
" -i secs\n"
" Alter the number of seconds in "
"the interval between refreshes\n"
"the interval between refreshes.\n"
" The default is 4, and the minimum "
"is 1, which is silently clamped.\n\n"
" (Note: use ctrl-C to quit)\n\n"
" For updates and other info, see http://"
" For more info, see http://"
"www.daveltd.com/src/util/ttyload/\n";
int clockpad, clocks;
clock_info *theclocks;
@ -82,11 +84,14 @@ int rows = 40,
cols = 80,
intsecs = 4,
debug = 3,
debug = 0,
theclock = 0,
height, width;
/* other globals (ugh, I know, but it's a simple program, that needs re-writing) */
char hostname[HOSTLENGTH + 1];
load_list *loadavgs;
int compute_height(load_t, load_t, int);
void showloads(load_list *);
@ -95,15 +100,60 @@ void home_screen();
void cycle_load_list(load_list*, load_list, int);
void initialize_load_list(load_list *list, int size);
void print_header(int current)
{
printf("%s %.2f, %.2f, %.2f %s ttyload, v%s\n\n",
hostname,
(loadavgs[current].one_minute / 1024.),
(loadavgs[current].five_minute / 1024.),
(loadavgs[current].fifteen_minute / 1024.),
strbuf,
version);
}
void update_clocks(time_t thetime, struct tm *thetimetm, int position)
{
int lastclock = (theclock + clocks - 1) % clocks;
/* if we don't have a previous clock, or "enough" time has past to have another */
if(theclocks[lastclock].pos < 0 /* getting-started special */ ||
(((thetime - theclocks[lastclock].when) >= CLOCKWIDTH * intsecs) && /* enough visual buffer space */
((thetime / 60) > (theclocks[lastclock].when / 60)))) /* at least a minute (for different value) */
{
if(!strftime(strbuf, 7, "^%H:%M", thetimetm))
{
/* This should never happen, I hope... */
perror("strftime failed");
exit(1);
}
/* set up the current clock: */
theclocks[theclock].pos = position;
strcpy(theclocks[theclock].clock, strbuf);
theclocks[theclock].when = thetime;
++theclock;
theclock %= clocks;
/* as a temporary cleanup functionality after changing from
* clear_screen on every iteration to home_screen on all but
* the first, but since it's nice to occasionally actually
* clear (at least until we're actually using curses or the
* like, when we can put that activity on SIGWINCH and ctrl-L
* command, or the like), I'm using the enclosing if()
* condition as a "good" time to do that: */
clear_screen();
}
}
int main(argc, argv, envp)
int argc;
char *argv[],
*envp[];
{
load_list *loadavgs, newload;
load_list newload;
int c, i, errflag=0, versflag=0;
char *basename;
char hostname[HOSTLENGTH + 1];
time_t thetime;
struct tm *thetimetm;
@ -224,7 +274,7 @@ int main(argc, argv, envp)
clear_screen();
for(i=0;i<width;i++)
for(i=0; i<width; ++i /* note: gets decremented, too; this is forever! */)
{
if(i != 0)
{
@ -237,40 +287,7 @@ int main(argc, argv, envp)
getload(&loadavgs[i]);
if(((thetimetm->tm_sec) / intsecs) == 0)
{
if(!strftime(strbuf, 7, "^%H:%M", thetimetm))
{
/* This should never happen, I hope... */
perror("strftime failed");
exit(1);
}
theclocks[theclock].pos = i;
strcpy(theclocks[theclock].clock, strbuf);
theclock++;
theclock %= clocks;
if(theclock >= clocks)
{
/* Hopefully, I'll get this to the point
where it well never happen... As I first
write it, I'm fairly certain it will, but
that should be fixable... */
fprintf(stderr, "Internal error: too many clocks!");
exit(1);
}
/* as a temporary cleanup functionality after
* changing from clear_screen on every iteration to
* home_screen on all but the first, but since it's
* nice to occasionally actually clear (at least
* until we're actually using curses or the like,
* when we can put that activity on SIGWINCH and
* ctrl-L command, or the like), I'm using the
* enclosing if() condition as a "good" time to do
* that: */
clear_screen();
}
update_clocks(thetime, thetimetm, i);
if(!strftime(strbuf, 9, "%H:%M:%S", thetimetm))
{
@ -280,14 +297,7 @@ int main(argc, argv, envp)
}
home_screen();
printf("%s %.2f, %.2f, %.2f %s ttyload, v%s\n\n",
hostname,
(loadavgs[i].one_minute / 1024.),
(loadavgs[i].five_minute / 1024.),
(loadavgs[i].fifteen_minute / 1024.),
strbuf + 1,
version);
print_header(i);
if(debug > 3)
printf("Load averages: %f, %f, %f\n",
@ -448,7 +458,7 @@ void showloads(loadavgs)
for(i=0;i<clocks;i++)
{
if(theclocks[i].pos > 0)
if(theclocks[i].pos >= 0)
{
strncpy(
&strbuf[9+theclocks[i].pos],
@ -483,7 +493,7 @@ int compute_height(thisload, maxload, height)
if(thisload < 0)
return(height + 1);
/* this is a reversal of what you might thing... the X axis
/* this is a reversal of what you might think... the X axis
* is really on the top of the graph, so larger heights sit
* lower. the 'height -' part is implicitly done elsewhere.
* (but not really ever actually done) */

View File

@ -3,12 +3,12 @@
*
* support file for ttyload.c
*
* Copyright 1996 David Lindes,
* all rights reserved.
* Copyright 1996-2011 David Lindes.
* All rights reserved.
*
*/
#define TTYLOAD_H_IDENT "$Id: ttyload.h,v 1.6 2001-08-28 01:00:31 lindes Exp $";
#include <time.h> /* because we use time_t inside this file */
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
@ -29,9 +29,11 @@ typedef struct load_list {
int numloads;
} load_list;
/* storage for clock display along the bottom */
typedef struct clock_info {
int pos;
char clock[6];
time_t when;
} clock_info;
/* functions in arch-specific files: */