Skip to content

Commit

Permalink
Added filesystems statistics to sar (part 1): Basic definitions and s…
Browse files Browse the repository at this point in the history
…tructures

A new option (-F) has been added to sar. This option tells sar to display
filesystems statistics.
This first patch adds the corresponding structures, constants and the new
functions prototypes.
sar's help and usage messages have also been updated.
  • Loading branch information
seb committed Apr 29, 2013
1 parent 1c49e72 commit fe061c6
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 4 deletions.
34 changes: 33 additions & 1 deletion activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,37 @@ struct activity pwr_usb_act = {
.bitmap = NULL
};

/* Filesystem usage activity */
struct activity filesystem_act = {
.id = A_FILESYSTEM,
.options = AO_NULL,
.magic = ACTIVITY_MAGIC_BASE,
.group = G_DISK,
#ifdef SOURCE_SADC
.f_count = wrap_get_filesystem_nr,
.f_count2 = NULL,
.f_read = wrap_read_filesystem,
#endif
#ifdef SOURCE_SAR
.f_print = print_filesystem_stats,
.f_print_avg = print_avg_filesystem_stats,
#endif
#ifdef SOURCE_SADF
.f_render = render_filesystem_stats,
.f_xml_print = xml_print_filesystem_stats,
.f_json_print = json_print_filesystem_stats,
.hdr_line = "Mbfsfree;Mbfsused;%fsused;%ufsused;Ifree;Iused;%Iused;FILESYSTEM",
.name = "A_FILESYSTEM",
#endif
.nr = -1,
.nr2 = 1,
.fsize = STATS_FILESYSTEM_SIZE,
.msize = STATS_FILESYSTEM_SIZE,
.opt_flags = 0,
.buf = {NULL, NULL, NULL},
.bitmap = NULL
};


/*
* Array of activities.
Expand Down Expand Up @@ -1239,6 +1270,7 @@ struct activity *act[NR_ACT] = {
&pwr_temp_act,
&pwr_in_act,
&pwr_wghfreq_act,
&pwr_usb_act /* AO_CLOSE_MARKUP */
&pwr_usb_act, /* AO_CLOSE_MARKUP */
/* </power-management> */
&filesystem_act
};
17 changes: 17 additions & 0 deletions json_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -2085,3 +2085,20 @@ __print_funct_t json_print_pwr_usb_stats(struct activity *a, int curr, int tab,
json_markup_power_management(tab, CLOSE_JSON_MARKUP);
}
}

/*
***************************************************************************
* Display filesystems statistics in JSON.
*
* IN:
* @a Activity structure with statistics.
* @curr Index in array for current sample statistics.
* @tab Indentation in output.
* @itv Interval of time in jiffies.
***************************************************************************
*/
__print_funct_t json_print_filesystem_stats(struct activity *a, int curr, int tab,
unsigned long long itv)
{
/* FIXME */
}
2 changes: 2 additions & 0 deletions json_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,7 @@ extern __print_funct_t json_print_pwr_wghfreq_stats
(struct activity *, int, int, unsigned long long);
extern __print_funct_t json_print_pwr_usb_stats
(struct activity *, int, int, unsigned long long);
extern __print_funct_t json_print_filesystem_stats
(struct activity *, int, int, unsigned long long);

