Common Lisp Package: COM.INFORMATIMAGO.CLMISC.RESOURCE-UTILIZATION

Gather resource utilization statistics and report them. Usage: (reporting-sru (:job-origin (remote-client) :stream (remote-stream)) (do-something-lengthy)) (reporting-sru (:job-origin (remote-client) :stream (remote-stream) :report-to (lambda (cpu-time sys-time device-i/o paging-i/o job-origin &key (stream t)) (SUMMARY-RESOURCE-UTILIZATION cpu-time sys-time device-i/o paging-i/o job-origin :stream stream))) (do-something-lengthy)) Example: (reporting-sru (:job-origin "REPL") (asdf-load :com.informatimago.clext)) prints: Summary of resource utilization ------------------------------- CPU time: 0.300 sec Device I/O: 175 Overhead CPU: 0.012 sec Paging I/O: 1 CPU model: AMD Athlon(tm) Processor 6.4.2 1200.303 MHz (2402.66 bogomips) Job origin: REPL License: AGPL3 Copyright Pascal Bourguignon 2006 - 2012 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>

README:

FUNCTION

Public

SUMMARY-RESOURCE-UTILIZATION (CPU-TIME SYS-TIME DEVICE-I/O PAGING-I/O JOB-ORIGIN &KEY (STREAM T))

DO: Reports resource utilisaty summary. CPU-TIME: CPU time used, in seconds. SYS-TIME: System time used, in seconds. DEVICE-I/O: Number of Disk I/O. PAGING-I/O: Number of Swap I/O. JOB-ORIGIN: Label of the originator of the job. STREAM: Output stream (the default T means *standard-output*).

Private

CPU-INFO

RETURN: An A-list containing the data from /proc/cpuinfo.

CPU-SHORT-DESCRIPTION

RETURN: A short description of the CPU.

DEVICE-I/O

RETURN: The number of disk I/O collected by (DISK-STATISTICS).

DISK-STATISTICS (&OPTIONAL DISK)

RETURN: Statistics from the DISK usage, obtained from /proc/diskstats.

PROCESS-STATUS (&OPTIONAL (PID self))

PID: Normally it's a small integer, pid_t number. But for /proc/, we can also use ''self'', as in '/proc/self/stat'. RETURN: The status of the specified process.

READ-PARENTHESIZED-STRING (&OPTIONAL (STREAM T) (EOF-ERROR-P T) (EOF-VALUE NIL) (RECURSIVE-P NIL))

DO: Skip spaces, and read a string in parentheses (like in Postscript). RETURN: The string read (without the external parentheses), or the EOF-VALUE if EOF occured and EOF-ERROR-P is NIL. NIL is returned if the next non whitespace character is not a left parenthesis. NOTE: Parentheses inside the string must be escaped by unless balanced.

Undocumented

TEST/READ-PARENTHESIZED-STRING

MACRO

Public

REPORTING-SRU ((&KEY (JOB-ORIGIN '(SHORT-SITE-NAME)) (STREAM T) (REPORT-TO NIL REPORT-TO-P)) &BODY BODY)

DO: Execute the BODY collecting resource usage statistics, and finally reporting them. JOB-ORIGIN: Label of the originator of the job; defaults to (SHORT-SITE-NAME). STREAM: Output stream (the default T means *standard-output*). REPORT-TO: If provided, it's a function with the same signature as SUMMARY-RESOURCE-UTILIZATION, ie.: (cpu-time sys-time device-i/o paging-i/o job-origin &key (stream t)) which is called to report the collected statistics. The default is SUMMARY-RESOURCE-UTILIZATION.

VARIABLE

Private

*JIFFY*

The JIFFY value of the Linux kernel (1/CONFIG_HZ)