home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume21 / perf / part01 < prev    next >
Encoding:
Text File  |  1994-01-10  |  75.7 KB  |  2,608 lines

  1. Newsgroups: comp.sources.x
  2. From: kssingvo@cip.informatik.uni-erlangen.de (Klaus Singvogel)
  3. Subject: v21i087: perf - A better perfmeter clone, Part01/01
  4. Message-ID: <1994Jan10.200324.4117@sparky.sterling.com>
  5. X-Md4-Signature: b347abb4eb0111c977ba2f444fc7ea1f
  6. Keywords: X11,xview,perfmeter
  7. Sender: chris@sparky.sterling.com (Chris Olson)
  8. Reply-To: rfkoenig@immd4.informatik.uni-erlangen.de
  9. Organization: Student Pool, CSD, University of Erlangen, Germany
  10. Date: Mon, 10 Jan 1994 20:03:24 GMT
  11. Approved: chris@sterling.com
  12.  
  13. Submitted-by: kssingvo@cip.informatik.uni-erlangen.de (Klaus Singvogel)
  14. Posting-number: Volume 21, Issue 87
  15. Archive-name: perf/part01
  16. Environment: X11, XView
  17.  
  18.  
  19. perf - report kernel statistics visually.
  20.  
  21. perf is a XView program that reports kernel statistics for a given host
  22. (or for the localhost if no host is specified).
  23.  
  24. Features are:
  25. Scrollback, multi column support, multi color support for displaying
  26. subvalues like e.g. usr, nice & sys in *one* (here: cpu) field, displaying
  27. statistics of a remote host and much more.
  28.  
  29. The displayed window consists of one or more fields, each showing a
  30. specified parameter. The name of the parameter and of its components are
  31. shown in the lower left corner of the field, the maximum value of the
  32. visible data in the lower right corner.
  33.  
  34. Tested on HP/UX, SunOS 4.1.x, Linux with different C compilers.
  35.  
  36. perf can also be found on ftp.informatik.uni-erlangen.de:
  37. pub/Linux/LOCAL/rstatd/perf.tgz.
  38. For Linux you need the kernel patch and rstatd, found in the same
  39. directory.
  40.  
  41. For a first look, configure, compile and start it; click with the "right"
  42. button into the display window. You will get a new window, in which you
  43. can set many parameters. "apply" Button to activate the parameters.
  44. "Hide window" or another right button click into the display window will
  45. remove the paramter window.
  46.  
  47. #! /bin/sh
  48. # This is a shell archive.  Remove anything before this line, then unpack
  49. # it by saving it into a file and typing "sh file".  To overwrite existing
  50. # files, type "sh file -c".  You can also feed this as standard input via
  51. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  52. # will see the following message at the end:
  53. #        "End of shell archive."
  54. # Contents:  perf perf/Imakefile perf/LICENSE perf/Makefile.simple
  55. #   perf/README perf/README.linux perf/icon.xbm perf/perf.1
  56. #   perf/perf.c perf/rstattest.c
  57. # Wrapped by kssingvo@medusa on Wed Nov 24 14:05:14 1993
  58. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  59. if test ! -d 'perf' ; then
  60.     echo shar: Creating directory \"'perf'\"
  61.     mkdir 'perf'
  62. fi
  63. if test -f 'perf/Imakefile' -a "${1}" != "-c" ; then 
  64.   echo shar: Will not clobber existing file \"'perf/Imakefile'\"
  65. else
  66. echo shar: Extracting \"'perf/Imakefile'\" \(383 characters\)
  67. sed "s/^X//" >'perf/Imakefile' <<'END_OF_FILE'
  68. X#include <XView.tmpl>
  69. X
  70. XSYS_LIBRARIES = -lrpcsvc
  71. XDEPLIBS = XViewClientDepLibs
  72. XLOCAL_LIBRARIES = XViewClientLibs
  73. X
  74. XMAKEFILE_SIMPLE = Makefile.simple
  75. XICON            = icon.xbm
  76. XSRCS            = perf.c
  77. XALLFILES        = $(MAKEFILE_SIMPLE) $(SRCS) $(ICON)
  78. X
  79. XPROGRAMS    = perf rstattest
  80. X
  81. XAllTarget($(PROGRAMS))
  82. XSingleProgramTarget(perf,perf.o,$(LOCAL_LIBRARIES), /**/)
  83. X
  84. X#include <XView.prog>
  85. END_OF_FILE
  86. if test 383 -ne `wc -c <'perf/Imakefile'`; then
  87.     echo shar: \"'perf/Imakefile'\" unpacked with wrong size!
  88. fi
  89. # end of 'perf/Imakefile'
  90. fi
  91. if test -f 'perf/LICENSE' -a "${1}" != "-c" ; then 
  92.   echo shar: Will not clobber existing file \"'perf/LICENSE'\"
  93. else
  94. echo shar: Extracting \"'perf/LICENSE'\" \(17982 characters\)
  95. sed "s/^X//" >'perf/LICENSE' <<'END_OF_FILE'
  96. X            GNU GENERAL PUBLIC LICENSE
  97. X               Version 2, June 1991
  98. X
  99. X Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  100. X                          675 Mass Ave, Cambridge, MA 02139, USA
  101. X Everyone is permitted to copy and distribute verbatim copies
  102. X of this license document, but changing it is not allowed.
  103. X
  104. X                Preamble
  105. X
  106. X  The licenses for most software are designed to take away your
  107. Xfreedom to share and change it.  By contrast, the GNU General Public
  108. XLicense is intended to guarantee your freedom to share and change free
  109. Xsoftware--to make sure the software is free for all its users.  This
  110. XGeneral Public License applies to most of the Free Software
  111. XFoundation's software and to any other program whose authors commit to
  112. Xusing it.  (Some other Free Software Foundation software is covered by
  113. Xthe GNU Library General Public License instead.)  You can apply it to
  114. Xyour programs, too.
  115. X
  116. X  When we speak of free software, we are referring to freedom, not
  117. Xprice.  Our General Public Licenses are designed to make sure that you
  118. Xhave the freedom to distribute copies of free software (and charge for
  119. Xthis service if you wish), that you receive source code or can get it
  120. Xif you want it, that you can change the software or use pieces of it
  121. Xin new free programs; and that you know you can do these things.
  122. X
  123. X  To protect your rights, we need to make restrictions that forbid
  124. Xanyone to deny you these rights or to ask you to surrender the rights.
  125. XThese restrictions translate to certain responsibilities for you if you
  126. Xdistribute copies of the software, or if you modify it.
  127. X
  128. X  For example, if you distribute copies of such a program, whether
  129. Xgratis or for a fee, you must give the recipients all the rights that
  130. Xyou have.  You must make sure that they, too, receive or can get the
  131. Xsource code.  And you must show them these terms so they know their
  132. Xrights.
  133. X
  134. X  We protect your rights with two steps: (1) copyright the software, and
  135. X(2) offer you this license which gives you legal permission to copy,
  136. Xdistribute and/or modify the software.
  137. X
  138. X  Also, for each author's protection and ours, we want to make certain
  139. Xthat everyone understands that there is no warranty for this free
  140. Xsoftware.  If the software is modified by someone else and passed on, we
  141. Xwant its recipients to know that what they have is not the original, so
  142. Xthat any problems introduced by others will not reflect on the original
  143. Xauthors' reputations.
  144. X
  145. X  Finally, any free program is threatened constantly by software
  146. Xpatents.  We wish to avoid the danger that redistributors of a free
  147. Xprogram will individually obtain patent licenses, in effect making the
  148. Xprogram proprietary.  To prevent this, we have made it clear that any
  149. Xpatent must be licensed for everyone's free use or not licensed at all.
  150. X
  151. X  The precise terms and conditions for copying, distribution and
  152. Xmodification follow.
  153. X
  154. X            GNU GENERAL PUBLIC LICENSE
  155. X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  156. X
  157. X  0. This License applies to any program or other work which contains
  158. Xa notice placed by the copyright holder saying it may be distributed
  159. Xunder the terms of this General Public License.  The "Program", below,
  160. Xrefers to any such program or work, and a "work based on the Program"
  161. Xmeans either the Program or any derivative work under copyright law:
  162. Xthat is to say, a work containing the Program or a portion of it,
  163. Xeither verbatim or with modifications and/or translated into another
  164. Xlanguage.  (Hereinafter, translation is included without limitation in
  165. Xthe term "modification".)  Each licensee is addressed as "you".
  166. X
  167. XActivities other than copying, distribution and modification are not
  168. Xcovered by this License; they are outside its scope.  The act of
  169. Xrunning the Program is not restricted, and the output from the Program
  170. Xis covered only if its contents constitute a work based on the
  171. XProgram (independent of having been made by running the Program).
  172. XWhether that is true depends on what the Program does.
  173. X
  174. X  1. You may copy and distribute verbatim copies of the Program's
  175. Xsource code as you receive it, in any medium, provided that you
  176. Xconspicuously and appropriately publish on each copy an appropriate
  177. Xcopyright notice and disclaimer of warranty; keep intact all the
  178. Xnotices that refer to this License and to the absence of any warranty;
  179. Xand give any other recipients of the Program a copy of this License
  180. Xalong with the Program.
  181. X
  182. XYou may charge a fee for the physical act of transferring a copy, and
  183. Xyou may at your option offer warranty protection in exchange for a fee.
  184. X
  185. X  2. You may modify your copy or copies of the Program or any portion
  186. Xof it, thus forming a work based on the Program, and copy and
  187. Xdistribute such modifications or work under the terms of Section 1
  188. Xabove, provided that you also meet all of these conditions:
  189. X
  190. X    a) You must cause the modified files to carry prominent notices
  191. X    stating that you changed the files and the date of any change.
  192. X
  193. X    b) You must cause any work that you distribute or publish, that in
  194. X    whole or in part contains or is derived from the Program or any
  195. X    part thereof, to be licensed as a whole at no charge to all third
  196. X    parties under the terms of this License.
  197. X
  198. X    c) If the modified program normally reads commands interactively
  199. X    when run, you must cause it, when started running for such
  200. X    interactive use in the most ordinary way, to print or display an
  201. X    announcement including an appropriate copyright notice and a
  202. X    notice that there is no warranty (or else, saying that you provide
  203. X    a warranty) and that users may redistribute the program under
  204. X    these conditions, and telling the user how to view a copy of this
  205. X    License.  (Exception: if the Program itself is interactive but
  206. X    does not normally print such an announcement, your work based on
  207. X    the Program is not required to print an announcement.)
  208. X
  209. XThese requirements apply to the modified work as a whole.  If
  210. Xidentifiable sections of that work are not derived from the Program,
  211. Xand can be reasonably considered independent and separate works in
  212. Xthemselves, then this License, and its terms, do not apply to those
  213. Xsections when you distribute them as separate works.  But when you
  214. Xdistribute the same sections as part of a whole which is a work based
  215. Xon the Program, the distribution of the whole must be on the terms of
  216. Xthis License, whose permissions for other licensees extend to the
  217. Xentire whole, and thus to each and every part regardless of who wrote it.
  218. X
  219. XThus, it is not the intent of this section to claim rights or contest
  220. Xyour rights to work written entirely by you; rather, the intent is to
  221. Xexercise the right to control the distribution of derivative or
  222. Xcollective works based on the Program.
  223. X
  224. XIn addition, mere aggregation of another work not based on the Program
  225. Xwith the Program (or with a work based on the Program) on a volume of
  226. Xa storage or distribution medium does not bring the other work under
  227. Xthe scope of this License.
  228. X
  229. X  3. You may copy and distribute the Program (or a work based on it,
  230. Xunder Section 2) in object code or executable form under the terms of
  231. XSections 1 and 2 above provided that you also do one of the following:
  232. X
  233. X    a) Accompany it with the complete corresponding machine-readable
  234. X    source code, which must be distributed under the terms of Sections
  235. X    1 and 2 above on a medium customarily used for software interchange; or,
  236. X
  237. X    b) Accompany it with a written offer, valid for at least three
  238. X    years, to give any third party, for a charge no more than your
  239. X    cost of physically performing source distribution, a complete
  240. X    machine-readable copy of the corresponding source code, to be
  241. X    distributed under the terms of Sections 1 and 2 above on a medium
  242. X    customarily used for software interchange; or,
  243. X
  244. X    c) Accompany it with the information you received as to the offer
  245. X    to distribute corresponding source code.  (This alternative is
  246. X    allowed only for noncommercial distribution and only if you
  247. X    received the program in object code or executable form with such
  248. X    an offer, in accord with Subsection b above.)
  249. X
  250. XThe source code for a work means the preferred form of the work for
  251. Xmaking modifications to it.  For an executable work, complete source
  252. Xcode means all the source code for all modules it contains, plus any
  253. Xassociated interface definition files, plus the scripts used to
  254. Xcontrol compilation and installation of the executable.  However, as a
  255. Xspecial exception, the source code distributed need not include
  256. Xanything that is normally distributed (in either source or binary
  257. Xform) with the major components (compiler, kernel, and so on) of the
  258. Xoperating system on which the executable runs, unless that component
  259. Xitself accompanies the executable.
  260. X
  261. XIf distribution of executable or object code is made by offering
  262. Xaccess to copy from a designated place, then offering equivalent
  263. Xaccess to copy the source code from the same place counts as
  264. Xdistribution of the source code, even though third parties are not
  265. Xcompelled to copy the source along with the object code.
  266. X
  267. X  4. You may not copy, modify, sublicense, or distribute the Program
  268. Xexcept as expressly provided under this License.  Any attempt
  269. Xotherwise to copy, modify, sublicense or distribute the Program is
  270. Xvoid, and will automatically terminate your rights under this License.
  271. XHowever, parties who have received copies, or rights, from you under
  272. Xthis License will not have their licenses terminated so long as such
  273. Xparties remain in full compliance.
  274. X
  275. X  5. You are not required to accept this License, since you have not
  276. Xsigned it.  However, nothing else grants you permission to modify or
  277. Xdistribute the Program or its derivative works.  These actions are
  278. Xprohibited by law if you do not accept this License.  Therefore, by
  279. Xmodifying or distributing the Program (or any work based on the
  280. XProgram), you indicate your acceptance of this License to do so, and
  281. Xall its terms and conditions for copying, distributing or modifying
  282. Xthe Program or works based on it.
  283. X
  284. X  6. Each time you redistribute the Program (or any work based on the
  285. XProgram), the recipient automatically receives a license from the
  286. Xoriginal licensor to copy, distribute or modify the Program subject to
  287. Xthese terms and conditions.  You may not impose any further
  288. Xrestrictions on the recipients' exercise of the rights granted herein.
  289. XYou are not responsible for enforcing compliance by third parties to
  290. Xthis License.
  291. X
  292. X  7. If, as a consequence of a court judgment or allegation of patent
  293. Xinfringement or for any other reason (not limited to patent issues),
  294. Xconditions are imposed on you (whether by court order, agreement or
  295. Xotherwise) that contradict the conditions of this License, they do not
  296. Xexcuse you from the conditions of this License.  If you cannot
  297. Xdistribute so as to satisfy simultaneously your obligations under this
  298. XLicense and any other pertinent obligations, then as a consequence you
  299. Xmay not distribute the Program at all.  For example, if a patent
  300. Xlicense would not permit royalty-free redistribution of the Program by
  301. Xall those who receive copies directly or indirectly through you, then
  302. Xthe only way you could satisfy both it and this License would be to
  303. Xrefrain entirely from distribution of the Program.
  304. X
  305. XIf any portion of this section is held invalid or unenforceable under
  306. Xany particular circumstance, the balance of the section is intended to
  307. Xapply and the section as a whole is intended to apply in other
  308. Xcircumstances.
  309. X
  310. XIt is not the purpose of this section to induce you to infringe any
  311. Xpatents or other property right claims or to contest validity of any
  312. Xsuch claims; this section has the sole purpose of protecting the
  313. Xintegrity of the free software distribution system, which is
  314. Ximplemented by public license practices.  Many people have made
  315. Xgenerous contributions to the wide range of software distributed
  316. Xthrough that system in reliance on consistent application of that
  317. Xsystem; it is up to the author/donor to decide if he or she is willing
  318. Xto distribute software through any other system and a licensee cannot
  319. Ximpose that choice.
  320. X
  321. XThis section is intended to make thoroughly clear what is believed to
  322. Xbe a consequence of the rest of this License.
  323. X
  324. X  8. If the distribution and/or use of the Program is restricted in
  325. Xcertain countries either by patents or by copyrighted interfaces, the
  326. Xoriginal copyright holder who places the Program under this License
  327. Xmay add an explicit geographical distribution limitation excluding
  328. Xthose countries, so that distribution is permitted only in or among
  329. Xcountries not thus excluded.  In such case, this License incorporates
  330. Xthe limitation as if written in the body of this License.
  331. X
  332. X  9. The Free Software Foundation may publish revised and/or new versions
  333. Xof the General Public License from time to time.  Such new versions will
  334. Xbe similar in spirit to the present version, but may differ in detail to
  335. Xaddress new problems or concerns.
  336. X
  337. XEach version is given a distinguishing version number.  If the Program
  338. Xspecifies a version number of this License which applies to it and "any
  339. Xlater version", you have the option of following the terms and conditions
  340. Xeither of that version or of any later version published by the Free
  341. XSoftware Foundation.  If the Program does not specify a version number of
  342. Xthis License, you may choose any version ever published by the Free Software
  343. XFoundation.
  344. X
  345. X  10. If you wish to incorporate parts of the Program into other free
  346. Xprograms whose distribution conditions are different, write to the author
  347. Xto ask for permission.  For software which is copyrighted by the Free
  348. XSoftware Foundation, write to the Free Software Foundation; we sometimes
  349. Xmake exceptions for this.  Our decision will be guided by the two goals
  350. Xof preserving the free status of all derivatives of our free software and
  351. Xof promoting the sharing and reuse of software generally.
  352. X
  353. X                NO WARRANTY
  354. X
  355. X  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  356. XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  357. XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  358. XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  359. XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  360. XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  361. XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  362. XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  363. XREPAIR OR CORRECTION.
  364. X
  365. X  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  366. XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  367. XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  368. XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  369. XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  370. XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  371. XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  372. XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  373. XPOSSIBILITY OF SUCH DAMAGES.
  374. X
  375. X             END OF TERMS AND CONDITIONS
  376. X
  377. X    Appendix: How to Apply These Terms to Your New Programs
  378. X
  379. X  If you develop a new program, and you want it to be of the greatest
  380. Xpossible use to the public, the best way to achieve this is to make it
  381. Xfree software which everyone can redistribute and change under these terms.
  382. X
  383. X  To do so, attach the following notices to the program.  It is safest
  384. Xto attach them to the start of each source file to most effectively
  385. Xconvey the exclusion of warranty; and each file should have at least
  386. Xthe "copyright" line and a pointer to where the full notice is found.
  387. X
  388. X    <one line to give the program's name and a brief idea of what it does.>
  389. X    Copyright (C) 19yy  <name of author>
  390. X
  391. X    This program is free software; you can redistribute it and/or modify
  392. X    it under the terms of the GNU General Public License as published by
  393. X    the Free Software Foundation; either version 2 of the License, or
  394. X    (at your option) any later version.
  395. X
  396. X    This program is distributed in the hope that it will be useful,
  397. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  398. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  399. X    GNU General Public License for more details.
  400. X
  401. X    You should have received a copy of the GNU General Public License
  402. X    along with this program; if not, write to the Free Software
  403. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  404. X
  405. XAlso add information on how to contact you by electronic and paper mail.
  406. X
  407. XIf the program is interactive, make it output a short notice like this
  408. Xwhen it starts in an interactive mode:
  409. X
  410. X    Gnomovision version 69, Copyright (C) 19yy name of author
  411. X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  412. X    This is free software, and you are welcome to redistribute it
  413. X    under certain conditions; type `show c' for details.
  414. X
  415. XThe hypothetical commands `show w' and `show c' should show the appropriate
  416. Xparts of the General Public License.  Of course, the commands you use may
  417. Xbe called something other than `show w' and `show c'; they could even be
  418. Xmouse-clicks or menu items--whatever suits your program.
  419. X
  420. XYou should also get your employer (if you work as a programmer) or your
  421. Xschool, if any, to sign a "copyright disclaimer" for the program, if
  422. Xnecessary.  Here is a sample; alter the names:
  423. X
  424. X  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  425. X  `Gnomovision' (which makes passes at compilers) written by James Hacker.
  426. X
  427. X  <signature of Ty Coon>, 1 April 1989
  428. X  Ty Coon, President of Vice
  429. X
  430. XThis General Public License does not permit incorporating your program into
  431. Xproprietary programs.  If your program is a subroutine library, you may
  432. Xconsider it more useful to permit linking proprietary applications with the
  433. Xlibrary.  If this is what you want to do, use the GNU Library General
  434. XPublic License instead of this License.
  435. END_OF_FILE
  436. if test 17982 -ne `wc -c <'perf/LICENSE'`; then
  437.     echo shar: \"'perf/LICENSE'\" unpacked with wrong size!
  438. fi
  439. # end of 'perf/LICENSE'
  440. fi
  441. if test -f 'perf/Makefile.simple' -a "${1}" != "-c" ; then 
  442.   echo shar: Will not clobber existing file \"'perf/Makefile.simple'\"
  443. else
  444. echo shar: Extracting \"'perf/Makefile.simple'\" \(204 characters\)
  445. sed "s/^X//" >'perf/Makefile.simple' <<'END_OF_FILE'
  446. XCC = cc
  447. XXHOME = /local/X11R5
  448. XCFLAGS = -O -I$(XHOME)/include
  449. X
  450. XPO = perf.o
  451. XLDFLAGS = -L$(XHOME)/lib -lxview -lolgx -lX11 -lrpcsvc #-lBSD
  452. X
  453. Xperf:$(PO)
  454. X    $(CC) -o $@ $(PO) $(LDFLAGS)
  455. X
  456. Xclean:
  457. X    -rm -f $(PO) perf
  458. END_OF_FILE
  459. if test 204 -ne `wc -c <'perf/Makefile.simple'`; then
  460.     echo shar: \"'perf/Makefile.simple'\" unpacked with wrong size!
  461. fi
  462. # end of 'perf/Makefile.simple'
  463. fi
  464. if test -f 'perf/README' -a "${1}" != "-c" ; then 
  465.   echo shar: Will not clobber existing file \"'perf/README'\"
  466. else
  467. echo shar: Extracting \"'perf/README'\" \(175 characters\)
  468. sed "s/^X//" >'perf/README' <<'END_OF_FILE'
  469. X1) You should have XView 3.0 or later 
  470. X2) how to build perf:
  471. X       xmkmf
  472. X       make
  473. X3) start it with
  474. X       perf
  475. X   or
  476. X    perf -\?
  477. X
  478. X
  479. XBug reports to rfkoenig@informatik.uni-erlangen.de
  480. END_OF_FILE
  481. if test 175 -ne `wc -c <'perf/README'`; then
  482.     echo shar: \"'perf/README'\" unpacked with wrong size!
  483. fi
  484. # end of 'perf/README'
  485. fi
  486. if test -f 'perf/README.linux' -a "${1}" != "-c" ; then 
  487.   echo shar: Will not clobber existing file \"'perf/README.linux'\"
  488. else
  489. echo shar: Extracting \"'perf/README.linux'\" \(326 characters\)
  490. sed "s/^X//" >'perf/README.linux' <<'END_OF_FILE'
  491. XHow to get perf running
  492. X1) You should have linux-pl12+ and the XView 3.2 port for Linux
  493. X2) install rstatd & librpcsvc.a
  494. X3) build & start perf
  495. X   export IMAKEINCLUDE="-I/usr/openwin/lib/config"
  496. X   (setenv IMAKEINCLUDE "-I/usr/openwin/lib/config")
  497. X   xmkmf
  498. X   make
  499. X   perf &
  500. X
  501. X
  502. XBug reports to rfkoenig@informatik.uni-erlangen.de
  503. END_OF_FILE
  504. if test 326 -ne `wc -c <'perf/README.linux'`; then
  505.     echo shar: \"'perf/README.linux'\" unpacked with wrong size!
  506. fi
  507. # end of 'perf/README.linux'
  508. fi
  509. if test -f 'perf/icon.xbm' -a "${1}" != "-c" ; then 
  510.   echo shar: Will not clobber existing file \"'perf/icon.xbm'\"
  511. else
  512. echo shar: Extracting \"'perf/icon.xbm'\" \(2704 characters\)
  513. sed "s/^X//" >'perf/icon.xbm' <<'END_OF_FILE'
  514. X#define icon_width 64
  515. X#define icon_height 64
  516. Xstatic char icon_bits[] = {
  517. X 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  518. X 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  519. X 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  520. X 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  521. X 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  522. X 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x07,0x00,
  523. X 0x00,0xf0,0xff,0xff,0xff,0xff,0x07,0x00,0x00,0x80,0xff,0xff,0xff,0xff,0x1f,
  524. X 0x00,0x00,0x00,0xfe,0xff,0xff,0xff,0x7f,0x00,0xff,0x03,0xfc,0xff,0xff,0xff,
  525. X 0x7f,0xc0,0xff,0x0f,0xf8,0xff,0xff,0xff,0xff,0xc0,0xff,0x3f,0xf0,0xff,0xff,
  526. X 0xff,0xff,0xc0,0xff,0x3f,0xe0,0xff,0xff,0xff,0xff,0xc0,0xff,0x7f,0xe0,0xff,
  527. X 0xff,0xff,0xff,0xc0,0xff,0xff,0xc0,0xff,0xff,0xff,0xff,0xc0,0xff,0xff,0xc0,
  528. X 0xff,0xff,0xff,0xff,0xc0,0xff,0xff,0xc0,0xff,0xff,0xff,0xff,0xc0,0xff,0xff,
  529. X 0xc0,0xff,0xff,0xff,0xff,0xc0,0xff,0xff,0xc0,0xff,0xff,0xff,0xff,0xc0,0xff,
  530. X 0xff,0xc0,0xff,0xff,0xff,0xff,0xc0,0xff,0xff,0xc0,0xff,0xff,0xff,0xff,0xc0,
  531. X 0xff,0x7f,0xe0,0xff,0xff,0xff,0xff,0xc0,0xff,0x7f,0xe0,0xff,0xff,0xff,0xff,
  532. X 0xc0,0xff,0x3f,0xe0,0xff,0xff,0xff,0xff,0xc0,0xff,0x1f,0xf0,0xff,0xff,0xff,
  533. X 0xff,0xc0,0xff,0x0f,0xf8,0xff,0xff,0xff,0xff,0xc0,0xff,0x03,0xfc,0xff,0xff,
  534. X 0xff,0xff,0x00,0x00,0x00,0xfe,0xff,0x3f,0xf8,0xff,0x00,0x00,0x80,0xff,0xff,
  535. X 0x9f,0xf1,0xff,0x00,0x00,0xf0,0xff,0xff,0xcf,0xf3,0xff,0xc0,0xff,0xff,0xff,
  536. X 0xff,0xc7,0xff,0xff,0xc0,0xff,0xff,0xff,0xff,0xc7,0xff,0xff,0xc0,0xff,0xff,
  537. X 0xff,0xff,0xc7,0xff,0xff,0xc0,0xff,0x81,0x7f,0x1c,0x01,0xfe,0xff,0xc0,0x7f,
  538. X 0x1c,0x0f,0x04,0xc6,0xff,0xff,0xc0,0x3f,0x3e,0x3e,0x38,0xc6,0xff,0xff,0xc0,
  539. X 0x3f,0x7f,0x7c,0xfc,0xc7,0xff,0xff,0xc0,0x1f,0x7f,0x7c,0xfc,0xc7,0xff,0xff,
  540. X 0xc0,0x1f,0x00,0x7c,0xfc,0xc7,0xff,0xff,0xc0,0x1f,0xff,0x7f,0xfc,0xc7,0xff,
  541. X 0xff,0xc0,0x1f,0xff,0x7f,0xfc,0xc7,0xff,0xff,0xc0,0x1f,0xff,0x7f,0xfc,0xc7,
  542. X 0xff,0xff,0xc0,0x1f,0xff,0x7f,0xfc,0xc7,0xff,0x7f,0x80,0x3f,0xfe,0x7d,0xfc,
  543. X 0xc7,0xff,0x3f,0x00,0x3f,0xfe,0x7e,0xfc,0xc7,0xff,0x07,0x00,0x70,0x7c,0x3f,
  544. X 0xfc,0xc7,0xff,0x07,0x00,0xf0,0x81,0x0f,0xf0,0x01,0xff,0xff,0xff,0xff,0xff,
  545. X 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  546. X 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  547. X 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  548. X 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  549. X 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  550. X 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  551. X 0xff,0xff};
  552. END_OF_FILE
  553. if test 2704 -ne `wc -c <'perf/icon.xbm'`; then
  554.     echo shar: \"'perf/icon.xbm'\" unpacked with wrong size!
  555. fi
  556. # end of 'perf/icon.xbm'
  557. fi
  558. if test -f 'perf/perf.1' -a "${1}" != "-c" ; then 
  559.   echo shar: Will not clobber existing file \"'perf/perf.1'\"
  560. else
  561. echo shar: Extracting \"'perf/perf.1'\" \(4909 characters\)
  562. sed "s/^X//" >'perf/perf.1' <<'END_OF_FILE'
  563. X.TH PERF 1 "15 September 1993"
  564. X.SH NAME
  565. Xperf \- report kernel statistics visually
  566. X.SH SYNOPSIS
  567. X.B perf
  568. X[-a] [-sampletime sec]
  569. X.if n .ti +0.5i
  570. X[-drawline] [-nosmooth] [-drawone] [-noadd]
  571. X.if n .ti +0.5i
  572. X[-noreset] [-scrollback sampled-values] [-columns cols]
  573. X.if n .ti +0.5i
  574. X[-col1 color] [-col2 color] [-col3 color]
  575. X.if n .ti +0.5i
  576. X[-col4 color] [-foreground color] [-background color]
  577. X.if n .ti +0.5i
  578. X[-cpu] [-disk] [-page] [-swap] [-interrupts] 
  579. X.if n .ti +0.5i
  580. X[-packets] [-errors] [-collisions] [-context] [-load] 
  581. X.if n .ti +0.5i
  582. X[host]
  583. X
  584. X.SH DESCRIPTION
  585. X.B perf
  586. Xis an XView program that reports kernel statistics for a given
  587. X.B host
  588. X(or for the localhost if no host is specified). The program is
  589. Xa frontend to the rstatd(8) daemon.
  590. X.PP
  591. XThe displayed window consists of one or more fields, each showing a specified
  592. Xparameter. The name of the parameter and of its components are shown in the
  593. Xlower left corner of the field, the maximum value of the visible data in the
  594. Xlower right corner.
  595. X
  596. X.SH OPTIONS
  597. X.TP
  598. X.B -sampletime sec
  599. XQuery the rstatd each 
  600. X.B sec
  601. Xseconds for new data. Default is 2.
  602. X.TP
  603. X.B -drawline
  604. XDraw only a line instead of a filled block.
  605. X.TP
  606. X.B -nosmooth
  607. XIf the drawing is filled, do not smooth the data.
  608. X.TP
  609. X.B -drawone
  610. XShow only the sum of multiple subvalues like e.g. usr, nice & sys.
  611. XThis is the default on monochrome diplays.
  612. X.TP
  613. X.B -noadd
  614. XDo not draw the subvalues on top of each other. This means, that
  615. Xsome subvalues may be completely hidden, if following ones are
  616. Xgreater. Use the drawline option in such cases.
  617. X.TP
  618. X.B -noreset
  619. XDo not readjust the maximum value shown in the lower right corner.
  620. X.TP
  621. X.B -scrollback sampled-values
  622. XSet the scrollback buffer to
  623. X.B sampled-values.
  624. XDefault is 200, i.e. 20 minutes if sampletime is 2.
  625. XThe total number of samples stored is field_width_in_pixels + scrollback.
  626. X.TP
  627. X.B -columns cols
  628. XDisplay the fields in
  629. X.B cols
  630. Xcolumns. Default is 1.
  631. X.TP
  632. X.B -col[1-4] color -forground color -background color
  633. XThe first subvalue is drawn with the color col1, the second with col2 and so on.
  634. X.B color
  635. Xmust be of the form 
  636. X.B #rrggbb,
  637. Xwhere 
  638. X.B rr
  639. Xis the red component,
  640. X.B gg
  641. Xthe green and
  642. X.B bb
  643. Xthe blue one
  644. X(e.g #ff0000 is red).
  645. XDefaults:
  646. X.if n .ti +0.5i
  647. Xcol1: #000000 (black)
  648. X.if n .ti +0.5i
  649. Xcol2: #a0a0a0
  650. X.if n .ti +0.5i
  651. Xcol3: #c0c0c0
  652. X.if n .ti +0.5i
  653. Xcol3: #e0e0e0
  654. X.if n .ti +0.5i
  655. Xcol4: #ffffff (white)
  656. X.if n .ti +0.5i
  657. Xforeground is black and background is white.
  658. X.PP
  659. X.if n .ti -1i
  660. XThe following options specify, which statistic values are displayed:
  661. X.TP
  662. X.B -cpu
  663. XPercent of cpu being used.
  664. X.TP
  665. X.B -disk
  666. XDisk transfers per second.
  667. X.TP
  668. X.B -page
  669. XPages paged per second.
  670. X.TP
  671. X.B -swap
  672. XPages swapped per second.
  673. X.TP
  674. X.B -interrupts
  675. XNumber of device interrupts in a second.
  676. X.TP
  677. X.B -packets
  678. XNetwork packets per second.
  679. X.TP
  680. X.B -errors
  681. XErrors per second on receiving packets.
  682. X.TP
  683. X.B -collisions
  684. XCollisions per second detected on the network.
  685. X.TP
  686. X.B -context
  687. XNumber of context switches per second.
  688. X.TP
  689. X.B -load
  690. XLoad average.
  691. X.TP
  692. X.B -a
  693. XAll of the above 10 options.
  694. X
  695. X.SH KEYBOARD ACCELERATORS
  696. X.TP
  697. X.B a
  698. XToggle the noadd option.
  699. X.TP
  700. X.B q
  701. XQuit the program.
  702. X.TP
  703. X.B s
  704. XToggle solid drawing.
  705. X.TP
  706. X.B o
  707. XToggle smooth option.
  708. X.TP
  709. X.B 1
  710. XToggle the drawone option.
  711. X.TP
  712. X.B ?
  713. XBring up the properties window.
  714. X.TP
  715. X.B NL (NewLine)
  716. XRestore all scrollback windows to the current values.
  717. X.SH Mouse (Pointer device) Usage
  718. X.TP
  719. X.B Right Mouse Button
  720. XYou can bring up the
  721. X.B properties window
  722. Xby clicking the right mouse button.
  723. XDon't forget to select the 'Apply' button after changing values.
  724. X.if n .ti +0.0i
  725. XIf you click the right mouse button over one of the displayed fields
  726. Xwhile pressing the
  727. X.B SHIFT
  728. Xkey, you can change values valid only for this field. You can reset
  729. Xthis settings by selecting the 'No special flags' button.
  730. X.TP
  731. X.B Left Mouse Button
  732. XIf you click in a field with the left mouse button, the exact value of the 
  733. Xsample will be displayed in the properties window.
  734. XIf you drag the field, you can examine the sampled values in the
  735. Xscrollback history.
  736. X.TP
  737. X.B Middle Mouse Button
  738. XYou can scroll more than one field at once by selecting all of them first with
  739. Xthe middle mouse button.
  740. X.SH X RESOURCES
  741. X.TP
  742. XFollowing X Resources are examined during startup:
  743. X.if n .ti +0.5i
  744. Xperf.sampletime
  745. X.if n .ti +0.5i
  746. Xperf.drawline
  747. X.if n .ti +0.5i
  748. Xperf.nosmooth
  749. X.if n .ti +0.5i
  750. Xperf.drawone
  751. X.if n .ti +0.5i
  752. Xperf.noreset
  753. X.if n .ti +0.5i
  754. Xperf.scrollback
  755. X.if n .ti +0.5i
  756. Xperf.columns
  757. X.if n .ti +0.5i
  758. Xperf.col1
  759. X.if n .ti +0.5i
  760. Xperf.col2
  761. X.if n .ti +0.5i
  762. Xperf.col3
  763. X.if n .ti +0.5i
  764. Xperf.col4
  765. X.if n .ti +0.5i
  766. Xperf.foreground
  767. X.if n .ti +0.5i
  768. Xperf.background
  769. X.TP
  770. XNote: Options take precedence over X Resources.
  771. X.SH FEATURES/BUGS
  772. X.PP
  773. XThe maximum scrollback is limited to 20000 values. This is because by 
  774. Xinitiating a scrollback the whole history will be drawn on a single
  775. Xpixmap and this can be a memory hog. Besides X limits the size
  776. Xof a pixmap to 2^15 pixels (if I'm right).
  777. X.SH ATHOR
  778. X.PP
  779. XRudolf Koenig, 1993
  780. END_OF_FILE
  781. if test 4909 -ne `wc -c <'perf/perf.1'`; then
  782.     echo shar: \"'perf/perf.1'\" unpacked with wrong size!
  783. fi
  784. # end of 'perf/perf.1'
  785. fi
  786. if test -f 'perf/perf.c' -a "${1}" != "-c" ; then 
  787.   echo shar: Will not clobber existing file \"'perf/perf.c'\"
  788. else
  789. echo shar: Extracting \"'perf/perf.c'\" \(41015 characters\)
  790. sed "s/^X//" >'perf/perf.c' <<'END_OF_FILE'
  791. X/*
  792. X * Copyright (C) 1993 Rudolf Koenig 
  793. X *
  794. X * This program is free software; you can redistribute it and/or modify
  795. X * it under the terms of the GNU General Public License as published by
  796. X * the Free Software Foundation; either version 2, or (at your option)
  797. X * any later version.
  798. X *
  799. X * This program is distributed in the hope that it will be useful,
  800. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  801. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  802. X * GNU General Public License for more details.
  803. X *
  804. X * You should have received a copy of the GNU General Public License
  805. X * along with this program (see the file COPYING); if not, write to the
  806. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  807. X */
  808. X
  809. X#include <xview/xview.h>
  810. X#include <xview/font.h>
  811. X#include <xview/canvas.h>
  812. X#include <xview/panel.h>
  813. X#include <xview/notify.h>
  814. X#include <xview/defaults.h>
  815. X#include <xview/icon.h>
  816. X#include "icon.xbm"
  817. X#include <rpc/rpc.h>
  818. X#include <rpcsvc/rstat.h>
  819. X#include <stdio.h>
  820. X
  821. Xextern int fork();
  822. X
  823. X#define PROGNAME "perf"
  824. X
  825. X#define CPU  1
  826. X#define PKTS 2
  827. X#define PAGE 3
  828. X#define SWAP 4
  829. X#define INTR 5
  830. X#define DISK 6
  831. X#define CTXT 7
  832. X#define LOAD 8
  833. X#define COLL 9
  834. X#define ERRS 10
  835. X
  836. X#define NUMCOLS 6
  837. X#define WHITE 4
  838. X#define BLACK 5
  839. X
  840. X
  841. Xstruct pm
  842. X{
  843. X  int offset;
  844. X  int starttime;
  845. X  int startvalidx;
  846. X  int posx, posy, width;
  847. X  GC colorgc[NUMCOLS];
  848. X  Pixmap pm;
  849. X} pm;
  850. X
  851. Xstruct values
  852. X{
  853. X  int type; 
  854. X  char *name;
  855. X  char *subname[4];
  856. X  int numvalues;
  857. X  int **values, *last;
  858. X  int maxval, maxval_to_show;
  859. X  int active;
  860. X  unsigned int
  861. X      special:1,
  862. X      draw_line:1,
  863. X      add_values:1,
  864. X      no_smooth:1,
  865. X      draw_one:1,
  866. X      no_reset:1,
  867. X      selected:1;
  868. X  int scrollback;
  869. X  int sec_perpixel,
  870. X      lastsec;        /* Amount to wait till next shift */
  871. X  int xpos, ypos;
  872. X  int validx;
  873. X  struct pm *pm;
  874. X} values[] =
  875. X{
  876. X  { CPU, "cpu", {"usr","nice","sys",0},3,0,0,100,-1,  }, 
  877. X  { DISK,"disk",{"1",  "2",   "3","4"},4,0,0,  1,-1,  }, 
  878. X  { PAGE,"page",{"in", "out",  0,   0},2,0,0,  1,-1,  }, 
  879. X  { SWAP,"swap",{"in", "out",  0,   0},2,0,0,  1,-1,  }, 
  880. X  { INTR,"interrupts",{0,0,    0,   0},1,0,0,  1,-1,  }, 
  881. X  { PKTS,"packets",{"in","out",0,   0},2,0,0,  1,-1,  }, 
  882. X  { ERRS,"errors", {"in","out",0,   0},2,0,0,  1,-1,  }, 
  883. X  { COLL,"collisions",{0,0,    0,   0},1,0,0,  1,-1,  }, 
  884. X  { CTXT,"context",{0,  0,     0,   0},1,0,0,  1,-1,  }, 
  885. X  { LOAD,"load",{0,     0,     0,   0},1,0,0,256, 1,  }, 
  886. X  { 0,   0,     {0,     0,     0,   0},0,0,0,  0, 0,  }
  887. X}, *active = 0;
  888. X
  889. X
  890. X
  891. XFrame fr, pfr;
  892. XCanvas ca;
  893. XPanel pn;
  894. XPanel_item pi_sels, pi_mach, pi_check, pi_spp,  pi_cols, pi_msg,
  895. X           pi_apply, pi_hide, pi_fork, pi_nosp, pi_scbk;
  896. XDisplay *dpy;
  897. XWindow win;
  898. Xint screen;
  899. XXv_Font font;
  900. XXFontStruct *font_info;
  901. XGC bwingc, wingc;
  902. Xint win_x, real_win_y, win_y = 0, 
  903. X    fontheight, depth, nrcurr_active,
  904. X    width1, width2, height1, lost_connection = 0;
  905. Xchar **argv;
  906. X
  907. X/* Options */
  908. Xint sec_perpixel = 2, lastsec = 0, scrollback = 600, columns = 1, 
  909. X    add_values, noadd = 0,
  910. X    no_reset = 0, draw_line = 0, no_smooth = 0, draw_one = 0;
  911. Xchar *host = 0;
  912. Xint defcol[NUMCOLS] =
  913. X  { 0x000000, 0xa0a0a0, 0xc0c0c0, 0xe0e0e0, 0xffffff, 0x000000 };
  914. Xint defidx[NUMCOLS];
  915. X
  916. Xstruct opts
  917. X{
  918. X  char *name;
  919. X  int *param;
  920. X  int needsarg;
  921. X} opts[] = 
  922. X{
  923. X  { "drawline",   &draw_line,     0 },
  924. X  { "nosmooth",   &no_smooth,     0 },
  925. X  { "drawone",    &draw_one,      0 },
  926. X  { "noadd",      &noadd,         0 },
  927. X  { "sampletime", &sec_perpixel,  1 },
  928. X  { "noreset",    &no_reset,      0 },
  929. X  { "scrollback", &scrollback,    1 },
  930. X  { "columns",    &columns,       1 },
  931. X  { "col1",       &defcol[0],     1 },
  932. X  { "col2",       &defcol[1],     1 },
  933. X  { "col3",       &defcol[2],     1 },
  934. X  { "col4",       &defcol[3],     1 },
  935. X  { "foreground", &defcol[BLACK], 1 },
  936. X  { "background", &defcol[WHITE], 1 },
  937. X  { 0, 0, 0 },
  938. X};
  939. X
  940. X#define FSET(v, flag) (v->special ? v->flag : flag) 
  941. X#define VALUES_LENGTH(v) (FSET(v, scrollback)+width2)
  942. X
  943. Xstruct statstime sx;
  944. Xint just_started = 1, diffdisk, min_spp;
  945. XNotify_value update();
  946. X
  947. Xdo_alarm(t)
  948. X  int t;
  949. X{
  950. X  struct itimerval timer;
  951. X
  952. X  timer.it_value.tv_sec = timer.it_interval.tv_sec = t;
  953. X  timer.it_value.tv_usec = timer.it_interval.tv_usec = 0;
  954. X  notify_enable_rpc_svc(1);
  955. X  notify_set_itimer_func(fr, update, ITIMER_REAL, &timer, NULL);
  956. X}
  957. X
  958. X/* indx is needed by repaint, scrollback... */
  959. Xstatic void
  960. XDrawPixels(val, p, indx, col)
  961. X  struct values *val;
  962. X  struct pm *p;
  963. X  int indx, col;
  964. X{
  965. X  int x, y, i, oldv, newv, old, new,
  966. X      **vals = val->values,
  967. X      vl = VALUES_LENGTH(val);
  968. X
  969. X  old = new = 0;
  970. X  x = val->xpos * width1 + col; 
  971. X  y = val->ypos * height1 + height1 - fontheight;
  972. X
  973. X  if(FSET(val, add_values))
  974. X    {
  975. X      for(i = 0; i < val->numvalues; i++)
  976. X    {
  977. X      new += vals[i][indx];
  978. X      old += vals[i][(indx-1+vl) % vl];
  979. X    }
  980. X      if(new > val->maxval) new = val->maxval;
  981. X      if(old > val->maxval) old = val->maxval;
  982. X    }
  983. X
  984. X  for(i = 0; i < val->numvalues; i++)
  985. X    {
  986. X      if(!FSET(val, add_values))
  987. X        {
  988. X      new = vals[i][indx];
  989. X      old = vals[i][(indx-1+vl) % vl];
  990. X        }
  991. X      newv = (double)((height1-fontheight) * new) / (double)val->maxval;
  992. X      oldv = (double)((height1-fontheight) * old) / (double)val->maxval;
  993. X
  994. X      if(FSET(val, draw_line))
  995. X        {
  996. X      XDrawLine(dpy, p->pm, p->colorgc[i], x-1, y - oldv, x, y - newv);
  997. X        }
  998. X      else
  999. X        {
  1000. X      XDrawLine(dpy, p->pm, p->colorgc[i], x, y, x, y - newv);
  1001. X
  1002. X      if(!FSET(val, no_smooth))
  1003. X        {
  1004. X          if(newv > oldv)
  1005. X        XDrawLine(dpy, p->pm, p->colorgc[i], 
  1006. X            x - 1, y - oldv, x - 1, y - oldv - (newv - oldv ) / 2);
  1007. X          else
  1008. X        XDrawLine(dpy, p->pm, p->colorgc[i],
  1009. X            x, y - newv, x, y - newv - (oldv - newv ) / 2);
  1010. X        }
  1011. X    }
  1012. X
  1013. X      if(FSET(val, draw_one))
  1014. X        break;
  1015. X      if(FSET(val, add_values))
  1016. X        {
  1017. X      new -= vals[i][indx];
  1018. X      old -= vals[i][(indx-1+vl) % vl];
  1019. X        }
  1020. X    }
  1021. X}
  1022. X
  1023. Xstatic int 
  1024. Xnextmax(v)
  1025. X  int v;
  1026. X{
  1027. X  int m;
  1028. X
  1029. X  for(m = 10; ; m *= 10)
  1030. X    if(v < m)
  1031. X      break;
  1032. X  m /= 10;
  1033. X  if(v > m * 5)
  1034. X    return m * 10;
  1035. X  if(v > m * 2)
  1036. X    return m *  5;
  1037. X  else if(v > m)
  1038. X    return m * 2;
  1039. X  else
  1040. X    return m;
  1041. X}
  1042. X
  1043. X/* from can be larger then to*/
  1044. Xstatic int
  1045. Xrescale(val, from, to)
  1046. X  struct values *val;
  1047. X  int from, to;
  1048. X{
  1049. X  int j, k, sum, max, tlen;
  1050. X  int changed = 0;
  1051. X
  1052. X  if(val->type == CPU)
  1053. X    return 0;
  1054. X  tlen = VALUES_LENGTH(val);
  1055. X  max = (val->type == LOAD) ? 256 : 1;
  1056. X
  1057. X  for(j = from; ; j = (j+1) % tlen)
  1058. X    {
  1059. X      for(sum = 0, k = val->numvalues - 1; k >= 0; k--)
  1060. X    sum += val->values[k][j];
  1061. X      if(sum > max)
  1062. X    if(val->type == LOAD)
  1063. X      while(sum > max) max *= 2;
  1064. X    else
  1065. X      max = sum;
  1066. X      if(j == to)
  1067. X        break;
  1068. X    }
  1069. X  if(val->type == LOAD)
  1070. X    {
  1071. X      val->maxval_to_show = max / 256;
  1072. X      changed = (val->maxval > max);
  1073. X      val->maxval = max;
  1074. X    }
  1075. X  else
  1076. X    {
  1077. X      changed = (val->maxval > nextmax(max));
  1078. X      val->maxval = nextmax(max);
  1079. X    }
  1080. X  return changed;
  1081. X}
  1082. X
  1083. Xstatic void
  1084. Xfill_last(sxp)
  1085. X  struct statstime *sxp;
  1086. X{
  1087. X  int i, j, sum;
  1088. X  struct values *v;
  1089. X
  1090. X  for(i = 0; values[i].numvalues; i++)
  1091. X    {
  1092. X      v = &values[i];
  1093. X      if(v->special && v->lastsec)
  1094. X         continue;
  1095. X      switch(v->type)
  1096. X        {
  1097. X          case CPU:
  1098. X        for(j = 0; j < 4; j++)
  1099. X          v->last[j] = sxp->cp_time[j];
  1100. X        break;
  1101. X          case DISK:
  1102. X        for(sum = j = 0; j < 4; j++)
  1103. X          v->last[j] = sxp->dk_xfer[j];
  1104. X        break;
  1105. X          case PAGE:
  1106. X        v->last[0] = sxp->v_pgpgin;
  1107. X        v->last[1] = sxp->v_pgpgout;
  1108. X        break;
  1109. X          case SWAP:
  1110. X        v->last[0] = sxp->v_pswpin;
  1111. X        v->last[1] = sxp->v_pswpout;
  1112. X        break;
  1113. X          case INTR:
  1114. X        v->last[0] = sxp->v_intr;
  1115. X        break;
  1116. X          case PKTS:
  1117. X        v->last[0] = sxp->if_ipackets;
  1118. X        v->last[1] = sxp->if_opackets;
  1119. X        break;
  1120. X          case ERRS:
  1121. X        v->last[0] = sxp->if_ierrors;
  1122. X        v->last[1] = sxp->if_oerrors;
  1123. X        break;
  1124. X          case COLL:
  1125. X        v->last[0] = sxp->if_collisions;
  1126. X        break;
  1127. X          case CTXT:
  1128. X        v->last[0] = sxp->v_swtch;
  1129. X        break;
  1130. X          case LOAD:
  1131. X        break;
  1132. X    }
  1133. X    }
  1134. X}
  1135. X
  1136. Xstatic void
  1137. Xinc()
  1138. X{
  1139. X  int i;
  1140. X  struct values *v;
  1141. X
  1142. X  for(i = 0; values[i].numvalues; i++)
  1143. X    {
  1144. X      v = &values[i];
  1145. X      if(!FSET(v, lastsec))
  1146. X    v->validx = (v->validx+1) % VALUES_LENGTH(v);
  1147. X      if(v->special)
  1148. X    v->lastsec = (v->lastsec+min_spp) % v->sec_perpixel;
  1149. X    }
  1150. X  lastsec = (lastsec+min_spp) % sec_perpixel;
  1151. X}
  1152. X
  1153. XNotify_value
  1154. Xupdate()
  1155. X{
  1156. X  int i, j, redraw, from, to,
  1157. X      sum, sum1, x, y;
  1158. X  double d;
  1159. X  struct values *v;
  1160. X  static void dopaint();
  1161. X
  1162. X  redraw = 0;
  1163. X
  1164. X  if(!values[0].last) /* Called before initialization */
  1165. X    return;
  1166. X  if(rstat(host, &sx))
  1167. X    {
  1168. X      static char noconn[]="Lost connection";
  1169. X      int dir, ascent, descent;
  1170. X      XCharStruct or;
  1171. X
  1172. X      /* Draw 'Lost Connection' in every field */
  1173. X      if(lost_connection)
  1174. X    return NOTIFY_DONE;
  1175. X      XTextExtents(font_info, noconn, strlen(noconn),&dir,&ascent,&descent,&or);
  1176. X
  1177. X      for(i = 0; values[i].numvalues; i++)
  1178. X        if(values[i].active)
  1179. X      {
  1180. X        XDrawImageString(dpy, pm.pm, pm.colorgc[WHITE],
  1181. X              values[i].xpos * width2 + (width2 - or.width)/2,
  1182. X          values[i].ypos * height1 + (height1 - fontheight + ascent)/2,
  1183. X          noconn, strlen(noconn));
  1184. X      }
  1185. X      lost_connection = 1;
  1186. X      XCopyArea(dpy, pm.pm, win, wingc, 0, 0, win_x, real_win_y, 0, 0);
  1187. X      XFlush(dpy);
  1188. X      return NOTIFY_DONE;
  1189. X    }
  1190. X
  1191. X  if(lost_connection || just_started) /* Connection alive again */
  1192. X    {
  1193. X      if(just_started)
  1194. X    {
  1195. X      do_alarm(min_spp);
  1196. X      if(sx.dk_xfer[0] + sx.dk_xfer[1] +
  1197. X         sx.dk_xfer[2] + sx.dk_xfer[3] > 200)
  1198. X        diffdisk = 0;
  1199. X      else
  1200. X        diffdisk = 1;
  1201. X    }
  1202. X      just_started = lost_connection = 0;
  1203. X      fill_last(&sx);
  1204. X      sleep(1);
  1205. X      rstat(host, &sx);
  1206. X      redraw = 1;
  1207. X    }
  1208. X/* Check for working rstatd */
  1209. X  if(!sx.cp_time[3]) /* No idle tick since boot ??? */
  1210. X    {
  1211. X      printf("Buggy rstatd around? (Or perhaps no kernel support?)\n");
  1212. X      exit(-1);
  1213. X    }
  1214. X
  1215. X/* Let's scroll back */
  1216. X  for(i = 0; values[i].numvalues; i++)
  1217. X    {
  1218. X      v = &values[i];
  1219. X      if(v->active && !FSET(v, lastsec))
  1220. X    {
  1221. X      x = v->xpos * width1;
  1222. X      y = v->ypos * height1;
  1223. X
  1224. X      XCopyArea(dpy, pm.pm, pm.pm, pm.colorgc[BLACK],
  1225. X                   x+1, y, width2-1, height1-fontheight+2, x, y);
  1226. X      XDrawLine(dpy, pm.pm, pm.colorgc[WHITE],
  1227. X                   x+width2-1, y, x+width2-1, y+height1);
  1228. X    }
  1229. X    }
  1230. X
  1231. X
  1232. X/* Let's update */
  1233. X  for(i = 0; values[i].numvalues; i++)
  1234. X    {
  1235. X      v = &values[i];
  1236. X      if(FSET(v, lastsec))
  1237. X        continue;
  1238. X/*
  1239. Xprintf("%s,", v->name); fflush(stdout);
  1240. X*/
  1241. X      switch(v->type)
  1242. X    {
  1243. X      case CPU:
  1244. X        for(j = sum = 0; j < 4; j++)
  1245. X          sum += sx.cp_time[j] - v->last[j];
  1246. X        if(!sum) /* Huhh?? But it happens!! */
  1247. X          {
  1248. X        fill_last(&sx);
  1249. X        return;
  1250. X          }
  1251. X        for(j = 0; j < 3; j++)
  1252. X          {
  1253. X        d = 100.0 * (sx.cp_time[j] - v->last[j])/(double)sum;
  1254. X        v->values[j][v->validx] = (int)(d+0.5);
  1255. X          }
  1256. X        break;
  1257. X      case PKTS:
  1258. X        sum  = sx.if_ipackets - v->last[0];
  1259. X        sum1 = sx.if_opackets - v->last[1];
  1260. X        v->values[0][v->validx] = sum;
  1261. X        v->values[1][v->validx] = sum1;
  1262. X#define CHECKMAX(a) if(a > v->maxval) { if(v->active) redraw = 1; v->maxval = nextmax(a); }
  1263. X            CHECKMAX(sum+sum1);
  1264. X        break;
  1265. X      case PAGE:
  1266. X        sum  = sx.v_pgpgin  - v->last[0];
  1267. X        sum1 = sx.v_pgpgout - v->last[1];
  1268. X        v->values[0][v->validx] = sum;
  1269. X        v->values[1][v->validx] = sum1;
  1270. X            CHECKMAX(sum+sum1);
  1271. X        break;
  1272. X      case SWAP:
  1273. X        sum  = sx.v_pswpin  - v->last[0];
  1274. X        sum1 = sx.v_pswpout - v->last[1];
  1275. X        v->values[0][v->validx] = sum;
  1276. X        v->values[1][v->validx] = sum1;
  1277. X            CHECKMAX(sum+sum1);
  1278. X        break;
  1279. X      case INTR:
  1280. X        v->values[0][v->validx] = sx.v_intr - v->last[0];
  1281. X            CHECKMAX(v->values[0][v->validx]);
  1282. X        break;
  1283. X      case DISK:
  1284. X        for(sum = j = 0; j < 4; j++)
  1285. X          {
  1286. X        v->values[j][v->validx] = sx.dk_xfer[j];
  1287. X        if(!diffdisk)
  1288. X          {
  1289. X            v->values[j][v->validx] -= v->last[j];
  1290. X            if(v->values[j][v->validx] < 0) 
  1291. X              {
  1292. X        /* It IS diffdisk, we should delete/reinterpret the data */
  1293. X            v->values[j][v->validx] += v->last[j];
  1294. X            diffdisk = 1;
  1295. X              }
  1296. X          }
  1297. X        sum += v->values[j][v->validx];
  1298. X          }
  1299. X        CHECKMAX(sum);
  1300. X        break;
  1301. X      case CTXT:
  1302. X        v->values[0][v->validx] = sx.v_swtch - v->last[0];
  1303. X            CHECKMAX(v->values[0][v->validx]);
  1304. X        break;
  1305. X      case COLL:
  1306. X        v->values[0][v->validx] = sx.if_collisions - v->last[0];
  1307. X            CHECKMAX(v->values[0][v->validx]);
  1308. X        break;
  1309. X      case LOAD:
  1310. X        v->values[0][v->validx] = sx.avenrun[0];
  1311. X        while(v->values[0][v->validx] > v->maxval)
  1312. X          {
  1313. X        v->maxval *= 2;
  1314. X        v->maxval_to_show *= 2;
  1315. X        if(v->active) redraw = 1;
  1316. X          }
  1317. X        break;
  1318. X      case ERRS:
  1319. X        sum  = sx.if_ierrors - v->last[0];
  1320. X        sum1 = sx.if_oerrors - v->last[1];
  1321. X        v->values[0][v->validx] = sum;
  1322. X        v->values[1][v->validx] = sum1;
  1323. X            CHECKMAX(sum+sum1);
  1324. X        break;
  1325. X    }
  1326. X    }
  1327. X  fill_last(&sx);
  1328. X
  1329. X/* Let's rescale, if necessary */
  1330. X  for(i = j = 0; values[i].numvalues; i++)
  1331. X    {
  1332. X      v = &values[i];
  1333. X      if(FSET(v, lastsec))
  1334. X        continue;
  1335. X      from = (v->validx + 1 - width2 + VALUES_LENGTH(v)) % VALUES_LENGTH(v);
  1336. X      to   = v->validx;
  1337. X
  1338. X      if(!(FSET(v, no_reset) || v->pm || (v->validx % 20)))
  1339. X    redraw += rescale(v, from, to);
  1340. X    }
  1341. X
  1342. X  if(redraw)
  1343. X    {
  1344. X      inc();
  1345. X      dopaint(1);
  1346. X    }
  1347. X  else
  1348. X    {
  1349. X      for(i = 0; values[i].numvalues; i++)
  1350. X        {
  1351. X      v = &values[i];
  1352. X      if(v->active && !FSET(v, lastsec))
  1353. X        {
  1354. X          DrawPixels(v, &pm, v->validx, width2-1);
  1355. X          if(!v->pm)
  1356. X            {
  1357. X          x = v->xpos * width1; y = v->ypos * height1;
  1358. X          XCopyArea(dpy, pm.pm, win, wingc,
  1359. X                x, y, width2, height1-fontheight+2, x, y);
  1360. X        }
  1361. X        }
  1362. X    }
  1363. X      inc();
  1364. X      XFlush(dpy);
  1365. X    }
  1366. X
  1367. X  return NOTIFY_DONE;
  1368. X}
  1369. X
  1370. Xstatic void
  1371. XFreePM(p)
  1372. X  struct pm *p;
  1373. X{
  1374. X  int i;
  1375. X
  1376. X  if(p->pm)
  1377. X    XFreePixmap(dpy, p->pm);
  1378. X  for(i = 0; i < NUMCOLS; i++)
  1379. X    if(p->colorgc[i])
  1380. X      XFreeGC(dpy, p->colorgc[i]);
  1381. X}
  1382. X
  1383. Xstatic void
  1384. XCreatePM(p, x, y)
  1385. X  struct pm *p;
  1386. X  int x, y;
  1387. X{
  1388. X  XGCValues gcv;
  1389. X  int i;
  1390. X
  1391. X  FreePM(p);
  1392. X  p->pm = XCreatePixmap(dpy, win, x, y, depth);
  1393. X
  1394. X  gcv.font = xv_get(font, XV_XID);
  1395. X
  1396. X  for(i = 0; i < NUMCOLS; i++)
  1397. X    {
  1398. X      gcv.background =  i == WHITE ? defidx[BLACK] : defidx[WHITE];
  1399. X      gcv.foreground = defidx[i];
  1400. X      p->colorgc[i] = XCreateGC(dpy, p->pm,
  1401. X                                        GCFont|GCBackground|GCForeground,&gcv);
  1402. X    }
  1403. X  XFillRectangle(dpy, p->pm, p->colorgc[WHITE], 0, 0, x, y);
  1404. X}
  1405. X
  1406. Xstatic void
  1407. Xrealloc_values(v, oldlen, newlen)
  1408. X  struct values *v;
  1409. X  int oldlen, newlen;
  1410. X{
  1411. X  int j, l, k,
  1412. X      *np, *op;
  1413. X
  1414. X  if(oldlen == newlen)
  1415. X    return;
  1416. X
  1417. X  if(!v->values) /* Let's initialize */
  1418. X    {
  1419. X      v->values = (int **)malloc(sizeof(int *) * v->numvalues);
  1420. X      for(l = 0; l < v->numvalues; l++)
  1421. X    v->values[l] = (int *)calloc(sizeof(int), newlen);
  1422. X      v->last = (int *)malloc(sizeof(int) * (v->type==CPU ? 4 : v->numvalues));
  1423. X      v->validx = newlen - 1;
  1424. X      return;
  1425. X    }
  1426. X
  1427. X/* Realloc a ringbuffer */
  1428. X  for(l = 0; l < v->numvalues; l++)
  1429. X    {
  1430. X      np = (int *)calloc(sizeof(int), newlen);
  1431. X      op = v->values[l];
  1432. X      if(newlen > oldlen)
  1433. X    {
  1434. X      k = newlen - oldlen;
  1435. X      for(j = 0; j < k; j++)
  1436. X        np[j] = 0;
  1437. X      
  1438. X      for(k = v->validx; j < newlen; j++, k = (k+1) % oldlen)
  1439. X        np[j] = op[k];
  1440. X    }
  1441. X      else
  1442. X    {
  1443. X      k = (v->validx + oldlen - newlen + 1) % oldlen;
  1444. X      for(j = 0; j < newlen; j++)
  1445. X        np[j] = op[(k+j)%oldlen];
  1446. X    }
  1447. X      free(op);
  1448. X      v->values[l] = np;
  1449. X    }
  1450. X  v->validx = newlen - 1;
  1451. X}
  1452. X
  1453. Xstatic void
  1454. XDrawText(v, drawtime)
  1455. X  struct values *v;
  1456. X  int drawtime;
  1457. X{
  1458. X  int j, where, dir, ascent, descent;
  1459. X  int drone = FSET(v, draw_one);
  1460. X  int height = (v->ypos+1) * height1;
  1461. X  XCharStruct or;
  1462. X  char *ti, buf[16];
  1463. X
  1464. X  if(drawtime)
  1465. X    {
  1466. X      ti = (char *)ctime((time_t *)&drawtime) + 11; ti[8] = '\0';
  1467. X      if(!pm.width)
  1468. X        {
  1469. X      XTextExtents(font_info, ti, 8, &dir, &ascent, &descent, &or);
  1470. X      v->pm->posx = width2 - 1 - or.width;
  1471. X      v->pm->posy = height1 - 1 - descent;
  1472. X      v->pm->width = or.width;
  1473. X        }
  1474. X      XDrawImageString(dpy, pm.pm, pm.colorgc[BLACK],
  1475. X               v->xpos*width1  + v->pm->posx,
  1476. X               v->ypos*height1 + v->pm->posy, ti, 8);
  1477. X      return;
  1478. X    }
  1479. X
  1480. X  /* Draw text (cpu) */
  1481. X  XTextExtents(font_info, v->name, strlen(v->name), &dir,&ascent,&descent,&or);
  1482. X  XDrawImageString(dpy, pm.pm, pm.colorgc[BLACK],
  1483. X      v->xpos*width1+2, height-descent-1, v->name, strlen(v->name));
  1484. X  where = v->xpos*width1 + 2+or.width;
  1485. X
  1486. X  /* Draw more text (sys nice usr) */
  1487. X  for(j = 0; !drone && j < 4 && v->subname[j]; j++)
  1488. X    {
  1489. X      char *str = v->subname[j];
  1490. X
  1491. X      XDrawImageString(dpy, pm.pm, pm.colorgc[j],
  1492. X            where + 5, height-descent-1, str, strlen(str));
  1493. X      XTextExtents(font_info, str, strlen(str),
  1494. X                    &dir,&ascent,&descent,&or);
  1495. X      where += 5 + or.width;
  1496. X    }
  1497. X  sprintf(buf, "%d", v->maxval_to_show == -1 ? v->maxval : v->maxval_to_show);
  1498. X  XTextExtents(font_info,buf,strlen(buf),&dir,&ascent,&descent,&or);
  1499. X  XDrawImageString(dpy, pm.pm, pm.colorgc[BLACK],
  1500. X         v->xpos * width1 + width2 - 2 - or.width,
  1501. X         height-descent-1, buf, strlen(buf));
  1502. X}
  1503. X          
  1504. Xstatic void
  1505. Xdopaint(doit)
  1506. X  int doit;
  1507. X{
  1508. X  int x, y, i, j, k, vl, oldwidth2,
  1509. X      size_changed, dir, ascent, descent;
  1510. X  XCharStruct or;
  1511. X  struct values *v;
  1512. X
  1513. X  x = xv_get(canvas_paint_window(ca), XV_WIDTH);
  1514. X  y = xv_get(canvas_paint_window(ca), XV_HEIGHT) -1;
  1515. X
  1516. X  size_changed = (win_x != x || real_win_y != y);
  1517. X  if(size_changed || doit)
  1518. X    {
  1519. X      CreatePM(&pm, x, y);
  1520. X
  1521. X      win_x = x; win_y = real_win_y = y;
  1522. X      if(strcmp(host, "localhost"))
  1523. X        {
  1524. X      win_y = real_win_y - fontheight;
  1525. X      XTextExtents(font_info, host, strlen(host),
  1526. X                         &dir, &ascent, &descent, &or);
  1527. X      XDrawImageString(dpy, pm.pm, pm.colorgc[BLACK],
  1528. X          (x-or.width)/2, real_win_y-descent-2, host, strlen(host));
  1529. X    }
  1530. X      oldwidth2 = width2;
  1531. X      width1  = win_x / columns;
  1532. X      width2  = width1 - 3;
  1533. X      height1 = win_y / ((nrcurr_active + columns - 1) / columns);
  1534. X
  1535. X      for(i = 0; values[i].numvalues; i++)
  1536. X        {
  1537. X      v = &values[i];
  1538. X      vl = VALUES_LENGTH(v);
  1539. X      realloc_values(v, FSET(v, scrollback) + oldwidth2, vl);
  1540. X
  1541. X      if(v->active)
  1542. X        {
  1543. X              DrawText(v, 0);
  1544. X          k = (v->validx - width2 + 1 + vl) % vl;
  1545. X          for(j = 1; j < width2; j++)
  1546. X            {
  1547. X          DrawPixels(&values[i], &pm, k, j);
  1548. X          k = (k+1) % vl;
  1549. X        }
  1550. X        }
  1551. X    }
  1552. X    }
  1553. X  /* Copy the stripes */
  1554. X  if(size_changed || just_started)
  1555. X    XFillRectangle(dpy, win, wingc, 0, 0, x, y);
  1556. X  for(i = 0; values[i].numvalues; i++)
  1557. X    {
  1558. X      v = &values[i];
  1559. X      if(!v->active)
  1560. X        continue;
  1561. X      x = v->xpos * width1; y = v->ypos * height1;
  1562. X      if(!v->pm)
  1563. X    {
  1564. X      XCopyArea(dpy, pm.pm, win, wingc, x, y, width2, height1, x, y);
  1565. X    }
  1566. X      else
  1567. X        {
  1568. X      XCopyArea(dpy, pm.pm, win, wingc, 
  1569. X        x, y+height1-fontheight+1, width2, fontheight,
  1570. X        x, y+height1-fontheight+1);
  1571. X      x = FSET(v, scrollback);
  1572. X      XCopyArea(dpy, v->pm->pm, win, wingc, 
  1573. X        x-v->pm->offset, 0, width2, height1-fontheight+1,
  1574. X        v->xpos * width1, v->ypos * height1);
  1575. X    }
  1576. X    }
  1577. X  if(real_win_y - win_y)
  1578. X    XCopyArea(dpy, pm.pm, win, wingc, 0,win_y,win_x,real_win_y-win_y,0,win_y);
  1579. X  for(i = 1; i < columns; i++)
  1580. X    {
  1581. X      x = (width1 * (i-1)) + width2 + 1;
  1582. X      XDrawLine(dpy, win, bwingc, x, 0, x, win_y);
  1583. X    }
  1584. X  XFlush(dpy);
  1585. X}
  1586. X
  1587. Xstatic int
  1588. Xcheckbox()
  1589. X{
  1590. X  int i, v, oldval = 0, from, to, vl;
  1591. X  struct values *p;
  1592. X
  1593. X  v = xv_get(pi_check, PANEL_VALUE);
  1594. X  if(active)
  1595. X    {
  1596. X      oldval |= active->draw_line ? 0 : 1;
  1597. X      oldval |= active->no_smooth ? 0 : 2;
  1598. X      oldval |= active->draw_one  ? 4 : 0;
  1599. X      oldval |= active->no_reset  ? 0 : 8;
  1600. X      oldval |= active->add_values?16 : 0;
  1601. X
  1602. X      active->draw_line = (v & 1) ? 0 : 1;
  1603. X      active->no_smooth = (v & 2) ? 0 : 1;
  1604. X      active->draw_one  = (v & 4) ? 1 : 0;
  1605. X      active->add_values= (v &16) ? 1 : 0;
  1606. X      if((v&8) && active->no_reset)
  1607. X        {
  1608. X      vl = VALUES_LENGTH(active);
  1609. X      from = (active->validx + 1 - width2 + vl) % vl;
  1610. X      to   = active->validx-1;
  1611. X      rescale(active, from, to);
  1612. X    }
  1613. X      active->no_reset  = (v & 8) ? 0 : 1;
  1614. X
  1615. X      if(!active->draw_line && depth == 1)
  1616. X    active->draw_one = 1;
  1617. X      return (v != oldval);
  1618. X    }
  1619. X  else
  1620. X    {
  1621. X      oldval |= draw_line ? 0 : 1;
  1622. X      oldval |= no_smooth ? 0 : 2;
  1623. X      oldval |= draw_one  ? 4 : 0;
  1624. X      oldval |= no_reset  ? 0 : 8;
  1625. X      oldval |= add_values?16 : 0;
  1626. X
  1627. X      draw_line = !(v & 1);
  1628. X      no_smooth = !(v & 2);
  1629. X      draw_one  = (v & 4);
  1630. X      add_values= (v & 16);
  1631. X      if((v&8) && no_reset)
  1632. X        {
  1633. X      for(i = 0; values[i].numvalues; i++)
  1634. X        {
  1635. X          p = &values[i];
  1636. X          if(p->special)
  1637. X            continue;
  1638. X          vl = VALUES_LENGTH(p);
  1639. X          from = (p->validx + 1 - width2 + vl) % vl;
  1640. X          to   = p->validx-1;
  1641. X          rescale(p, from, to);
  1642. X        }
  1643. X    }
  1644. X      no_reset  = !(v & 8);
  1645. X
  1646. X      if(!draw_line && depth == 1)
  1647. X    draw_one = 1;
  1648. X      return (v != oldval);
  1649. X    }
  1650. X}
  1651. X
  1652. Xstatic int
  1653. Xselection(pi, v, e)
  1654. X  Panel_item pi;
  1655. X  int v;
  1656. X  Event *e;
  1657. X{
  1658. X  int i, j, max;
  1659. X  int oldnr, changed = 0;
  1660. X
  1661. X  if(!v)
  1662. X    {
  1663. X      v = 1;
  1664. X      xv_set(pi, PANEL_VALUE, v, NULL);
  1665. X    }
  1666. X
  1667. X  oldnr = nrcurr_active;
  1668. X  for(i = 0; values[i].numvalues; i++)
  1669. X    {
  1670. X      if(values[i].active && !(v & (1<<i)))
  1671. X    {
  1672. X      for(j = 0; values[j].numvalues; j++)
  1673. X        if(values[j].active > values[i].active)
  1674. X          values[j].active--;
  1675. X      values[i].active = 0;
  1676. X      nrcurr_active--;
  1677. X      changed++;
  1678. X    }
  1679. X      else if(!values[i].active && (v & (1<<i)))
  1680. X    {
  1681. X      for(max = j = 0; values[j].numvalues; j++)
  1682. X        if(values[j].active > max)
  1683. X          max = values[j].active;
  1684. X      values[i].active = max+1;
  1685. X      nrcurr_active++;
  1686. X      changed++;
  1687. X    }
  1688. X    }
  1689. X  if(oldnr != nrcurr_active)
  1690. X    {
  1691. X      int diff, newheight;
  1692. X
  1693. X      /* just_started = 1; */
  1694. X      if(nrcurr_active < columns)
  1695. X    columns = nrcurr_active;
  1696. X
  1697. X      if(xv_get(pi_cols, PANEL_VALUE) != columns)
  1698. X        return changed;
  1699. X
  1700. X      newheight = height1*((nrcurr_active+columns-1)/columns)+real_win_y-win_y;
  1701. X      diff = xv_get(fr, XV_HEIGHT) - xv_get(canvas_paint_window(ca), XV_HEIGHT);
  1702. X      xv_set(canvas_paint_window(ca), XV_HEIGHT, newheight+1, NULL);
  1703. X      xv_set(fr, XV_HEIGHT, newheight+1+diff, NULL);
  1704. X      if(nrcurr_active < columns)
  1705. X    {
  1706. X      diff = xv_get(fr,XV_WIDTH) - xv_get(canvas_paint_window(ca),XV_WIDTH);
  1707. X      xv_set(canvas_paint_window(ca),XV_WIDTH,width1*columns, NULL);
  1708. X      xv_set(fr, XV_WIDTH, width1*columns+diff, NULL);
  1709. X    }
  1710. X    }
  1711. X    
  1712. X  return changed;
  1713. X}
  1714. X
  1715. Xstatic void
  1716. Xspp()
  1717. X{
  1718. X  int i, min, v = xv_get(pi_spp, PANEL_VALUE);
  1719. X
  1720. X  if(active)
  1721. X    {
  1722. X      active->sec_perpixel = v;
  1723. X      active->lastsec = 0;
  1724. X    }
  1725. X  else
  1726. X    {
  1727. X      sec_perpixel = v;
  1728. X      lastsec = 0;
  1729. X    }
  1730. X
  1731. X/* Ahem.. correct gcd would be better... */
  1732. X  min = sec_perpixel;
  1733. X  for(i = 0; values[i].numvalues; i++)
  1734. X    if(values[i].special && min != values[i].sec_perpixel)
  1735. X      {
  1736. X    if(min % values[i].sec_perpixel == 0)
  1737. X      min = values[i].sec_perpixel;
  1738. X    else if(values[i].sec_perpixel % min != 0)
  1739. X      min = 1;
  1740. X      }
  1741. X        
  1742. X  if(min != min_spp)
  1743. X    {
  1744. X      min_spp = min;
  1745. X      do_alarm(min_spp);
  1746. X    }
  1747. X}
  1748. X
  1749. Xstatic int
  1750. Xmachine()
  1751. X{
  1752. X  char *s = (char *)xv_get(pi_mach, PANEL_VALUE);
  1753. X  int i, j;
  1754. X  extern void bzero();
  1755. X  struct values *v;
  1756. X
  1757. X  if(!s || !*s)
  1758. X    s = "localhost";
  1759. X  if(!strcmp(s, host))
  1760. X    return 0;
  1761. X  free(host);
  1762. X  for(i = 0; values[i].numvalues; i++)
  1763. X    {
  1764. X      v = &values[i];
  1765. X      for(j = 0; j < v->numvalues; j++)
  1766. X    bzero(v->values[j], sizeof(int) * VALUES_LENGTH(v));
  1767. X      rescale(v, 0, VALUES_LENGTH(v)-1);
  1768. X    }
  1769. X  host = strdup(s);
  1770. X  just_started = 1;
  1771. X
  1772. X  return 1;
  1773. X}
  1774. X
  1775. Xstatic void
  1776. Xset_columns()
  1777. X{
  1778. X  int i;
  1779. X
  1780. X  for(i = 0; values[i].numvalues; i++)
  1781. X    if(values[i].active)
  1782. X      {
  1783. X    values[i].xpos = (values[i].active-1) % columns;
  1784. X    values[i].ypos = (values[i].active-1) / columns;
  1785. X      }
  1786. X}
  1787. X
  1788. Xstatic int
  1789. Xdocolumns()
  1790. X{
  1791. X  int i, newheight, newwidth, diffw, diffh;
  1792. X  if((i = xv_get(pi_cols, PANEL_VALUE)) == columns)
  1793. X    return 0;
  1794. X  columns = i > nrcurr_active ? nrcurr_active : i;
  1795. X
  1796. X  newwidth  = width1 * columns;
  1797. X  newheight = height1 * ((nrcurr_active+columns-1)/columns) + real_win_y-win_y;
  1798. X  diffh = xv_get(fr, XV_HEIGHT) - xv_get(canvas_paint_window(ca), XV_HEIGHT);
  1799. X  diffw = xv_get(fr, XV_WIDTH) - xv_get(canvas_paint_window(ca), XV_WIDTH);
  1800. X
  1801. X  xv_set(canvas_paint_window(ca),
  1802. X    XV_HEIGHT, newheight + 1, XV_WIDTH,  newwidth, NULL);
  1803. X  xv_set(fr, XV_HEIGHT, newheight+diffh+1, XV_WIDTH, newwidth+diffw, NULL);
  1804. X  return 1;
  1805. X}
  1806. X
  1807. Xstatic void
  1808. Xdoscrollback()
  1809. X{
  1810. X  int i, oldlen = 0, v = xv_get(pi_scbk, PANEL_VALUE);
  1811. X  struct values *val;
  1812. X
  1813. X  if(active)
  1814. X    {
  1815. X      oldlen = VALUES_LENGTH(active);
  1816. X      active->special = 1;
  1817. X      active->scrollback = v;
  1818. X      realloc_values(active, oldlen, VALUES_LENGTH(active));
  1819. X    }
  1820. X  else
  1821. X    {
  1822. X      for(i = 0; values[i].numvalues; i++)
  1823. X        {
  1824. X      val = &values[i];
  1825. X      if(!(val->special))
  1826. X        {
  1827. X          oldlen = VALUES_LENGTH(val);
  1828. X          break;
  1829. X        }
  1830. X    }
  1831. X      scrollback = v;
  1832. X      for(i = 0; values[i].numvalues; i++)
  1833. X        {
  1834. X      val = &values[i];
  1835. X      if(!(val->special))
  1836. X        realloc_values(val, oldlen, VALUES_LENGTH(val));
  1837. X    }
  1838. X    }
  1839. X}
  1840. X
  1841. Xstatic int
  1842. Xapply(i, e)
  1843. X  Panel_item i;
  1844. X  Event *e;
  1845. X{
  1846. X  int redraw = 0;
  1847. X
  1848. X  if(!active)
  1849. X    {
  1850. X      redraw += selection(pi_sels, xv_get(pi_sels, PANEL_VALUE), e);
  1851. X      redraw += docolumns();
  1852. X      redraw += machine();
  1853. X      set_columns();
  1854. X    }
  1855. X  doscrollback();
  1856. X  spp();
  1857. X  redraw += checkbox();
  1858. X
  1859. X  if(redraw)
  1860. X    dopaint(1);
  1861. X  return XV_OK;
  1862. X}
  1863. X
  1864. Xstatic int
  1865. Xhide(i, e)
  1866. X  Panel_item i;
  1867. X  Event *e;
  1868. X{
  1869. X  xv_set(pfr, XV_SHOW, FALSE, NULL);
  1870. X  return XV_OK;
  1871. X}
  1872. X
  1873. Xstatic int
  1874. Xnosp_proc()
  1875. X{
  1876. X  int i;
  1877. X
  1878. X  if(active)
  1879. X    active->special = 0;
  1880. X  else
  1881. X    {
  1882. X      for(i = 0; values[i].numvalues; i++)
  1883. X        values[i].special = 0;
  1884. X    }
  1885. X  dopaint(1);
  1886. X  return XV_OK;
  1887. X}
  1888. X
  1889. Xstatic int
  1890. Xdofork()
  1891. X{
  1892. X  switch(fork())
  1893. X    {
  1894. X      case -1:
  1895. X        perror("fork");
  1896. X    return XV_OK;
  1897. X      case 0:
  1898. X/* Not very nice, but xview isn't reentrant */
  1899. X    execvp(argv[0], argv);
  1900. X        perror(argv[0]);
  1901. X    return XV_OK;
  1902. X      default:
  1903. X    return XV_OK;
  1904. X    }
  1905. X}
  1906. X
  1907. Xstatic void
  1908. Xcreate_pfr()
  1909. X{
  1910. X  int i, v, y;
  1911. X
  1912. X    
  1913. X  pfr = xv_create(fr, FRAME_CMD, FRAME_LABEL, PROGNAME, NULL);
  1914. X  pn = xv_get(pfr, FRAME_CMD_PANEL);
  1915. X  xv_set(pn, WIN_ROW_GAP, xv_get(pn, WIN_ROW_GAP)/3, NULL);
  1916. X
  1917. X  for(v = i = 0; values[i].numvalues; i++)
  1918. X    if(values[i].active)
  1919. X      v |= (1 << i);
  1920. X  pi_sels = xv_create(pn, PANEL_TOGGLE,
  1921. X    XV_X, xv_col(pn, 1),
  1922. X    XV_Y, xv_row(pn, 0),
  1923. X    PANEL_CHOICE_STRINGS,
  1924. X      values[0].name, values[1].name, values[2].name, values[3].name,
  1925. X      values[4].name, values[5].name, values[6].name, values[7].name,
  1926. X      values[8].name, values[9].name, NULL,
  1927. X    PANEL_CHOICE_NCOLS, 5,
  1928. X    PANEL_VALUE, v,
  1929. X    NULL);
  1930. X
  1931. X
  1932. X  y = xv_get(pi_sels, XV_Y) + xv_get(pi_sels, XV_HEIGHT) + xv_row(pn, 1);
  1933. X
  1934. X  pi_check = xv_create(pn, PANEL_CHECK_BOX,
  1935. X    XV_Y, y,
  1936. X    PANEL_LAYOUT, PANEL_VERTICAL,
  1937. X    PANEL_CHOICE_STRINGS,
  1938. X      "Solid graph (s)", "Smooth if solid (o)", "Show sum only (1)",
  1939. X      "Autoreset", "Add values (a)", NULL,
  1940. X    NULL);
  1941. X  xv_set(pi_check, 
  1942. X    XV_X, xv_get(pi_sels, XV_X) + xv_get(pi_sels, XV_WIDTH) -
  1943. X          xv_get(pi_check, XV_WIDTH),
  1944. X    NULL);
  1945. X  
  1946. X  pi_mach = xv_create(pn, PANEL_TEXT,
  1947. X    XV_Y, y, XV_X, xv_get(pi_sels, XV_X),
  1948. X    PANEL_LABEL_STRING, "Machine:",
  1949. X    PANEL_VALUE, host,
  1950. X    PANEL_VALUE_DISPLAY_LENGTH, 16,
  1951. X    NULL);
  1952. X  
  1953. X  pi_spp = xv_create(pn, PANEL_NUMERIC_TEXT,
  1954. X    XV_Y, xv_get(pi_mach, XV_Y) + xv_get(pi_mach, XV_HEIGHT) + xv_row(pn, 1)/2,
  1955. X    XV_X, xv_get(pi_sels, XV_X),
  1956. X    PANEL_LABEL_STRING, "Sample time (sec):",
  1957. X    PANEL_VALUE, sec_perpixel,
  1958. X    PANEL_MIN_VALUE, 1,
  1959. X    PANEL_VALUE_DISPLAY_LENGTH, 4,
  1960. X    NULL);
  1961. X
  1962. X  pi_scbk = xv_create(pn, PANEL_NUMERIC_TEXT,
  1963. X    XV_Y, xv_get(pi_spp, XV_Y) + xv_get(pi_spp, XV_HEIGHT) + xv_row(pn, 1)/2,
  1964. X    XV_X, xv_get(pi_sels, XV_X),
  1965. X    PANEL_LABEL_STRING, "Scrollback (values):",
  1966. X    PANEL_MIN_VALUE, 0,
  1967. X    PANEL_MAX_VALUE, 20000,
  1968. X    PANEL_VALUE, scrollback,
  1969. X    PANEL_VALUE_DISPLAY_LENGTH, 5,
  1970. X    NULL);
  1971. X
  1972. X  pi_cols = xv_create(pn, PANEL_NUMERIC_TEXT,
  1973. X    XV_Y, xv_get(pi_scbk, XV_Y) + xv_get(pi_scbk, XV_HEIGHT) + xv_row(pn, 1)/2,
  1974. X    XV_X, xv_get(pi_sels, XV_X),
  1975. X    PANEL_LABEL_STRING, "Columns:",
  1976. X    PANEL_INACTIVE, TRUE,
  1977. X    PANEL_MAX_VALUE, 10, PANEL_MIN_VALUE, 1,
  1978. X    PANEL_VALUE, columns,
  1979. X    PANEL_VALUE_DISPLAY_LENGTH, 2,
  1980. X    NULL);
  1981. X  
  1982. X  pi_nosp = xv_create(pn, PANEL_BUTTON,
  1983. X    XV_Y, xv_get(pi_cols, XV_Y) + xv_get(pi_cols, XV_HEIGHT) + xv_row(pn, 1)/2,
  1984. X    XV_X, xv_get(pi_sels, XV_X),
  1985. X    PANEL_LABEL_STRING, "No special flags",
  1986. X    PANEL_NOTIFY_PROC, nosp_proc,
  1987. X    NULL);
  1988. X  pi_fork = xv_create(pn, PANEL_BUTTON,
  1989. X    XV_Y, xv_get(pi_nosp, XV_Y),
  1990. X    XV_X, xv_get(pi_nosp, XV_X) + xv_get(pi_nosp, XV_WIDTH) + xv_col(pn, 1),
  1991. X    PANEL_LABEL_STRING, "Fork",
  1992. X    PANEL_NOTIFY_PROC, dofork,
  1993. X    NULL);
  1994. X  pi_msg = xv_create(pn, PANEL_MESSAGE,
  1995. X    XV_Y, xv_get(pi_nosp, XV_Y) + xv_get(pi_nosp, XV_HEIGHT) + xv_row(pn, 1)/3,
  1996. X    XV_X, xv_get(pi_sels, XV_X),
  1997. X    NULL);
  1998. X
  1999. X  window_fit_width(pn);
  2000. X  pi_apply = xv_create(pn, PANEL_BUTTON,
  2001. X    XV_Y, xv_get(pi_fork, XV_Y) + xv_get(pi_fork, XV_HEIGHT) + xv_row(pn, 1),
  2002. X    PANEL_LABEL_STRING, "Apply",
  2003. X    PANEL_NOTIFY_PROC, apply,
  2004. X    NULL);
  2005. X  xv_set(pi_apply,
  2006. X    XV_X, xv_get(pn, XV_WIDTH)/3 - xv_get(pi_apply, XV_WIDTH)/2,
  2007. X    NULL);
  2008. X
  2009. X  pi_hide = xv_create(pn, PANEL_BUTTON,
  2010. X    XV_Y, xv_get(pi_apply, XV_Y),
  2011. X    PANEL_LABEL_STRING, "Hide window",
  2012. X    PANEL_NOTIFY_PROC, hide,
  2013. X    NULL);
  2014. X  xv_set(pi_hide,
  2015. X    XV_X, 2*xv_get(pn, XV_WIDTH)/3 - xv_get(pi_hide, XV_WIDTH)/2,
  2016. X    NULL);
  2017. X
  2018. X  window_fit(pn);
  2019. X  window_fit(pfr);
  2020. X}
  2021. X
  2022. Xstatic void
  2023. Xgrayout(val)
  2024. X  struct values *val;
  2025. X{
  2026. X  int v = val ? 1 : 0;
  2027. X  char buf[256];
  2028. X
  2029. X  xv_set(pi_sels, PANEL_INACTIVE, v, NULL);
  2030. X  xv_set(pi_mach, PANEL_INACTIVE, v, NULL);
  2031. X  xv_set(pi_cols, PANEL_INACTIVE, v, NULL);
  2032. X  xv_set(pi_fork, PANEL_INACTIVE, v, NULL);
  2033. X  if(strcmp(host, "localhost"))
  2034. X    sprintf(buf, "%s (%s)", val ? active->name : PROGNAME, host);
  2035. X  else
  2036. X    sprintf(buf, "%s", val ? active->name : PROGNAME);
  2037. X  xv_set(pfr, FRAME_LABEL, buf, NULL);
  2038. X
  2039. X  v = 0;
  2040. X  if(val && val->special)
  2041. X    {
  2042. X      if(!val->draw_line) v |= 1; if(!val->no_smooth) v |= 2;
  2043. X      if(val->draw_one) v |= 4;   if(!val->no_reset) v |= 8;
  2044. X      if(val->add_values) v |= 16;
  2045. X    }
  2046. X  else
  2047. X    {
  2048. X      if(!draw_line) v |= 1; if(!no_smooth) v |= 2;
  2049. X      if(draw_one) v |= 4;   if(!no_reset) v |= 8;
  2050. X      if(add_values) v |= 16;
  2051. X    }
  2052. X  xv_set(pi_check, PANEL_VALUE, v, NULL);
  2053. X  xv_set(pi_spp,
  2054. X    PANEL_VALUE, (val && val->special) ? val->sec_perpixel : sec_perpixel,
  2055. X    NULL);
  2056. X  xv_set(pi_scbk,
  2057. X    PANEL_VALUE, (val && val->special) ? val->scrollback : scrollback,
  2058. X    NULL);
  2059. X  xv_set(pi_msg, PANEL_LABEL_STRING, "", NULL);
  2060. X}
  2061. X
  2062. Xstatic struct values *
  2063. Xpostoval(e)
  2064. X  Event *e;
  2065. X{
  2066. X  int i, j = event_y(e)/height1, k = event_x(e)/width1;
  2067. X
  2068. X  for(i = 0; values[i].numvalues; i++)
  2069. X    if(values[i].active && values[i].xpos == k && values[i].ypos == j)
  2070. X      break;
  2071. X  if(!values[i].numvalues)
  2072. X    return 0;
  2073. X  return &values[i];
  2074. X}
  2075. X
  2076. Xstatic void
  2077. Xreset_scrolled(ifzero)
  2078. X  int ifzero;
  2079. X{
  2080. X  int i, xx, yy;
  2081. X  struct values *v;
  2082. X
  2083. X  for(i = 0; values[i].numvalues; i++)
  2084. X    if(values[i].pm)
  2085. X      {
  2086. X    if(!(ifzero && values[i].pm->offset))
  2087. X      {
  2088. X        v = &values[i];
  2089. X
  2090. X        xx = v->xpos * width1; yy = v->ypos * height1;
  2091. X
  2092. X        XFillRectangle(dpy, pm.pm, pm.colorgc[WHITE], 
  2093. X          xx + v->pm->posx, yy + height1 - fontheight + 1,
  2094. X          v->pm->width, fontheight);
  2095. X        DrawText(v, 0);
  2096. X
  2097. X        XCopyArea(dpy, pm.pm, win, wingc, 
  2098. X          xx + v->pm->posx, yy + height1 - fontheight + 2,
  2099. X          v->pm->width,fontheight,
  2100. X          xx + v->pm->posx, yy + height1 - fontheight + 2);
  2101. X
  2102. X        v->selected = 0;
  2103. X        FreePM(v->pm);
  2104. X        free(v->pm);
  2105. X        v->pm = 0;
  2106. X      }
  2107. X      }
  2108. X    else if(values[i].selected)
  2109. X      values[i].selected = 0;
  2110. X}
  2111. X
  2112. Xstatic void
  2113. Xevent_proc(w, e)
  2114. X  Xv_window w;
  2115. X  Event *e;
  2116. X{
  2117. X  static int lastx, dragged;
  2118. X  struct values *v;
  2119. X  int i, x, y;
  2120. X
  2121. X  if(event_is_ascii(e))
  2122. X    {
  2123. X      if(event_is_up(e))
  2124. X    return;
  2125. X      switch(event_action(e))
  2126. X        {
  2127. X      case 'q': case 'Q':
  2128. X        exit(0);
  2129. X        break;
  2130. X      case 's': case 'S':
  2131. X        draw_line = !draw_line;
  2132. X        if(!draw_line && depth == 1)
  2133. X          draw_one = 1;
  2134. X        dopaint(1);
  2135. X        break;
  2136. X      case 'o': case 'O':
  2137. X        no_smooth = !no_smooth;
  2138. X        dopaint(1);
  2139. X        break;
  2140. X      case 'a':
  2141. X        add_values = !add_values;
  2142. X        dopaint(1);
  2143. X        break;
  2144. X      case '1':
  2145. X        draw_one = !draw_one;
  2146. X        if(!draw_line && depth == 1)
  2147. X          draw_one = 1;
  2148. X        dopaint(1);
  2149. X        break;
  2150. X      case '?': case 'h':
  2151. X        if(!pfr)
  2152. X          create_pfr();
  2153. X        xv_set(pfr, XV_SHOW, TRUE, NULL);
  2154. X        break;
  2155. X      case 10: /* CR/NL */
  2156. X      case 13:
  2157. X        reset_scrolled(0);
  2158. X        dopaint(1);
  2159. X        return;
  2160. X    }
  2161. X      return;
  2162. X    }
  2163. X  switch(event_action(e))
  2164. X    {
  2165. X      case WIN_RESIZE:
  2166. X        lost_connection = 0;
  2167. X    x = e->ie_xevent->xconfigure.width;
  2168. X    y = e->ie_xevent->xconfigure.height;
  2169. X    if(x <= win_x && y <= real_win_y)
  2170. X      {
  2171. X        reset_scrolled(0);
  2172. X        dopaint(0);
  2173. X      }
  2174. X    break;
  2175. X      case WIN_REPAINT:
  2176. X    x = xv_get(canvas_paint_window(ca), XV_WIDTH);
  2177. X    y = xv_get(canvas_paint_window(ca), XV_HEIGHT) -1;
  2178. X    if(x != win_x || y != real_win_y)
  2179. X      reset_scrolled(0);
  2180. X    dopaint(0);
  2181. X        break;
  2182. X      case LOC_DRAG:
  2183. X        if(!dragged)
  2184. X      return;
  2185. X    dragged = 2;
  2186. X    for(i = 0; values[i].numvalues; i++)
  2187. X      if(values[i].selected)
  2188. X        {
  2189. X          int k, off;
  2190. X
  2191. X          v = &values[i];
  2192. X
  2193. X          if(!v->pm)
  2194. X        {
  2195. X          int mx, my, vl, j, k;
  2196. X
  2197. X          vl = VALUES_LENGTH(v);
  2198. X          if(!v->pm)
  2199. X            v->pm = (struct pm *)calloc(1, sizeof(pm));
  2200. X          CreatePM(v->pm, vl, height1-fontheight+2);
  2201. X          v->pm->width = v->pm->offset = 0;
  2202. X          v->pm->starttime = time(0);
  2203. X          v->pm->startvalidx = v->validx;
  2204. X          mx = v->xpos; my = v->ypos; 
  2205. X          v->xpos = v->ypos = 0; 
  2206. X
  2207. X          k = (v->validx + 1) % vl;
  2208. X          for(j = 1; j < vl; k %= vl)
  2209. X            DrawPixels(v, v->pm, k++, j++);
  2210. X          v->xpos = mx; v->ypos = my; 
  2211. X        }
  2212. X
  2213. X          off = v->pm->offset + event_x(e) - lastx;
  2214. X          k = v->special ? v->scrollback : scrollback;
  2215. X          if(off < 0) off = 0;
  2216. X          if(off > k) off = k;
  2217. X          if(off != v->pm->offset)
  2218. X            {
  2219. X          int xx = v->xpos * width1,
  2220. X              yy = v->ypos * height1;
  2221. X
  2222. X          v->pm->offset = off;
  2223. X          DrawText(v, v->pm->starttime - 
  2224. X                     (off * FSET(v, sec_perpixel)));
  2225. X          XCopyArea(dpy, v->pm->pm, win, wingc, 
  2226. X            k - off, 0, width2, height1-fontheight+2, xx, yy);
  2227. X          XCopyArea(dpy, pm.pm, win, wingc, 
  2228. X            xx + v->pm->posx, yy + height1 - fontheight+2,
  2229. X            v->pm->width,fontheight,
  2230. X            xx + v->pm->posx, yy + height1 - fontheight+2);
  2231. X        }
  2232. X        }
  2233. X    lastx = event_x(e);
  2234. X        break;
  2235. X      case ACTION_ADJUST:
  2236. X      case MS_MIDDLE:
  2237. X        if(event_is_up(e) || !(v = postoval(e)))
  2238. X      return;
  2239. X    v->selected = 1;
  2240. X        break;
  2241. X      case ACTION_SELECT:
  2242. X      case MS_LEFT:
  2243. X        if(event_is_down(e))
  2244. X      {
  2245. X        lastx = event_x(e);
  2246. X        dragged = 1;
  2247. X        if(!(v = postoval(e)))
  2248. X          return;
  2249. X        if(!v->selected)
  2250. X          {
  2251. X            for(i = 0; values[i].numvalues; i++)
  2252. X          values[i].selected = 0;
  2253. X            v->selected = 1;
  2254. X          }
  2255. X      }
  2256. X    else
  2257. X      {
  2258. X        char buf[128];
  2259. X
  2260. X        if(dragged)
  2261. X          {
  2262. X        lastx = -1;
  2263. X        if(dragged == 2)
  2264. X          {
  2265. X            reset_scrolled(1);
  2266. X            dragged = 0;
  2267. X            return;
  2268. X          }
  2269. X        dragged = 0;
  2270. X          }
  2271. X        if(!(v = postoval(e)))
  2272. X          return;
  2273. X        y = VALUES_LENGTH(v);
  2274. X        x = v->pm ? v->pm->startvalidx - v->pm->offset : v->validx;
  2275. X        x -= ((width1 * v->xpos) + width2 - event_x(e));
  2276. X        x = (x + y) % y;
  2277. X        sprintf(buf, "%s: ", v->name);
  2278. X        if(v->type == LOAD)
  2279. X          {
  2280. X        sprintf(buf+strlen(buf), "%.2f",
  2281. X                                (double)v->values[0][x]/256.0);
  2282. X          }
  2283. X        else
  2284. X          {
  2285. X        for(y = 0; y < v->numvalues; y++)
  2286. X          sprintf(buf+strlen(buf), "%s %d ", 
  2287. X            v->subname[y]?v->subname[y] : "", v->values[y][x]);
  2288. X          }
  2289. X        if(pi_msg)
  2290. X          xv_set(pi_msg, PANEL_LABEL_STRING, buf, NULL);
  2291. X      }
  2292. X        break;
  2293. X      case ACTION_MENU:
  2294. X      case MS_RIGHT:
  2295. X    if(event_is_up(e))
  2296. X      return;
  2297. X    if(!pfr)
  2298. X      create_pfr();
  2299. X    if(event_shift_is_down(e))
  2300. X      {
  2301. X        active = postoval(e);
  2302. X        grayout(active);
  2303. X      }
  2304. X    else
  2305. X      {
  2306. X        if(xv_get(pfr, XV_SHOW))
  2307. X          {
  2308. X        xv_set(pfr, XV_SHOW, FALSE, NULL);
  2309. X        return;
  2310. X          }
  2311. X        active = NULL;
  2312. X        grayout(0);
  2313. X      }
  2314. X    xv_set(pfr, XV_SHOW, TRUE, NULL);
  2315. X    break;
  2316. X    }
  2317. X
  2318. X}
  2319. X  
  2320. Xvoid
  2321. Xgetdefault(name, value)
  2322. X  char *name;
  2323. X  int *value;
  2324. X{
  2325. X  static char none[] = "NONE";
  2326. X  char *str, buffer[128];
  2327. X
  2328. X  sprintf(buffer, "%s.%s", PROGNAME, name);
  2329. X  str = defaults_get_string(buffer, buffer, none);
  2330. X  if(!strcmp(str, none))
  2331. X    return;
  2332. X  if(!strcmp(str, "True") || !strcmp(str, "true") || 
  2333. X     !strcmp(str, "Yes") || !strcmp(str, "yes"))
  2334. X   {
  2335. X     *value = 1;
  2336. X     return;
  2337. X   }
  2338. X  if(*str == '#')
  2339. X    *value = strtol(str+1, NULL, 16);
  2340. X  else
  2341. X    *value = strtol(str, NULL, 0);
  2342. X}
  2343. X
  2344. Xvoid
  2345. Xmain(ac, av)
  2346. X  int ac;
  2347. X  char *av[];
  2348. X{
  2349. X  XColor col;
  2350. X  XGCValues gcv;
  2351. X  int i, rows, len;
  2352. X
  2353. X  argv = (char **)calloc(ac+1, sizeof(char *));
  2354. X  for(i = 0; i < ac; i++)
  2355. X    argv[i] = strdup(av[i]);
  2356. X  xv_init(XV_INIT_ARGC_PTR_ARGV, &ac, av, NULL);
  2357. X
  2358. X/* X - Resources */
  2359. X  for(i = 0; opts[i].name; i++)
  2360. X    getdefault(opts[i].name, opts[i].param);
  2361. X  
  2362. X/* Argument parsing... */
  2363. X  for(av++; ac > 1; ac--, av++)
  2364. X    {
  2365. X      if(*av[0] != '-')
  2366. X        {
  2367. X      host = strdup(av[0]);
  2368. X      continue;
  2369. X    }
  2370. X      for(i = 0; opts[i].name; i++)
  2371. X        if(!strcmp(av[0]+1, opts[i].name))
  2372. X      {
  2373. X        if(opts[i].needsarg)
  2374. X          {
  2375. X        if(!av[1] || !*av[1])
  2376. X          {
  2377. X            fprintf(stderr, "%s: Option %s needs an argument\n", 
  2378. X                    PROGNAME, av[0]);
  2379. X            exit(-1);
  2380. X          }
  2381. X        if(*av[1] == '#')
  2382. X          *opts[i].param = strtol(av[1]+1, NULL, 16);
  2383. X        else
  2384. X          *opts[i].param = strtol(av[1], NULL, 0);
  2385. X        av++; ac--;
  2386. X          }
  2387. X        else
  2388. X          *opts[i].param = 1;
  2389. X        goto next;
  2390. X      }
  2391. X      if(!strcmp(av[0]+1, "a"))
  2392. X        {
  2393. X      for(i = 0; values[i].numvalues; i++)
  2394. X        if(!values[i].active)
  2395. X          values[i].active = ++nrcurr_active;
  2396. X      goto next;
  2397. X    }
  2398. X      for(i = 0; values[i].numvalues; i++)
  2399. X        if(!strcmp(av[0]+1, values[i].name))
  2400. X      {
  2401. X        if(!values[i].active)
  2402. X          values[i].active = ++nrcurr_active;
  2403. X        goto next;
  2404. X      }
  2405. X
  2406. X/* No valid option: print usage */
  2407. Xusage:
  2408. X      fprintf(stderr, "Usage: %s [-a]\n\t", PROGNAME);
  2409. X      for(len = 8,i = 0; opts[i].name; i++)
  2410. X        {
  2411. X      fprintf(stderr, "[-%s%s] ",opts[i].name,opts[i].needsarg?" <arg>":"");
  2412. X      len += strlen(opts[i].name) + 4 + (opts[i].needsarg ? 6 : 0);
  2413. X      if(len > 60)
  2414. X        {
  2415. X          fprintf(stderr, "\n\t");
  2416. X          len = 8;
  2417. X        }
  2418. X    }
  2419. X      for(i = 0; values[i].numvalues; i++)
  2420. X        {
  2421. X      fprintf(stderr, "[-%s] ", values[i].name);
  2422. X      len += strlen(values[i].name) + 4;
  2423. X      if(len > 60)
  2424. X        {
  2425. X          fprintf(stderr, "\n\t");
  2426. X          len = 8;
  2427. X        }
  2428. X    }
  2429. X      fprintf(stderr,
  2430. X                  "[host]\n\nKeyboard accelerators: a,q,s,o,1,?,NL\n");
  2431. X      exit(-1);
  2432. Xnext:
  2433. X      continue;
  2434. X    }
  2435. X
  2436. X  add_values = !noadd;
  2437. X  if(!host)
  2438. X    host = strdup("localhost");
  2439. X  if(!nrcurr_active)
  2440. X    {
  2441. X      nrcurr_active = 1;
  2442. X      values[0].active =1;
  2443. X    }
  2444. X  if(scrollback < 0) scrollback = 0;
  2445. X  if(sec_perpixel < 1) sec_perpixel = 1;
  2446. X  if(columns < 1) columns = 1;
  2447. X  if(columns > 10) columns = 10;
  2448. X  min_spp = sec_perpixel;
  2449. X  set_columns();
  2450. X
  2451. X  rows = (nrcurr_active + columns - 1) / columns;
  2452. X  fr = xv_create(0, FRAME,
  2453. X    FRAME_LABEL, PROGNAME,
  2454. X    XV_WIDTH,  (columns > 3 ? columns * 100 : columns * 200) + 3,
  2455. X    XV_HEIGHT, (rows > 3 ? rows * 60 : rows * 100) + 10,
  2456. X    FRAME_SHOW_FOOTER, FALSE,
  2457. X    FRAME_SHOW_RESIZE_CORNER, TRUE,
  2458. X    FRAME_SHOW_HEADER, FALSE,
  2459. X    NULL);
  2460. X
  2461. X  do_alarm(min_spp);
  2462. X
  2463. X  ca = xv_create(fr, CANVAS,
  2464. X    XV_X, 0, XV_Y, 0,
  2465. X    CANVAS_RETAINED,       FALSE,
  2466. X    CANVAS_AUTO_CLEAR,     FALSE,
  2467. X    CANVAS_AUTO_SHRINK,    TRUE,
  2468. X    CANVAS_AUTO_EXPAND,    TRUE,
  2469. X    NULL);
  2470. X  window_fit(fr);
  2471. X  xv_set(canvas_paint_window(ca),
  2472. X    WIN_EVENT_PROC, event_proc,
  2473. X    WIN_CONSUME_EVENTS,
  2474. X      WIN_ASCII_EVENTS, WIN_RESIZE, WIN_REPAINT,
  2475. X      WIN_MOUSE_BUTTONS, LOC_DRAG, NULL,
  2476. X    NULL);
  2477. X
  2478. X  dpy = (Display *)xv_get(fr, XV_DISPLAY);
  2479. X  win = xv_get(canvas_paint_window(ca), XV_XID);
  2480. X  screen = xv_get(xv_get(fr, XV_SCREEN), SCREEN_NUMBER);
  2481. X  font = xv_get(fr, XV_FONT);
  2482. X  font_info =(XFontStruct *)xv_get(font, FONT_INFO);
  2483. X#if 0
  2484. X  /* Returns -66+4 for the 5x7 :-( */
  2485. X  fontheight = xv_get(font, FONT_SIZE) + 4;
  2486. X#else
  2487. X  {
  2488. X    int dm, as, ds;
  2489. X    XCharStruct ov;
  2490. X
  2491. X    XTextExtents(font_info, "Cpgf", 4, &dm, &as, &ds, &ov);
  2492. X    fontheight = as+ds+4;
  2493. X  }
  2494. X#endif
  2495. X
  2496. X/* ICON */
  2497. X  {
  2498. X    Pixmap pm;
  2499. X    Server_image sim;
  2500. X    Icon icon;
  2501. X
  2502. X    pm = XCreatePixmapFromBitmapData(dpy, win,
  2503. X       icon_bits, icon_width, icon_height, 0, 1, 1);
  2504. X    sim = (Server_image)xv_create(0,
  2505. X       SERVER_IMAGE, SERVER_IMAGE_PIXMAP, pm, NULL);
  2506. X    icon = xv_create(fr, ICON, XV_WIDTH, icon_width, XV_HEIGHT, icon_height,
  2507. X       ICON_IMAGE, sim, ICON_MASK_IMAGE, sim, NULL);
  2508. X    xv_set(fr, FRAME_ICON, icon, NULL);
  2509. X  }
  2510. X
  2511. X  defidx[0] = defidx[1] = defidx[2] = defidx[3] = 
  2512. X                      defidx[BLACK] = BlackPixel(dpy, screen);
  2513. X  defidx[WHITE] = WhitePixel(dpy, screen);
  2514. X
  2515. X  if((depth = xv_get(fr, XV_DEPTH)) > 1)
  2516. X    {
  2517. X      col.flags = DoRed|DoGreen|DoBlue;
  2518. X
  2519. X      for(i = 0; i < NUMCOLS; i++)
  2520. X    {
  2521. X      col.pixel = BlackPixel(dpy, screen);
  2522. X      col.red   = (defcol[i] & 0xff0000) >> 8;
  2523. X      col.green = (defcol[i] & 0x00ff00);
  2524. X      col.blue  = (defcol[i] & 0x0000ff) << 8;
  2525. X      XAllocColor(dpy, DefaultColormap(dpy, screen), &col);
  2526. X      defidx[i] = col.pixel;
  2527. X    }
  2528. X    }
  2529. X  gcv.foreground = defidx[WHITE];
  2530. X  wingc = XCreateGC(dpy, win, GCForeground,&gcv);
  2531. X  gcv.foreground = defidx[BLACK];
  2532. X  bwingc = XCreateGC(dpy, win, GCForeground,&gcv);
  2533. X
  2534. X  if(!draw_line && depth == 1)
  2535. X    draw_one = 1;
  2536. X
  2537. X  xv_main_loop(fr);
  2538. X}
  2539. END_OF_FILE
  2540. if test 41015 -ne `wc -c <'perf/perf.c'`; then
  2541.     echo shar: \"'perf/perf.c'\" unpacked with wrong size!
  2542. fi
  2543. # end of 'perf/perf.c'
  2544. fi
  2545. if test -f 'perf/rstattest.c' -a "${1}" != "-c" ; then 
  2546.   echo shar: Will not clobber existing file \"'perf/rstattest.c'\"
  2547. else
  2548. echo shar: Extracting \"'perf/rstattest.c'\" \(988 characters\)
  2549. sed "s/^X//" >'perf/rstattest.c' <<'END_OF_FILE'
  2550. X/* Copyright (c) 1993 by Rudolf Koenig */
  2551. X#include <rpc/rpc.h>
  2552. X#include <rpcsvc/rstat.h>
  2553. X#include <stdio.h>
  2554. X
  2555. Xmain(ac, av)
  2556. X  int ac;
  2557. X  char *av[];
  2558. X{
  2559. X  struct statstime sx;
  2560. X
  2561. X  if(ac != 2)
  2562. X    exit(0);
  2563. X  for(;;)
  2564. X    {
  2565. X      if(rstat(av[1], &sx))
  2566. X    {
  2567. X      printf("No rstat...\n");
  2568. X      exit(0);
  2569. X    }
  2570. X
  2571. X      printf("cp_time: %d %d %d %d\n",
  2572. X    sx.cp_time[0], sx.cp_time[1], sx.cp_time[2], sx.cp_time[3]);
  2573. X      printf("dk_xfer: %d %d %d %d\n",
  2574. X    sx.dk_xfer[0], sx.dk_xfer[1], sx.dk_xfer[2], sx.dk_xfer[3]);
  2575. X      printf("pgin: %u, pgout %u, pswpin %u pswpout %u, intr %u\n",
  2576. X    sx.v_pgpgin,sx.v_pgpgout,
  2577. X    sx.v_pswpin,sx.v_pswpout,
  2578. X    sx.v_intr);
  2579. X      printf("ipack: %d, opack %d, ierr %d oerr %d, collis %d\n",
  2580. X    sx.if_ipackets,sx.if_opackets,
  2581. X    sx.if_ierrors,sx.if_oerrors,
  2582. X    sx.if_collisions);
  2583. X      printf("avg: %g %g %g\n", 
  2584. X    (double)sx.avenrun[0] / 256,
  2585. X    (double)sx.avenrun[1] / 256,
  2586. X    (double)sx.avenrun[2] / 256);
  2587. X      printf("context: %d\n", sx.v_swtch);
  2588. X      fflush(stdout);
  2589. X      sleep(1);
  2590. X    }
  2591. X}
  2592. END_OF_FILE
  2593. if test 988 -ne `wc -c <'perf/rstattest.c'`; then
  2594.     echo shar: \"'perf/rstattest.c'\" unpacked with wrong size!
  2595. fi
  2596. # end of 'perf/rstattest.c'
  2597. fi
  2598. echo shar: End of shell archive.
  2599. exit 0
  2600.  
  2601. exit 0 # Just in case...
  2602. -- 
  2603.   // chris@Sterling.COM           | Send comp.sources.x submissions to:
  2604. \X/  Amiga: The only way to fly!  |    sources-x@sterling.com
  2605.        "It's intuitively obvious to the most casual observer..."
  2606.  GCS d++(--) -p+ c++ !l u++ e+ m+(-) s++/++ n h--- f+ g+++ w+ t++ r+ y+
  2607.