Skip to content

Commit

Permalink
sadf: PCP: Add support for A_PWR_TEMP activity
Browse files Browse the repository at this point in the history
Add metrics displayed by "sar -m TEMP" (temperature statistics) to PCP
archive.

Signed-off-by: Sebastien GODARD <[email protected]>
  • Loading branch information
sysstat committed May 25, 2019
1 parent c5bfb2a commit 4a1a247
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 1 deletion.
1 change: 1 addition & 0 deletions activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,7 @@ struct activity pwr_temp_act = {
.f_json_print = json_print_pwr_temp_stats,
.f_svg_print = svg_print_pwr_temp_stats,
.f_raw_print = raw_print_pwr_temp_stats,
.f_pcp_print = pcp_print_pwr_temp_stats,
.f_count_new = NULL,
.item_list = NULL,
.desc = "Devices temperature",
Expand Down
39 changes: 39 additions & 0 deletions pcp_def_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,45 @@ void pcp_def_pwr_fan_metrics(struct activity *a)
#endif /* HAVE_PCP */
}

/*
***************************************************************************
* Define PCP metrics for temperature statistics.
*
* IN:
* @a Activity structure with statistics.
***************************************************************************
*/
void pcp_def_pwr_temp_metrics(struct activity *a)
{
#ifdef HAVE_PCP
int inst = 0;
static pmInDom indom = PM_INDOM_NULL;
char buf[16];

if (indom == PM_INDOM_NULL) {
/* Create domain */
indom = pmInDom_build(0, PM_INDOM_TEMP);

for (inst = 0; inst < a->item_list_sz; inst++) {
sprintf(buf, "temp%d", inst + 1);
pmiAddInstance(indom, buf, inst);
}
}

pmiAddMetric("power.temp.degC",
PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
pmiUnits(0, 0, 0, 0, 0, 0));

pmiAddMetric("power.temp.temp_pct",
PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
pmiUnits(0, 0, 0, 0, 0, 0));

pmiAddMetric("power.temp.device",
PM_IN_NULL, PM_TYPE_STRING, indom, PM_SEM_DISCRETE,
pmiUnits(0, 0, 0, 0, 0, 0));
#endif /* HAVE_PCP */
}

/*
***************************************************************************
* Define PCP metrics for USB devices statistics.
Expand Down
3 changes: 2 additions & 1 deletion pcp_def_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void pcp_def_net_eicmp6_metrics(void);
void pcp_def_net_udp6_metrics(void);
void pcp_def_huge_metrics(void);
void pcp_def_pwr_fan_metrics(struct activity *);
void pcp_def_pwr_temp_metrics(struct activity *);
void pcp_def_pwr_usb_metrics(struct activity *);
void pcp_def_filesystem_metrics(struct activity *);
void pcp_def_fchost_metrics(struct activity *);
Expand All @@ -57,6 +58,6 @@ void pcp_def_fchost_metrics(struct activity *);
#define PM_INDOM_USB 7
#define PM_INDOM_DISK 8
#define PM_INDOM_FAN 9

#define PM_INDOM_TEMP 10

#endif /* _PCP_DEF_METRICS_H */
41 changes: 41 additions & 0 deletions pcp_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,47 @@ __print_funct_t pcp_print_pwr_fan_stats(struct activity *a, int curr, unsigned l
#endif /* HAVE_PCP */
}

/*
***************************************************************************
* Display temperature 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_pwr_temp_stats(struct activity *a, int curr, unsigned long long itv,
struct record_header *record_hdr)
{
#ifdef HAVE_PCP
int i;
struct stats_pwr_temp *spc;
char buf[64], instance[32];

for (i = 0; i < a->nr[curr]; i++) {

spc = (struct stats_pwr_temp *) ((char *) a->buf[curr] + i * a->msize);
sprintf(instance, "temp%d", i + 1);

snprintf(buf, sizeof(buf), "%f",
spc->temp);
pmiPutValue("power.temp.degC", instance, buf);

snprintf(buf, sizeof(buf), "%f",
(spc->temp_max - spc->temp_min) ?
(spc->temp - spc->temp_min) / (spc->temp_max - spc->temp_min) * 100 :
0.0);
pmiPutValue("power.temp.temp_pct", instance, buf);

snprintf(buf, sizeof(buf), "%s",
spc->device);
pmiPutValue("power.temp.device", instance, buf);
}
#endif /* HAVE_PCP */
}

/*
***************************************************************************
* Display huge pages statistics in PCP format.
Expand Down
2 changes: 2 additions & 0 deletions pcp_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ __print_funct_t pcp_print_pwr_cpufreq_stats
(struct activity *, int, unsigned long long, struct record_header *);
__print_funct_t pcp_print_pwr_fan_stats
(struct activity *, int, unsigned long long, struct record_header *);
__print_funct_t pcp_print_pwr_temp_stats
(struct activity *, int, unsigned long long, struct record_header *);
__print_funct_t pcp_print_huge_stats
(struct activity *, int, unsigned long long, struct record_header *);
__print_funct_t pcp_print_pwr_usb_stats
Expand Down
4 changes: 4 additions & 0 deletions sadf_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,10 @@ __printf_funct_t print_pcp_statistics(int *tab, int action, struct activity *act
pcp_def_pwr_fan_metrics(act[p]);
break;

case A_PWR_TEMP:
pcp_def_pwr_temp_metrics(act[p]);
break;

case A_PWR_USB:
pcp_def_pwr_usb_metrics(act[p]);
break;
Expand Down

0 comments on commit 4a1a247

Please sign in to comment.