summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2024-07-11 21:48:37 -0700
committerVito Caputo <vcaputo@pengaru.com>2024-07-11 21:48:37 -0700
commit76858370c14fab315032651697a70f948952686c (patch)
treef5da41a43144da253208be79ebaf23c369479390
parent63f6dd6ecc163f69e609501c426f64054bda1aa3 (diff)
vmon: introduce --snapshots flag
Takes a number of seconds interval argument, arranges for an interval timer to trigger the sigusr1 handler which causes a snapshot to be generated. e.g. `./vmon --snapshots 1` will produce a .png per second
-rw-r--r--src/vmon.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/vmon.c b/src/vmon.c
index ed4d433..3300112 100644
--- a/src/vmon.c
+++ b/src/vmon.c
@@ -27,6 +27,7 @@
#include <sys/prctl.h>
#include <time.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -50,6 +51,7 @@ typedef struct vmon_t {
int done;
int linger;
time_t start_time;
+ int snapshots_interval;
int snapshot;
char *output_dir;
char *name;
@@ -181,9 +183,9 @@ static void print_help(void)
{
puts(
"\n"
- "-----------------------------------------------------------------------------\n"
+ "-------------------------------------------------------------------------------\n"
" Flag Description\n"
- "-----------------------------------------------------------------------------\n"
+ "-------------------------------------------------------------------------------\n"
" -- Sentinel, subsequent arguments form command to execute\n"
" -f --fullscreen Fullscreen window\n"
" -h --help Show this help\n"
@@ -192,11 +194,12 @@ static void print_help(void)
" -n --name Name of chart, shows in window title and output filenames\n"
" -o --output-dir Directory to store saved output to (\".\" if unspecified)\n"
" -p --pid PID of the top-level process to monitor (1 if unspecified)\n"
- " -s --snapshot Save a PNG snapshot upon receiving SIGCHLD (SIGUSR1 also triggers snapshots)\n"
+ " -i --snapshots Save a PNG snapshot every N seconds (SIGUSR1 also snapshots)\n"
+ " -s --snapshot Save a PNG snapshot upon receiving SIGCHLD\n"
" -v --version Print version\n"
" -W --width Window width\n"
" -z --hertz Sample rate in hertz\n"
- "-----------------------------------------------------------------------------"
+ "-------------------------------------------------------------------------------"
);
}
@@ -415,6 +418,11 @@ static int vmon_handle_argv(vmon_t *vmon, int argc, const char * const *argv)
return 0;
last = ++argv;
+ } else if (is_flag(*argv, "-i", "--snapshots")) {
+ if (!parse_flag_int(argv, end, argv + 1, 1, INT_MAX, &vmon->snapshots_interval))
+ return 0;
+
+ last = ++argv;
} else if (is_flag(*argv, "-s", "--snapshot")) {
vmon->snapshot = 1;
last = argv;
@@ -586,6 +594,25 @@ static vmon_t * vmon_startup(int argc, const char * const *argv)
goto _err_xserver;
}
+ if (signal(SIGALRM, handle_sigusr1) == SIG_ERR) {
+ VWM_PERROR("unable to set SIGALRM handler");
+ goto _err_xserver;
+ }
+
+ if (vmon->snapshots_interval) {
+ int r;
+
+ r = setitimer(ITIMER_REAL,
+ &(struct itimerval){
+ .it_interval.tv_sec = vmon->snapshots_interval,
+ .it_value.tv_sec = vmon->snapshots_interval,
+ }, NULL);
+ if (r < 0) {
+ VWM_PERROR("unable to set interval timer");
+ goto _err_xserver;
+ }
+ }
+
vmon->window = XCreateSimpleWindow(vmon->xserver->display, XSERVER_XROOT(vmon->xserver), 0, 0, vmon->width, vmon->height, 1, 0, 0);
if (vmon->name)
XStoreName(vmon->xserver->display, vmon->window, vmon->name);
© All Rights Reserved