From 85e01f63720215de7bbd5cbf0515f1c4c0f28dcc Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Thu, 23 Feb 2023 11:23:53 +0100 Subject: [PATCH] Reduce variables scope when relevant Signed-off-by: Sebastien GODARD --- common.c | 9 +++++--- iostat.c | 17 +++++++++----- json_stats.c | 2 +- mpstat.c | 4 +++- pcp_def_metrics.c | 45 ++++++++++++++++++++++--------------- pidstat.c | 18 ++++++++++----- pr_stats.c | 3 ++- raw_stats.c | 5 +++-- rndr_stats.c | 4 ++-- sa_common.c | 19 +++++++--------- sa_conv.c | 9 ++++---- sadf_misc.c | 32 ++++++++++++++++----------- svg_stats.c | 56 ++++++++++++++++++++++++++++------------------- tapestat.c | 6 +++-- xml_stats.c | 2 +- 15 files changed, 138 insertions(+), 93 deletions(-) diff --git a/common.c b/common.c index f3a88b4..48493b5 100644 --- a/common.c +++ b/common.c @@ -138,9 +138,10 @@ time_t get_xtime(struct tm *rectime, int d_off, int utc) time_t get_time(struct tm *rectime, int d_off) { static int utc = 0; - char *e; if (!utc) { + char *e; + /* Read environment variable value once */ if ((e = __getenv(ENV_TIME_DEFTM)) != NULL) { utc = !strcmp(e, K_UTC); @@ -488,9 +489,10 @@ unsigned int get_devmap_major(void) int is_iso_time_fmt(void) { static int is_iso = -1; - char *e; if (is_iso < 0) { + char *e; + is_iso = (((e = __getenv(ENV_TIME_FMT)) != NULL) && !strcmp(e, K_ISO)); } return is_iso; @@ -1134,7 +1136,6 @@ char *get_device_name(unsigned int major, unsigned int minor, unsigned long long static unsigned int dm_major = 0; char *dev_name = NULL, *persist_dev_name = NULL, *bang; static char sid[64], dname[MAX_NAME_LEN]; - char xsid[32] = "", pn[16] = ""; if (disp_persist_name) { persist_dev_name = get_persistent_name_from_pretty(get_devname(major, minor)); @@ -1145,6 +1146,8 @@ char *get_device_name(unsigned int major, unsigned int minor, unsigned long long } else { if (use_stable_id && (wwn[0] != 0)) { + char xsid[32] = "", pn[16] = ""; + if (wwn[1] != 0) { sprintf(xsid, "%016llx", wwn[1]); } diff --git a/iostat.c b/iostat.c index 15bcbbc..89aae34 100644 --- a/iostat.c +++ b/iostat.c @@ -292,8 +292,7 @@ struct io_device *add_list_device(struct io_device **dlist, char *name, int dtyp int major, int minor) { struct io_device *d, *ds; - int i, rc = 0, maj_nr, min_nr; - char *dm_name; + int i, maj_nr, min_nr; if (strnlen(name, MAX_NAME_LEN) == MAX_NAME_LEN) /* Device name is too long */ @@ -341,6 +340,8 @@ struct io_device *add_list_device(struct io_device **dlist, char *name, int dtyp memset(d->dev_stats[i], 0, sizeof(struct io_stats)); } if (DISPLAY_DEVMAP_NAME(flags)) { + char *dm_name; + /* * Save device mapper name (e.g. "dm-0") instead of * its registered name (e.g. "virtualhd-home") @@ -365,6 +366,8 @@ struct io_device *add_list_device(struct io_device **dlist, char *name, int dtyp d->dev_tp = dtype; } else { + int rc = 0; + if (!alt_dir[0] || USE_ALL_DIR(flags)) { rc = is_device(SLASH_SYS, name, ACCEPT_VIRTUAL_DEVICES); } @@ -667,7 +670,6 @@ int read_sysfs_all_devices_stat_work(int curr, char *sysblock) int read_sysfs_all_devices_stat(int curr) { int rc = 0; - char sysblock[MAX_PF_NAME]; if (!alt_dir[0] || USE_ALL_DIR(flags)) { /* Read all whole devices from /sys */ @@ -675,6 +677,8 @@ int read_sysfs_all_devices_stat(int curr) } if (alt_dir[0]) { + char sysblock[MAX_PF_NAME]; + snprintf(sysblock, sizeof(sysblock), "%s/%s", alt_dir, __BLOCK); sysblock[sizeof(sysblock) - 1] = '\0'; /* Read stats from an alternate sys location */ @@ -884,14 +888,14 @@ void read_diskstats_stat_work(int curr, char *diskstats) */ void read_diskstats_stat(int curr) { - char diskstats[MAX_PF_NAME]; - if (!alt_dir[0] || USE_ALL_DIR(flags)) { /* Read stats from /proc/diskstats */ read_diskstats_stat_work(curr, DISKSTATS); } if (alt_dir[0]) { + char diskstats[MAX_PF_NAME]; + snprintf(diskstats, sizeof(diskstats), "%s/%s", alt_dir, __DISKSTATS); diskstats[sizeof(diskstats) - 1] = '\0'; /* Read stats from an alternate diskstats file */ @@ -1355,7 +1359,6 @@ void write_json_ext_stat(int tab, unsigned long long itv, int fctr, struct ext_io_stats *xios) { int n; - char line[256]; /* If this is a group with no devices, skip it */ if (d->dev_tp == T_GROUP) @@ -1389,6 +1392,8 @@ void write_json_ext_stat(int tab, unsigned long long itv, int fctr, S_VALUE(ioj->rq_ticks, ioi->rq_ticks, itv) / 1000.0); } else { + char line[256]; + printf("\"r/s\": %.2f, \"w/s\": %.2f, \"d/s\": %.2f, \"f/s\": %.2f, ", S_VALUE(ioj->rd_ios, ioi->rd_ios, itv), S_VALUE(ioj->wr_ios, ioi->wr_ios, itv), diff --git a/json_stats.c b/json_stats.c index cbd5643..0ee3eb2 100644 --- a/json_stats.c +++ b/json_stats.c @@ -535,11 +535,11 @@ __print_funct_t json_print_memory_stats(struct activity *a, int curr, int tab, struct stats_memory *smc = (struct stats_memory *) a->buf[curr]; int sep = FALSE; - unsigned long long nousedmem; xprintf0(tab, "\"memory\": {"); if (DISPLAY_MEMORY(a->opt_flags)) { + unsigned long long nousedmem; sep = TRUE; diff --git a/mpstat.c b/mpstat.c index bddba41..4a2e8e8 100644 --- a/mpstat.c +++ b/mpstat.c @@ -1932,7 +1932,7 @@ void read_interrupts_stat(char *file, struct stats_irqcpu *st_ic[], int ic_nr, i void rw_mpstat_loop(int dis_hdr, int rows) { struct stats_cpu *scc; - int i, new_cpu_nr; + int new_cpu_nr; int curr = 1, dis = 1; unsigned long lines = rows; @@ -1946,6 +1946,8 @@ void rw_mpstat_loop(int dis_hdr, int rows) * read from /proc/stat for global CPU stats. */ if (cpu_nr > 1) { + int i; + memset(st_cpu[0], 0, STATS_CPU_SIZE); for (i = 1; i <= cpu_nr; i++) { diff --git a/pcp_def_metrics.c b/pcp_def_metrics.c index f4f41b6..8f89d0b 100644 --- a/pcp_def_metrics.c +++ b/pcp_def_metrics.c @@ -612,11 +612,12 @@ void pcp_def_queue_metrics(void) void pcp_def_disk_metrics(struct activity *a) { #ifdef HAVE_PCP - int inst = 0; static pmInDom indom = PM_INDOM_NULL; - struct sa_item *list = a->item_list; if (indom == PM_INDOM_NULL) { + int inst = 0; + struct sa_item *list = a->item_list; + /* Create domain */ indom = pmInDom_build(60, 1); @@ -692,11 +693,12 @@ void pcp_def_disk_metrics(struct activity *a) void pcp_def_net_dev_metrics(struct activity *a) { #ifdef HAVE_PCP - int inst = 0; static pmInDom indom = PM_INDOM_NULL; - struct sa_item *list = a->item_list; if (indom == PM_INDOM_NULL) { + int inst = 0; + struct sa_item *list = a->item_list; + /* Create domain */ indom = pmInDom_build(60, 3); @@ -1558,11 +1560,12 @@ void pcp_def_huge_metrics() void pcp_def_pwr_fan_metrics(struct activity *a) { #ifdef HAVE_PCP - int inst; static pmInDom indom = PM_INDOM_NULL; - char buf[16]; if (indom == PM_INDOM_NULL) { + int inst; + char buf[16]; + /* Create domain */ indom = pmInDom_build(34, 0); @@ -1597,11 +1600,12 @@ void pcp_def_pwr_fan_metrics(struct activity *a) void pcp_def_pwr_temp_metrics(struct activity *a) { #ifdef HAVE_PCP - int inst; static pmInDom indom = PM_INDOM_NULL; - char buf[16]; if (indom == PM_INDOM_NULL) { + int inst; + char buf[16]; + /* Create domain */ indom = pmInDom_build(34, 1); @@ -1636,11 +1640,12 @@ void pcp_def_pwr_temp_metrics(struct activity *a) void pcp_def_pwr_in_metrics(struct activity *a) { #ifdef HAVE_PCP - int inst; static pmInDom indom = PM_INDOM_NULL; - char buf[16]; if (indom == PM_INDOM_NULL) { + int inst; + char buf[16]; + /* Create domain */ indom = pmInDom_build(34, 2); @@ -1675,11 +1680,12 @@ void pcp_def_pwr_in_metrics(struct activity *a) void pcp_def_pwr_bat_metrics(struct activity *a) { #ifdef HAVE_PCP - int inst = 0; static pmInDom indom = PM_INDOM_NULL; - struct sa_item *list = a->item_list; if (indom == PM_INDOM_NULL) { + int inst = 0; + struct sa_item *list = a->item_list; + /* Create domain */ indom = pmInDom_build(34, 4); @@ -1711,11 +1717,12 @@ void pcp_def_pwr_bat_metrics(struct activity *a) void pcp_def_pwr_usb_metrics(struct activity *a) { #ifdef HAVE_PCP - int inst; static pmInDom indom = PM_INDOM_NULL; - char buf[16]; if (indom == PM_INDOM_NULL) { + int inst; + char buf[16]; + /* Create domain */ indom = pmInDom_build(34, 3); @@ -1762,11 +1769,12 @@ void pcp_def_pwr_usb_metrics(struct activity *a) void pcp_def_filesystem_metrics(struct activity *a) { #ifdef HAVE_PCP - int inst = 0; static pmInDom indom = PM_INDOM_NULL; - struct sa_item *list = a->item_list; if (indom == PM_INDOM_NULL) { + int inst = 0; + struct sa_item *list = a->item_list; + /* Create domain */ indom = pmInDom_build(60, 5); @@ -1822,11 +1830,12 @@ void pcp_def_filesystem_metrics(struct activity *a) void pcp_def_fchost_metrics(struct activity *a) { #ifdef HAVE_PCP - int inst = 0; static pmInDom indom = PM_INDOM_NULL; - struct sa_item *list = a->item_list; if (indom == PM_INDOM_NULL) { + int inst = 0; + struct sa_item *list = a->item_list; + /* Create domain */ indom = pmInDom_build(60, 39); diff --git a/pidstat.c b/pidstat.c index d550605..30b7cad 100644 --- a/pidstat.c +++ b/pidstat.c @@ -249,7 +249,6 @@ struct st_pid *add_list_pid(struct st_pid **plist, pid_t pid, pid_t tgid) { struct st_pid *p, *ps, *tgid_p = NULL; int i; - int tgid_found = FALSE; if (!pid) return NULL; @@ -275,6 +274,8 @@ struct st_pid *add_list_pid(struct st_pid **plist, pid_t pid, pid_t tgid) } } else { + int tgid_found = FALSE; + /* * PID is a TID. * It will be inserted in ascending order immediately @@ -505,7 +506,7 @@ int read_proc_pid_stat(pid_t pid, struct st_pid *plist, */ int read_proc_pid_sched(pid_t pid, struct st_pid *plist, pid_t tgid, int curr) { - int fd, sz, rc = 0; + int fd, rc = 0; char filename[128]; static char buffer[1024 + 1]; unsigned long long wtime = 0; @@ -519,6 +520,8 @@ int read_proc_pid_sched(pid_t pid, struct st_pid *plist, pid_t tgid, int curr) } if ((fd = open(filename, O_RDONLY)) >= 0) { + int sz; + /* schedstat file found for process */ sz = read(fd, buffer, 1024); close(fd); @@ -671,7 +674,7 @@ int read_proc_pid_cmdline(pid_t pid, struct st_pid *plist, pid_t tgid) FILE *fp; char filename[128], line[MAX_CMDLINE_LEN]; size_t len; - int i, found = FALSE; + int found = FALSE; if (tgid) { sprintf(filename, TASK_CMDLINE, tgid, pid); @@ -690,6 +693,8 @@ int read_proc_pid_cmdline(pid_t pid, struct st_pid *plist, pid_t tgid) fclose(fp); if (len) { + int i; + for (i = len - 2; i >= 0; i--) { if (line[i]) { found = TRUE; @@ -931,8 +936,6 @@ void read_task_stats(pid_t pid, struct st_pid *plist, int curr) */ void read_stats(int curr) { - DIR *dir; - struct dirent *drp; unsigned int thr_nr; pid_t pid; struct st_pid *plist; @@ -961,6 +964,8 @@ void read_stats(int curr) free(st_cpu); if (DISPLAY_ALL_PID(pidflag)) { + DIR *dir; + struct dirent *drp; /* Open /proc directory */ if ((dir = __opendir(PROC)) == NULL) { @@ -1059,7 +1064,6 @@ int get_pid_to_display(int prev, int curr, unsigned int activity, unsigned int p int rc; char *pc; regex_t regex; - struct passwd *pwdent; struct pid_stats *pstc = plist->pstats[curr], *pstp = plist->pstats[prev]; if (!plist->exist) @@ -1204,6 +1208,8 @@ int get_pid_to_display(int prev, int curr, unsigned int activity, unsigned int p } if (USER_STRING(pidflag)) { + struct passwd *pwdent; + if ((pwdent = __getpwuid(plist->uid)) != NULL) { if (strcmp(pwdent->pw_name, userstr)) /* This PID doesn't belong to user */ diff --git a/pr_stats.c b/pr_stats.c index 71790b0..514c6db 100644 --- a/pr_stats.c +++ b/pr_stats.c @@ -573,7 +573,6 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr, int dispavg avg_tlskb = 0, avg_caskb = 0; int unit = NO_UNIT; - unsigned long long nousedmem; if (DISPLAY_UNIT(flags)) { /* Default values unit is kB */ @@ -581,6 +580,8 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr, int dispavg } if (DISPLAY_MEMORY(a->opt_flags)) { + unsigned long long nousedmem; + if (dish) { print_hdr_line(timestamp[!curr], a, FIRST, 0, 9, NULL); } diff --git a/raw_stats.c b/raw_stats.c index 62ed06c..1469ec8 100644 --- a/raw_stats.c +++ b/raw_stats.c @@ -49,14 +49,15 @@ extern char bat_status[][16]; */ char *pfield(char *hdr_line, int pos) { - char hline[HEADER_LINE_LEN] = ""; static char field[HEADER_LINE_LEN] = ""; static char gen_name[HEADER_LINE_LEN] = ""; static int idx = 0; - char *hl; int i, j = 0; if (hdr_line) { + char hline[HEADER_LINE_LEN] = ""; + char *hl; + strncpy(hline, hdr_line, sizeof(hline) - 1); hline[sizeof(hline) - 1] = '\0'; idx = 0; diff --git a/rndr_stats.c b/rndr_stats.c index 9bf1bf9..3d660c6 100644 --- a/rndr_stats.c +++ b/rndr_stats.c @@ -810,10 +810,10 @@ __print_funct_t render_memory_stats(struct activity *a, int isdb, char *pre, *smc = (struct stats_memory *) a->buf[curr]; int pt_newlin = PT_NOFLAG + (DISPLAY_HORIZONTALLY(flags) ? 0 : PT_NEWLIN); - int ptn; - unsigned long long nousedmem; if (DISPLAY_MEMORY(a->opt_flags)) { + unsigned long long nousedmem; + int ptn; nousedmem = smc->frmkb + smc->bufkb + smc->camkb + smc->slabkb; if (nousedmem > smc->tlmkb) { diff --git a/sa_common.c b/sa_common.c index 6118957..7c3e222 100644 --- a/sa_common.c +++ b/sa_common.c @@ -329,12 +329,12 @@ void display_sa_file_version(FILE *st, struct file_magic *file_magic) void handle_invalid_sa_file(int fd, struct file_magic *file_magic, char *file, int n) { - unsigned short fmt_magic; - fprintf(stderr, _("Invalid system activity file: %s\n"), file); if (n == FILE_MAGIC_SIZE) { if ((file_magic->sysstat_magic == SYSSTAT_MAGIC) || (file_magic->sysstat_magic == SYSSTAT_MAGIC_SWAPPED)) { + unsigned short fmt_magic; + /* This is a sysstat file, but this file has an old format */ display_sa_file_version(stderr, file_magic); @@ -2773,11 +2773,9 @@ int parse_sa_P_opt(char *argv[], int *opt, uint64_t *flags, struct activity *act */ void set_bitmaps(struct activity *act[], uint64_t *flags) { - int p; - if (!USE_OPTION_P(*flags)) { /* Force -P ALL */ - p = get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND); + int p = get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND); memset(act[p]->bitmap->b_array, ~0, BITMAP_SIZE(act[p]->bitmap->b_size)); } @@ -2845,11 +2843,8 @@ void parse_sa_devices(char *argv, struct activity *a, int max_len, int *opt, int */ double compute_ifutil(struct stats_net_dev *st_net_dev, double rx, double tx) { - unsigned long long speed; - if (st_net_dev->speed) { - - speed = (unsigned long long) st_net_dev->speed * 1000000; + unsigned long long speed = (unsigned long long) st_net_dev->speed * 1000000; if (st_net_dev->duplex == C_DUPLEX_FULL) { /* Full duplex */ @@ -3053,7 +3048,6 @@ int print_special_record(struct record_header *record_hdr, uint64_t l_flags, { char cur_date[TIMESTAMP_LEN], cur_time[TIMESTAMP_LEN]; int dp = 1; - int p; /* Fill timestamp structure (rectime) for current record */ if (sa_get_record_timestamp_struct(l_flags, record_hdr, rectime)) @@ -3072,6 +3066,8 @@ int print_special_record(struct record_header *record_hdr, uint64_t l_flags, } if (rtype == R_RESTART) { + int p; + /* Read new cpu number following RESTART record */ file_hdr->sa_cpu_nr = read_nr_value(ifd, file, file_magic, endian_mismatch, arch_64, TRUE); @@ -3438,9 +3434,10 @@ void get_global_int_statistics(struct activity *a, int prev, int curr, char *get_fs_name_to_display(struct activity *a, uint64_t flags, struct stats_filesystem *st_fs) { char *pname = NULL, *persist_dev_name; - char fname[MAX_FS_LEN]; if (DISPLAY_PERSIST_NAME_S(flags) && !DISPLAY_MOUNT(a->opt_flags)) { + char fname[MAX_FS_LEN]; + strncpy(fname, st_fs->fs_name, sizeof(fname)); fname[sizeof(fname) - 1] = '\0'; if ((persist_dev_name = get_persistent_name_from_pretty(basename(fname))) != NULL) { diff --git a/sa_conv.c b/sa_conv.c index 397ec14..e6b1f51 100644 --- a/sa_conv.c +++ b/sa_conv.c @@ -436,16 +436,15 @@ invalid_header: unsigned long long moveto_long_long(void *buffer, int endian_mismatch, int arch_64) { unsigned int *u_int; - unsigned long long *ull_int, ull_i; if (arch_64) { - ull_int = (unsigned long long *) buffer; + unsigned long long *ull_int = (unsigned long long *) buffer; return *ull_int; } u_int = (unsigned int *) buffer; if (endian_mismatch) { - ull_i = (unsigned long long) *u_int; + unsigned long long ull_i = (unsigned long long) *u_int; return (ull_i >> 32) | (ull_i << 32); } else { @@ -1600,12 +1599,14 @@ int upgrade_restart_record(int fd, int stdfd, struct activity *act[], int endian_mismatch, int arch_64, unsigned int vol_act_nr) { - int i, p; + int p; struct old_file_activity ofile_act; /* Number of cpu read in the activity list. See upgrade_header_section() */ __nr_t cpu_nr = file_hdr->sa_cpu_nr; if (previous_format == FORMAT_MAGIC_2173) { + int i; + /* * For versions from 10.3.1 to 11.6.x, * the restart record is followed by a list diff --git a/sadf_misc.c b/sadf_misc.c index e39ca81..152cc24 100644 --- a/sadf_misc.c +++ b/sadf_misc.c @@ -632,9 +632,9 @@ __printf_funct_t print_pcp_statistics(int *tab, int action, struct activity *act unsigned int id_seq[]) { #ifdef HAVE_PCP - int i, p; - if (action & F_BEGIN) { + int i, p; + for (i = 0; i < NR_ACT; i++) { if (!id_seq[i]) continue; /* Activity not in file */ @@ -1112,10 +1112,11 @@ __printf_funct_t print_xml_header(void *parm, int action, char *dfile, char *my_ { struct tm rectime, loc_t; time_t t = file_hdr->sa_ust_time; - char cur_time[TIMESTAMP_LEN]; int *tab = (int *) parm; if (action & F_BEGIN) { + char cur_time[TIMESTAMP_LEN]; + printf("\n"); printf("sa_ust_time; - char cur_time[TIMESTAMP_LEN]; int *tab = (int *) parm; if (action & F_BEGIN) { + char cur_time[TIMESTAMP_LEN]; + xprintf(*tab, "{\"sysstat\": {"); xprintf(++(*tab), "\"hosts\": ["); @@ -1241,14 +1243,14 @@ __printf_funct_t print_hdr_header(void *parm, int action, char *dfile, char *my_ struct activity *act[], unsigned int id_seq[], struct file_activity *file_actlst) { - int i, p; - struct tm rectime, loc_t; - time_t t = file_hdr->sa_ust_time; - struct file_activity *fal; - char cur_time[TIMESTAMP_LEN]; - /* Actions F_MAIN and F_END ignored */ if (action & F_BEGIN) { + struct tm rectime, loc_t; + time_t t = file_hdr->sa_ust_time; + int i, p; + char cur_time[TIMESTAMP_LEN]; + struct file_activity *fal; + printf(_("System activity data file: %s (%#x)\n"), dfile, file_magic->format_magic); @@ -1348,8 +1350,6 @@ __printf_funct_t print_svg_header(void *parm, int action, char *dfile, char *my_ struct svg_hdr_parm *hdr_parm = (struct svg_hdr_parm *) parm; struct tm rectime; time_t t = file_hdr->sa_ust_time; - unsigned int height, ht = 0; - int i, p; if (action & F_BEGIN) { printf("\n"); @@ -1365,6 +1365,8 @@ __printf_funct_t print_svg_header(void *parm, int action, char *dfile, char *my_ } if (action & F_MAIN) { + unsigned int height; + if (SET_CANVAS_HEIGHT(flags)) { /* * Option "-O height=..." used: @graph_nr is @@ -1394,6 +1396,9 @@ __printf_funct_t print_svg_header(void *parm, int action, char *dfile, char *my_ PLAIN_OUTPUT); printf("\n"); if (DISPLAY_TOC(flags)) { + unsigned int ht = 0; + int i, p; + for (i = 0; i < NR_ACT; i++) { if (!id_seq[i]) continue; /* Activity not in file */ @@ -1455,7 +1460,6 @@ __printf_funct_t print_pcp_header(void *parm, int action, char *dfile, char *my_ { #ifdef HAVE_PCP char buf[64]; - int rc; unsigned long long utc_sec = file_hdr->sa_ust_time; if (action & F_BEGIN) { @@ -1497,6 +1501,8 @@ __printf_funct_t print_pcp_header(void *parm, int action, char *dfile, char *my_ if (action & F_END) { if (action & F_BEGIN) { + int rc; + if ((rc = pmiWrite(utc_sec, 0)) < 0) { fprintf(stderr, "PCP: pmiWrite: %s\n", pmiErrStr(rc)); exit(4); diff --git a/svg_stats.c b/svg_stats.c index bb2082d..ff79a1b 100644 --- a/svg_stats.c +++ b/svg_stats.c @@ -600,7 +600,6 @@ void gr_autoscaling(unsigned int asfactor[], int asf_nr, int group, enum svg_gra int pos, double gmax, double *spmax) { int j; - char val[32]; for (j = 0; j < asf_nr; j++) { /* Init autoscale factors */ @@ -608,6 +607,8 @@ void gr_autoscaling(unsigned int asfactor[], int asf_nr, int group, enum svg_gra } if (AUTOSCALE_ON(flags) && (group > 1) && gmax && (g_type == SVG_LINE_GRAPH)) { + char val[32]; + /* Autoscaling... */ for (j = 0; (j < group) && (j < asf_nr); j++) { if (!*(spmax + pos + j) || (*(spmax + pos + j) == gmax)) @@ -1156,7 +1157,6 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st unsigned long long itv, struct record_header *record_hdr) { struct stats_cpu *scc, *scp; - unsigned long long deltot_jiffies = 1; unsigned char offline_cpu_bitmap[BITMAP_SIZE(NR_CPUS)] = {0}; int group1[] = {5}; int group2[] = {9}; @@ -1167,9 +1167,8 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st static double *spmin, *spmax; static char **out; static int *outsize; - char item_name[16]; - double offset, val; - int i, j, k, pos; + double offset; + int i, pos; if (action & F_BEGIN) { /* @@ -1180,6 +1179,8 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st } if (action & F_MAIN) { + unsigned long long deltot_jiffies = 1; + int j, k; /* @nr[curr] cannot normally be greater than @nr_ini */ if (a->nr[curr] > a->nr_ini) { @@ -1233,7 +1234,7 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st if (!deltot_jiffies) { /* Current CPU is tickless */ - val = 100.0; /* Tickless CPU: %idle = 100% */ + double val = 100.0; /* Tickless CPU: %idle = 100% */ if (DISPLAY_CPU_DEF(a->opt_flags)) { j = 5; /* -u */ @@ -1368,6 +1369,7 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st if (action & F_END) { int xid = 0, displayed; + char item_name[16]; if (DISPLAY_IDLE(flags)) { /* Include additional %idle field */ @@ -1776,9 +1778,6 @@ __print_funct_t svg_print_memory_stats(struct activity *a, int curr, int action, static char **out; static int *outsize; static int xid = 0; - double tval; - int i; - unsigned long long nousedmem; if (action & F_BEGIN) { /* @@ -1789,6 +1788,9 @@ __print_funct_t svg_print_memory_stats(struct activity *a, int curr, int action, } if (action & F_MAIN) { + unsigned long long nousedmem; + double tval; + /* Check for min/max values */ save_extrema(a->gtypes_nr, (void *) a->buf[curr], NULL, itv, spmin, spmax, g_fields); @@ -1943,6 +1945,7 @@ __print_funct_t svg_print_memory_stats(struct activity *a, int curr, int action, } if (action & F_END) { + int i; /* Conversion kB -> MB */ for (i = 0; i < 17; i++) { @@ -4307,7 +4310,6 @@ __print_funct_t svg_print_pwr_cpufreq_stats(struct activity *a, int curr, int ac static double *spmin, *spmax; static char **out; static int *outsize; - char item_name[16]; int i; if (action & F_BEGIN) { @@ -4346,6 +4348,7 @@ __print_funct_t svg_print_pwr_cpufreq_stats(struct activity *a, int curr, int ac if (action & F_END) { int xid = 0; + char item_name[16]; for (i = 0; (i < a->item_list_sz) && (i < a->bitmap->b_size + 1); i++) { @@ -4410,7 +4413,6 @@ __print_funct_t svg_print_pwr_fan_stats(struct activity *a, int curr, int action static double *spmin, *spmax; static char **out; static int *outsize; - char item_name[MAX_SENSORS_DEV_LEN + 16]; int i; if (action & F_BEGIN) { @@ -4438,6 +4440,7 @@ __print_funct_t svg_print_pwr_fan_stats(struct activity *a, int curr, int action } if (action & F_END) { + char item_name[MAX_SENSORS_DEV_LEN + 16]; int xid = 0; for (i = 0; i < a->item_list_sz; i++) { @@ -4490,9 +4493,7 @@ __print_funct_t svg_print_pwr_temp_stats(struct activity *a, int curr, int actio static double *spmin, *spmax; static char **out; static int *outsize; - char item_name[MAX_SENSORS_DEV_LEN + 16]; int i; - double tval; if (action & F_BEGIN) { /* @@ -4503,6 +4504,8 @@ __print_funct_t svg_print_pwr_temp_stats(struct activity *a, int curr, int actio } if (action & F_MAIN) { + double tval; + /* For each temperature sensor */ for (i = 0; i < a->nr[curr]; i++) { @@ -4537,6 +4540,7 @@ __print_funct_t svg_print_pwr_temp_stats(struct activity *a, int curr, int actio } if (action & F_END) { + char item_name[MAX_SENSORS_DEV_LEN + 16]; int xid = 0; for (i = 0; i < a->item_list_sz; i++) { @@ -4590,9 +4594,7 @@ __print_funct_t svg_print_pwr_in_stats(struct activity *a, int curr, int action, static double *spmin, *spmax; static char **out; static int *outsize; - char item_name[MAX_SENSORS_DEV_LEN + 16]; int i; - double tval; if (action & F_BEGIN) { /* @@ -4603,6 +4605,8 @@ __print_funct_t svg_print_pwr_in_stats(struct activity *a, int curr, int action, } if (action & F_MAIN) { + double tval; + /* For each voltage input sensor */ for (i = 0; i < a->nr[curr]; i++) { @@ -4637,6 +4641,7 @@ __print_funct_t svg_print_pwr_in_stats(struct activity *a, int curr, int action, } if (action & F_END) { + char item_name[MAX_SENSORS_DEV_LEN + 16]; int xid = 0; for (i = 0; i < a->item_list_sz; i++) { @@ -4687,7 +4692,6 @@ __print_funct_t svg_print_pwr_bat_stats(struct activity *a, int curr, int action static double *spmin, *spmax; static char **out; static int *outsize; - char item_name[16]; int i; if (action & F_BEGIN) { @@ -4722,6 +4726,7 @@ __print_funct_t svg_print_pwr_bat_stats(struct activity *a, int curr, int action } if (action & F_END) { + char item_name[16]; int xid = 0; for (i = 0; i < a->item_list_sz; i++) { @@ -4776,7 +4781,6 @@ __print_funct_t svg_print_huge_stats(struct activity *a, int curr, int action, s static double *spmin, *spmax; static char **out; static int *outsize; - double tval; if (action & F_BEGIN) { /* @@ -4789,6 +4793,8 @@ __print_funct_t svg_print_huge_stats(struct activity *a, int curr, int action, s } if (action & F_MAIN) { + double tval; + /* Check for min/max values */ save_extrema(a->gtypes_nr, (void *) a->buf[curr], NULL, itv, spmin, spmax, g_fields); @@ -5298,9 +5304,8 @@ __print_funct_t svg_print_softnet_stats(struct activity *a, int curr, int action static double *spmin, *spmax; static char **out; static int *outsize; - char item_name[16]; unsigned char offline_cpu_bitmap[BITMAP_SIZE(NR_CPUS)] = {0}; - int i, pos, restart; + int i, pos; if (action & F_BEGIN) { /* @@ -5311,6 +5316,8 @@ __print_funct_t svg_print_softnet_stats(struct activity *a, int curr, int action } if (action & F_MAIN) { + int restart; + memset(&ssnczero, 0, STATS_SOFTNET_SIZE); /* @nr[curr] cannot normally be greater than @nr_ini */ @@ -5390,6 +5397,8 @@ __print_funct_t svg_print_softnet_stats(struct activity *a, int curr, int action } if (action & F_END) { + char item_name[16]; + for (i = 0; (i < a->item_list_sz) && (i < a->bitmap->b_size + 1); i++) { /* Should current CPU (including CPU "all") be displayed? */ @@ -5448,7 +5457,6 @@ __print_funct_t svg_print_psicpu_stats(struct activity *a, int curr, int action, static double *spmin, *spmax; static char **out; static int *outsize; - double tval; if (action & F_BEGIN) { /* @@ -5459,6 +5467,8 @@ __print_funct_t svg_print_psicpu_stats(struct activity *a, int curr, int action, } if (action & F_MAIN) { + double tval; + /* Check for min/max values */ if (psic->some_acpu_10 > *spmax) { *spmax = psic->some_acpu_10; @@ -5552,7 +5562,6 @@ __print_funct_t svg_print_psiio_stats(struct activity *a, int curr, int action, static double *spmin, *spmax; static char **out; static int *outsize; - double tval; if (action & F_BEGIN) { /* @@ -5563,6 +5572,8 @@ __print_funct_t svg_print_psiio_stats(struct activity *a, int curr, int action, } if (action & F_MAIN) { + double tval; + /* Check for min/max values */ if (psic->some_aio_10 > *spmax) { *spmax = psic->some_aio_10; @@ -5704,7 +5715,6 @@ __print_funct_t svg_print_psimem_stats(struct activity *a, int curr, int action, static double *spmin, *spmax; static char **out; static int *outsize; - double tval; if (action & F_BEGIN) { /* @@ -5715,6 +5725,8 @@ __print_funct_t svg_print_psimem_stats(struct activity *a, int curr, int action, } if (action & F_MAIN) { + double tval; + /* Check for min/max values */ if (psic->some_amem_10 > *spmax) { *spmax = psic->some_amem_10; diff --git a/tapestat.c b/tapestat.c index fcc4e8b..b1fb2aa 100644 --- a/tapestat.c +++ b/tapestat.c @@ -211,12 +211,14 @@ int get_max_tape_drives(void) */ void tape_check_tapes_and_realloc(void) { - int new_max_tape_drives, i; + int new_max_tape_drives; /* Count again number of tapes */ new_max_tape_drives = get_max_tape_drives(); if (new_max_tape_drives > max_tape_drives && new_max_tape_drives > 0) { + int i; + /* New tapes found: Realloc structures */ struct tape_stats *tape_old_stats_t = (struct tape_stats *) realloc(tape_old_stats, sizeof(struct tape_stats) * new_max_tape_drives); @@ -484,7 +486,6 @@ void tape_write_stats(struct calc_stats *tape, int i) */ void write_stats(struct tm *rectime) { - int i; struct calc_stats tape; struct tape_stats *tmp; @@ -510,6 +511,7 @@ void write_stats(struct tm *rectime) * zero omit is true then we print nothing. */ if (max_tape_drives > 0) { + int i; for (i = 0; i < max_tape_drives; i++) { if ((tape_new_stats[i].valid == TAPE_STATS_VALID) && diff --git a/xml_stats.c b/xml_stats.c index 62bf3a1..4793fd2 100644 --- a/xml_stats.c +++ b/xml_stats.c @@ -513,11 +513,11 @@ __print_funct_t xml_print_memory_stats(struct activity *a, int curr, int tab, { struct stats_memory *smc = (struct stats_memory *) a->buf[curr]; - unsigned long long nousedmem; xprintf(tab, ""); if (DISPLAY_MEMORY(a->opt_flags)) { + unsigned long long nousedmem; nousedmem = smc->frmkb + smc->bufkb + smc->camkb + smc->slabkb; if (nousedmem > smc->tlmkb) { -- 2.40.0