Skip to content

Commit c6bad09

Browse files
tallpsmithclaude
andcommitted
pmstat: add -C/--compact mode to hide unavailable metrics
This change adds optional dynamic column hiding to pmstat, allowing it to automatically suppress columns for metrics that are unavailable on the current platform. This is particularly useful for macOS and other platforms where some Linux-specific metrics (like swap in/out, buffer memory, etc.) don't exist. Instead of showing "?" for missing values, the columns are simply not displayed. Usage: pmstat # Default: show all columns (original behavior) pmstat -C # Compact: hide unavailable metric columns Note: This commit is part of separating cross-platform tool improvements from platform-specific PMDA enhancements. Darwin PMDA swap metrics have been split into a separate PR for the macOS-specific enhancement branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 82b1752 commit c6bad09

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/pmstat/pmstat.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ pmLongOptions longopts[] = {
113113
PMOPT_HOSTSFILE,
114114
PMOPT_LOCALPMDA,
115115
PMAPI_OPTIONS_HEADER("Reporting options"),
116+
{ "compact", 0, 'C', 0, "suppress columns for unavailable metrics" },
116117
{ "suffix", 0, 'l', 0, "print last 7 charcters of the host name(s)" },
117118
{ "pause", 0, 'P', 0, "pause between updates for archive replay" },
118119
{ "xcpu", 0, 'x', 0, "extended CPU statistics reporting" },
@@ -121,11 +122,12 @@ pmLongOptions longopts[] = {
121122

122123
pmOptions opts = {
123124
.flags = PM_OPTFLAG_MULTI | PM_OPTFLAG_BOUNDARIES | PM_OPTFLAG_STDOUT_TZ,
124-
.short_options = PMAPI_OPTIONS "H:LlPx",
125+
.short_options = PMAPI_OPTIONS "CH:LlPx",
125126
.long_options = longopts,
126127
};
127128

128129
static int extraCpuStats;
130+
static int compactMode;
129131
static char swapOp = 'p';
130132
static int rows = 21;
131133
static int header;
@@ -436,7 +438,25 @@ detectColumnAvailability(struct statsrc **ctxList, int ctxCount)
436438
/* Start optimistic - assume all columns available */
437439
memset(&display, 1, sizeof(display));
438440

439-
/* Check each context */
441+
/*
442+
* If not in compact mode, show all columns regardless of availability.
443+
* Unavailable metrics will be displayed as "?" in the output.
444+
*/
445+
if (!compactMode) {
446+
/* Set all group visibility to show all groups */
447+
for (i = 0; i < NUM_COL_GROUPS; i++)
448+
display.show_group[i] = 1;
449+
450+
/* Verbose reporting - only if debugging enabled */
451+
if (pmDebugOptions.appl0)
452+
reportAvailabilityDiagnostics();
453+
return;
454+
}
455+
456+
/*
457+
* Compact mode: analyze availability and suppress unavailable columns.
458+
* Check each context and mark columns unavailable if ANY context lacks them.
459+
*/
440460
for (i = 0; i < ctxCount; i++) {
441461
struct statsrc *s = ctxList[i];
442462

@@ -766,6 +786,9 @@ main(int argc, char *argv[])
766786

767787
while ((sts = pmGetOptions(argc, argv, &opts)) != EOF) {
768788
switch (sts) {
789+
case 'C': /* compact mode - suppress unavailable columns */
790+
compactMode = 1;
791+
break;
769792
case 'l': /* print last 7 characters of hostname(s) */
770793
printTail++;
771794
break;

0 commit comments

Comments
 (0)