summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2025-08-10 11:37:52 -0700
committerVito Caputo <vcaputo@pengaru.com>2025-09-11 21:21:44 -0700
commit733fa3c2722a2c59d3e5a27b8becf19a86caf302 (patch)
tree14b49827ff7a70e38c3036c5211104f5b6b61d06 /src
parented683c9966edc3522aec958bdb40e8ff8a20287f (diff)
vcr: make vcr_draw_bar() base explicit parameter
Get rid of the overloaded meaning of negative values indicating base. While here also put the min_height logic in charts, the vcr side of this should be more dumb mechanism and less policy. While here these pixel space scaled heights should really get rounded to the nearest int in the scaled float->int conversion, otherwise 13.9 height becomes 13 when it should clearly be 14.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/charts.c26
-rw-r--r--src/vcr.c27
-rw-r--r--src/vcr.h8
4 files changed, 41 insertions, 24 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index a8d1035..915ae6a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,7 +2,7 @@ SUBDIRS = libvmon
bin_PROGRAMS = vmon
vmon_SOURCES = ascii.c charts.c vcr.c vmon.c ascii.h charts.h vcr.h
-vmon_LDADD = libvmon/libvmon.a
+vmon_LDADD = libvmon/libvmon.a -lm
vmon_CPPFLAGS = -O2
if HAVE_XCLIENT_DEV
@@ -21,6 +21,6 @@ if ENABLE_VWM
bin_PROGRAMS += vwm
vwm_SOURCES = ascii.c clickety.c composite.c context.c desktop.c key.c launch.c logo.c charts.c screen.c vcr.c vwm.c window.c xevent.c xserver.c xwindow.c ascii.h clickety.h composite.h context.h desktop.h direction.h key.h launch.h list.h logo.h charts.h screen.h util.h vcr.h vwm.h window.h xevent.h xserver.h xwindow.h colors.def context_colors.def launchers.def
-vwm_LDADD = @XWM_DEV_LIBS@ libvmon/libvmon.a
+vwm_LDADD = @XWM_DEV_LIBS@ libvmon/libvmon.a -lm
vwm_CPPFLAGS = @XWM_DEV_CFLAGS@ -DUSE_XLIB
endif
diff --git a/src/charts.c b/src/charts.c
index da74400..5d52d0d 100644
--- a/src/charts.c
+++ b/src/charts.c
@@ -409,16 +409,30 @@ static int proc_hierarchy_changed(vmon_proc_t *proc)
/* helper for drawing the vertical bars in the graph layers */
static void draw_bars(vwm_charts_t *charts, vwm_chart_t *chart, int row, float mult, float a_fraction, float inv_a_total, vcr_layer_t a_layer, float b_fraction, float inv_b_total, vcr_layer_t b_layer)
{
+ int a_height, b_height;
float a_t, b_t;
/* compute the bar %ages for this sample */
a_t = a_fraction * inv_a_total * mult;
+ if (a_t > 1.f)
+ a_t = 1.f;
+
b_t = b_fraction * inv_b_total * mult;
+ if (b_t > 1.f)
+ b_t = 1.f;
/* ensure at least 1 pixel when the scaled result is a fraction less than 1,
* I want to at least see 1 pixel blips for the slightest cpu utilization */
- vcr_draw_bar(chart->vcr, a_layer, row, a_t, a_fraction != 0 ? 1 : 0 /* min_height */);
- vcr_draw_bar(chart->vcr, b_layer, row, b_t, b_fraction != 0 ? 1 : 0 /* min_height */);
+ a_height = rintf(a_t * (float)(VCR_ROW_HEIGHT - 1));
+ if (a_height == 0 && a_fraction != 0.f)
+ a_height = 1;
+
+ b_height = rintf(b_t * (float)(VCR_ROW_HEIGHT - 1));
+ if (b_height == 0 && b_fraction != 0.f)
+ b_height = 1;
+
+ vcr_draw_bar(chart->vcr, a_layer, VCR_BAR_BASE_TOP, row, a_height);
+ vcr_draw_bar(chart->vcr, b_layer, VCR_BAR_BASE_BOTTOM, row, b_height);
}
@@ -1069,7 +1083,7 @@ static void draw_chart_rest(vwm_charts_t *charts, vwm_chart_t *chart, vmon_proc_
draw_bars(charts, chart, *row,
(proc->is_thread || !proc->is_threaded) ? charts->vmon.num_cpus : 1.f /* mult */,
- -stime_delta,
+ stime_delta,
charts->inv_total_delta,
VCR_LAYER_GRAPHA,
utime_delta,
@@ -1111,7 +1125,7 @@ static void draw_chart(vwm_charts_t *charts, vwm_chart_t *chart, vmon_proc_t *pr
/* IOWait and Idle % @ row 0 */
draw_bars(charts, chart, row,
1.f /* mult */,
- -charts->iowait_delta,
+ charts->iowait_delta,
charts->inv_total_delta,
VCR_LAYER_GRAPHA,
charts->idle_delta,
@@ -1121,7 +1135,7 @@ static void draw_chart(vwm_charts_t *charts, vwm_chart_t *chart, vmon_proc_t *pr
/* IRQ and SoftIRQ % @ row 1 */
draw_bars(charts, chart, row + 1,
1.f /* mult */,
- -charts->irq_delta,
+ charts->irq_delta,
charts->inv_total_delta,
VCR_LAYER_GRAPHA,
charts->softirq_delta,
@@ -1131,7 +1145,7 @@ static void draw_chart(vwm_charts_t *charts, vwm_chart_t *chart, vmon_proc_t *pr
/* "Adherence" @ row 2 */
draw_bars(charts, chart, row + 2,
1.f /* mult */,
- charts->this_sample_adherence > 0.f ? -charts->this_sample_adherence : 0.f /* a_fraction */,
+ charts->this_sample_adherence > 0.f ? charts->this_sample_adherence : 0.f /* a_fraction */,
1.f /* inv_a_total */,
VCR_LAYER_GRAPHA,
charts->this_sample_adherence < 0.f ? -charts->this_sample_adherence : 0.f /* b_fraction */,
diff --git a/src/vcr.c b/src/vcr.c
index 20f726a..5406a9d 100644
--- a/src/vcr.c
+++ b/src/vcr.c
@@ -1195,35 +1195,32 @@ void vcr_mark_finish_line(vcr_t *vcr, vcr_layer_t layer, int row)
}
-/* draw a bar at the current phase into the specified layer of t % with a minimum of min_height pixels.
+/* draw a bar at the current phase into the specified layer of height pixels
*
* the only layers supported right now are grapha/graphb
*/
-void vcr_draw_bar(vcr_t *vcr, vcr_layer_t layer, int row, float t, int min_height)
+void vcr_draw_bar(vcr_t *vcr, vcr_layer_t layer, vcr_bar_base_t base, int row, int height)
{
- int height, y = row * VCR_ROW_HEIGHT;
+ int y = row * VCR_ROW_HEIGHT;
assert(vcr);
assert(vcr->backend);
assert(row >= 0);
assert(layer == VCR_LAYER_GRAPHA || layer == VCR_LAYER_GRAPHB);
- assert(min_height >= 0 && min_height < (VCR_ROW_HEIGHT - 1));
+ assert(height >= 0 && height < VCR_ROW_HEIGHT);
if ((row + 1) * VCR_ROW_HEIGHT >= vcr->height)
return;
- height = fabsf(t) * (float)(VCR_ROW_HEIGHT - 1);
-
- if (height < min_height)
- height = min_height;
-
- /* clamp the height to not potentially overflow */
- if (height > (VCR_ROW_HEIGHT - 1))
- height = (VCR_ROW_HEIGHT - 1);
-
- /* negative values project down from the top, positive up from bottom */
- if (t > 0.f)
+ switch (base) {
+ case VCR_BAR_BASE_BOTTOM:
y += VCR_ROW_HEIGHT - height - 1;
+ break;
+ case VCR_BAR_BASE_TOP:
+ break;
+ default:
+ assert(0);
+ }
switch (vcr->backend->type) {
#ifdef USE_XLIB
diff --git a/src/vcr.h b/src/vcr.h
index 31c7dc6..612ac23 100644
--- a/src/vcr.h
+++ b/src/vcr.h
@@ -38,6 +38,12 @@ typedef enum vcr_layer_t {
VCR_LAYER_CNT,
} vcr_layer_t;
+typedef enum vcr_bar_base_t {
+ VCR_BAR_BASE_BOTTOM,
+ VCR_BAR_BASE_TOP,
+ VCR_BAR_BASE_CNT
+} vcr_bar_base_t;
+
typedef struct vcr_backend_t vcr_backend_t;
typedef struct vcr_dest_t vcr_dest_t;
typedef struct vcr_t vcr_t;
@@ -69,7 +75,7 @@ int vcr_resize_visible(vcr_t *vcr, int width, int height);
void vcr_draw_text(vcr_t *vcr, vcr_layer_t layer, int x, int row, const vcr_str_t *strs, int n_strs, int *res_width);
void vcr_draw_ortho_line(vcr_t *vcr, vcr_layer_t layer, int x1, int y1, int x2, int y2);
void vcr_mark_finish_line(vcr_t *vcr, vcr_layer_t layer, int row);
-void vcr_draw_bar(vcr_t *vcr, vcr_layer_t layer, int row, float t, int min_height);
+void vcr_draw_bar(vcr_t *vcr, vcr_layer_t layer, vcr_bar_base_t base, int row, int height);
void vcr_clear_row(vcr_t *vcr, vcr_layer_t layer, int row, int x, int width);
void vcr_shift_below_row_up_one(vcr_t *vcr, int row);
void vcr_shift_below_row_down_one(vcr_t *vcr, int row);
© All Rights Reserved