From 8d4a95746c66bcebed01c2d8c0bbc16f4804bafb Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Wed, 20 Mar 2019 11:28:10 +0100 Subject: [PATCH] sadf: PCP: Add support for A_SWAP activity Add metrics displayed by "sar -W" (swapping statistics) to PCP archive. Signed-off-by: Sebastien GODARD --- activity.c | 1 + pcp_def_metrics.c | 18 ++++++++++++++++++ pcp_def_metrics.h | 1 + pcp_stats.c | 30 ++++++++++++++++++++++++++++++ pcp_stats.h | 2 ++ sadf_misc.c | 4 ++++ 6 files changed, 56 insertions(+) diff --git a/activity.c b/activity.c index 3a7a9b0..c992a4e 100644 --- a/activity.c +++ b/activity.c @@ -231,6 +231,7 @@ struct activity swap_act = { .f_json_print = json_print_swap_stats, .f_svg_print = svg_print_swap_stats, .f_raw_print = raw_print_swap_stats, + .f_pcp_print = pcp_print_swap_stats, .f_count_new = NULL, .item_list = NULL, .desc = "Swap activity", diff --git a/pcp_def_metrics.c b/pcp_def_metrics.c index 83b2e9c..24d2252 100644 --- a/pcp_def_metrics.c +++ b/pcp_def_metrics.c @@ -185,6 +185,24 @@ void pcp_def_irq_metrics(struct activity *a) #endif /* HAVE_PCP */ } +/* + *************************************************************************** + * Define PCP metrics for swapping statistics. + *************************************************************************** + */ +void pcp_def_swap_metrics(void) +{ +#ifdef HAVE_PCP + pmiAddMetric("swap.pagesin", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("swap.pagesout", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); +#endif /* HAVE_PCP */ +} + /* *************************************************************************** * Define PCP metrics for memory statistics. diff --git a/pcp_def_metrics.h b/pcp_def_metrics.h index a67993d..040b3af 100644 --- a/pcp_def_metrics.h +++ b/pcp_def_metrics.h @@ -15,6 +15,7 @@ void pcp_def_cpu_metrics(struct activity *); void pcp_def_pcsw_metrics(void); void pcp_def_irq_metrics(struct activity *); +void pcp_def_swap_metrics(void); void pcp_def_memory_metrics(struct activity *); void pcp_def_queue_metrics(void); diff --git a/pcp_stats.c b/pcp_stats.c index 8cac066..d71602b 100644 --- a/pcp_stats.c +++ b/pcp_stats.c @@ -237,6 +237,36 @@ __print_funct_t pcp_print_irq_stats(struct activity *a, int curr, unsigned long #endif /* HAVE_PCP */ } +/* + *************************************************************************** + * Display swapping statistics in PCP format. + * + * IN: + * @a Activity structure with statistics. + * @curr Index in array for current sample statistics. + * @itv Interval of time in 1/100th of a second. + * @record_hdr Record header for current sample. + *************************************************************************** + */ +__print_funct_t pcp_print_swap_stats(struct activity *a, int curr, unsigned long long itv, + struct record_header *record_hdr) +{ +#ifdef HAVE_PCP + char buf[64]; + struct stats_swap + *ssc = (struct stats_swap *) a->buf[curr], + *ssp = (struct stats_swap *) a->buf[!curr]; + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(ssp->pswpin, ssc->pswpin, itv)); + pmiPutValue("swap.pagesin", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(ssp->pswpout, ssc->pswpout, itv)); + pmiPutValue("swap.pagesout", NULL, buf); +#endif /* HAVE_PCP */ +} + /* *************************************************************************** * Display memory statistics in PCP format. diff --git a/pcp_stats.h b/pcp_stats.h index 0ab592f..36f3679 100644 --- a/pcp_stats.h +++ b/pcp_stats.h @@ -19,6 +19,8 @@ __print_funct_t pcp_print_pcsw_stats (struct activity *, int, unsigned long long, struct record_header *); __print_funct_t pcp_print_irq_stats (struct activity *, int, unsigned long long, struct record_header *); +__print_funct_t pcp_print_swap_stats + (struct activity *, int, unsigned long long, struct record_header *); __print_funct_t pcp_print_memory_stats (struct activity *, int, unsigned long long, struct record_header *); __print_funct_t pcp_print_queue_stats diff --git a/sadf_misc.c b/sadf_misc.c index b0e60c7..a0c3176 100644 --- a/sadf_misc.c +++ b/sadf_misc.c @@ -509,6 +509,10 @@ __printf_funct_t print_pcp_statistics(int *tab, int action, struct activity *act pcp_def_irq_metrics(act[p]); break; + case A_SWAP: + pcp_def_swap_metrics(); + break; + case A_MEMORY: pcp_def_memory_metrics(act[p]); break; -- 2.49.0