#endif /* _XML_STATS_H */
53 changes: 53 additions & 0 deletions pr_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -2437,3 +2437,56 @@ __print_funct_t print_avg_pwr_usb_stats(struct activity *a, int prev, int curr,
{
stub_print_pwr_usb_stats(a, 2, TRUE);
}

/*
***************************************************************************
* Display filesystems statistics. This function is used to
* display instantaneous and average statistics.
*
* IN:
* @a Activity structure with statistics.
* @prev Index in array where stats used as reference are.
* @curr Index in array for current sample statistics.
* @itv Interval of time in jiffies.
* @dispavg TRUE if displaying average statistics.
***************************************************************************
*/
__print_funct_t stub_print_filesystem_stats(struct activity *a, int prev, int curr,
unsigned long long itv, int dispavg)
{
/* FIXME */
}

/*
***************************************************************************
* Display filesystems statistics.
*
* IN:
* @a Activity structure with statistics.
* @prev Index in array where stats used as reference are.
* @curr Index in array for current sample statistics.
* @itv Interval of time in jiffies.
***************************************************************************
*/
__print_funct_t print_filesystem_stats(struct activity *a, int prev, int curr,
unsigned long long itv)
{
stub_print_filesystem_stats(a, prev, curr, itv, FALSE);
}

/*
***************************************************************************
* Display average filesystems statistics.
*
* IN:
* @a Activity structure with statistics.
* @prev Index in array where stats used as reference are.
* @curr Index in array for current sample statistics.
* @itv Interval of time in jiffies.
***************************************************************************
*/
__print_funct_t print_avg_filesystem_stats(struct activity *a, int prev, int curr,
unsigned long long itv)
{
stub_print_filesystem_stats(a, prev, curr, itv, TRUE);
}
4 changes: 4 additions & 0 deletions pr_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ extern __print_funct_t print_pwr_wghfreq_stats
(struct activity *, int, int, unsigned long long);
extern __print_funct_t print_pwr_usb_stats
(struct activity *, int, int, unsigned long long);
extern __print_funct_t print_filesystem_stats
(struct activity *, int, int, unsigned long long);

/* Functions used to display average statistics */
extern __print_funct_t print_avg_memory_stats
Expand All @@ -112,5 +114,7 @@ extern __print_funct_t print_avg_huge_stats
(struct activity *, int, int, unsigned long long);
extern __print_funct_t print_avg_pwr_usb_stats
(struct activity *, int, int, unsigned long long);
extern __print_funct_t print_avg_filesystem_stats
(struct activity *, int, int, unsigned long long);

#endif /* _PR_STATS_H */
12 changes: 12 additions & 0 deletions rd_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#define NET_SNMP "/proc/net/snmp"
#define NET_SNMP6 "/proc/net/snmp6"
#define CPUINFO "/proc/cpuinfo"
#define MTAB "/etc/mtab"


/*
Expand Down Expand Up @@ -520,6 +521,17 @@ struct stats_pwr_usb {

#define STATS_PWR_USB_SIZE (sizeof(struct stats_pwr_usb))

/* Structure for filesystems statistics */
struct stats_filesystem {
unsigned long long f_blocks __attribute__ ((aligned (16)));
unsigned long long f_bfree __attribute__ ((aligned (16)));
unsigned long long f_bavail __attribute__ ((aligned (16)));
unsigned long long f_files __attribute__ ((aligned (16)));
unsigned long long f_ffree __attribute__ ((aligned (16)));
};

#define STATS_FILESYSTEM_SIZE (sizeof(struct stats_filesystem))

/*
***************************************************************************
* Prototypes for functions used to read system statistics
Expand Down
18 changes: 18 additions & 0 deletions rndr_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -2792,3 +2792,21 @@ __print_funct_t render_pwr_usb_stats(struct activity *a, int isdb, char *pre,
suc->product);
}
}

/*
***************************************************************************
* Display filesystems statistics in selected format.
*
* IN:
* @a Activity structure with statistics.
* @isdb Flag, true if db printing, false if ppc printing.
* @pre Prefix string for output entries
* @curr Index in array for current sample statistics.
* @itv Interval of time in jiffies.
***************************************************************************
*/
__print_funct_t render_filesystem_stats(struct activity *a, int isdb, char *pre,
int curr, unsigned long long itv)
{
/* FIXME */
}
2 changes: 2 additions & 0 deletions rndr_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,7 @@ extern __print_funct_t render_pwr_wghfreq_stats
(struct activity *, int, char *, int, unsigned long long);
extern __print_funct_t render_pwr_usb_stats
(struct activity *, int, char *, int, unsigned long long);
extern __print_funct_t render_filesystem_stats
(struct activity *, int, char *, int, unsigned long long);

#endif /* _RNDR_STATS_H */
8 changes: 7 additions & 1 deletion sa.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

/* Number of activities */
#define NR_ACT 36
#define NR_ACT 37

/* Activities */
#define A_CPU 1
Expand Down Expand Up @@ -58,6 +58,7 @@
#define A_HUGE 34
#define A_PWR_WGHFREQ 35
#define A_PWR_USB 36
#define A_FILESYSTEM 37


/* Macro used to flag an activity that should be collected */
Expand Down Expand Up @@ -197,6 +198,7 @@
#define NR_DISK_PREALLOC 3
#define NR_FREQ_PREALLOC 0
#define NR_USB_PREALLOC 5
#define NR_FILESYSTEM_PREALLOC 3

#define UTSNAME_LEN 65
#define TIMESTAMP_LEN 16
Expand Down Expand Up @@ -706,6 +708,8 @@ extern __nr_t
wrap_get_freq_nr(struct activity *);
extern __nr_t
wrap_get_usb_nr(struct activity *);
extern __nr_t
wrap_get_filesystem_nr(struct activity *);

/* Functions used to read activities statistics */
extern __read_funct_t
Expand Down Expand Up @@ -780,6 +784,8 @@ extern __read_funct_t
wrap_read_time_in_state(struct activity *);
extern __read_funct_t
wrap_read_bus_usb_dev(struct activity *);
extern __read_funct_t
wrap_read_filesystem(struct activity *);

/* Other functions */
extern void
Expand Down
4 changes: 4 additions & 0 deletions sa_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,10 @@ int parse_sar_opt(char *argv[], int *opt, struct activity *act[],
SELECT_ACTIVITY(A_DISK);
break;

case 'F':
SELECT_ACTIVITY(A_FILESYSTEM);
break;

case 'H':
p = get_activity_position(act, A_HUGE);
act[p]->options |= AO_SELECTED;
Expand Down
43 changes: 43 additions & 0 deletions sa_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,28 @@ __read_funct_t wrap_read_bus_usb_dev(struct activity *a)
return;
}

/*
***************************************************************************
* Read filesystem statistics.
*
* IN:
* @a Activity structure.
*
* OUT:
* @a Activity structure with statistics.
***************************************************************************
*/
__read_funct_t wrap_read_filesystem(struct activity *a)
{
struct stats_filesystem *st_filesystem
= (struct stats_filesystem *) a->_buf0;

/* Read filesystems from /etc/mtab */
/* FIXME */

return;
}

/*
***************************************************************************
* Count number of interrupts that are in /proc/stat file.
Expand Down Expand Up @@ -1049,3 +1071,24 @@ __nr_t wrap_get_usb_nr(struct activity *a)

return 0;
}

/*
***************************************************************************
* Get number of mounted filesystems from /etc/mtab. Don't take into account
* pseudo-filesystems.
*
* IN:
* @a Activity structure.
*
* RETURNS:
* Number of filesystems + a pre-allocation constant.
***************************************************************************
*/
__nr_t wrap_get_filesystem_nr(struct activity *a)
{
__nr_t n = 0;

/* FIXME */

return 0;
}
3 changes: 2 additions & 1 deletion sar.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void usage(char *progname)
{
print_usage_title(stderr, progname);
fprintf(stderr, _("Options are:\n"
"[ -A ] [ -B ] [ -b ] [ -C ] [ -d ] [ -H ] [ -h ] [ -p ] [ -q ] [ -R ]\n"
"[ -A ] [ -B ] [ -b ] [ -C ] [ -d ] [ -F ] [ -H ] [ -h ] [ -p ] [ -q ] [ -R ]\n"
"[ -r ] [ -S ] [ -t ] [ -u [ ALL ] ] [ -V ] [ -v ] [ -W ] [ -w ] [ -y ]\n"
"[ -I { <int> [,...] | SUM | ALL | XALL } ] [ -P { <cpu> [,...] | ALL } ]\n"
"[ -m { <keyword> [,...] | ALL } ] [ -n { <keyword> [,...] | ALL } ]\n"
Expand All @@ -132,6 +132,7 @@ void display_help(char *progname)
printf(_("\t-b\tI/O and transfer rate statistics\n"));
printf(_("\t-B\tPaging statistics\n"));
printf(_("\t-d\tBlock device statistics\n"));
printf(_("\t-F\tFilesystems statistics\n"));
printf(_("\t-H\tHugepages utilization statistics\n"));
printf(_("\t-I { <int> | SUM | ALL | XALL }\n"
"\t\tInterrupts statistics\n"));
Expand Down
19 changes: 18 additions & 1 deletion xml_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -1989,4 +1989,21 @@ __print_funct_t xml_print_pwr_usb_stats(struct activity *a, int curr, int tab,
if (CLOSE_MARKUP(a->options)) {
xml_markup_power_management(tab, CLOSE_XML_MARKUP);
}
}
}

/*
***************************************************************************
* Display filesystems statistics in XML.
*
* IN:
* @a Activity structure with statistics.
* @curr Index in array for current sample statistics.
* @tab Indentation in XML output.
* @itv Interval of time in jiffies.
***************************************************************************
*/
__print_funct_t xml_print_filesystem_stats(struct activity *a, int curr, int tab,
unsigned long long itv)
{
/* FIXME */
}
2 changes: 2 additions & 0 deletions xml_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,7 @@ extern __print_funct_t xml_print_pwr_wghfreq_stats
(struct activity *, int, int, unsigned long long);
extern __print_funct_t xml_print_pwr_usb_stats
(struct activity *, int, int, unsigned long long);
extern __print_funct_t xml_print_filesystem_stats
(struct activity *, int, int, unsigned long long);

#endif /* _XML_STATS_H */

0 comments on commit fe061c6

Please sign in to comment.