Changes:
xxxx/xx/xx: Version 10.1.1 - Sebastien Godard (sysstat <at> orange.fr)
+ * Added option -[0-9]* to sar to show data of that days ago.
2012/05/16: Version 10.0.5 - Sebastien Godard (sysstat <at> orange.fr)
* [Alain Chereau]: Options -g and -T added to iostat. These
read_cifs_stat(curr);
/* Get time */
- get_localtime(rectime);
+ get_localtime(rectime, 0);
/* Print results */
write_stats(curr, rectime);
/* Init structures according to machine architecture */
io_sys_init();
- get_localtime(&rectime);
+ get_localtime(&rectime, 0);
/* Get system name, release number and hostname */
uname(&header);
***************************************************************************
* Get local date and time.
*
+ * IN:
+ * @d_off Day offset (number of days to go back in the past).
+ *
* OUT:
* @rectime Current local date and time.
*
* Value of time in seconds since the Epoch.
***************************************************************************
*/
-time_t get_localtime(struct tm *rectime)
+time_t get_localtime(struct tm *rectime, int d_off)
{
time_t timer;
struct tm *ltm;
time(&timer);
+ timer -= SEC_PER_DAY * d_off;
ltm = localtime(&timer);
*rectime = *ltm;
***************************************************************************
* Get date and time expressed in UTC.
*
+ * IN:
+ * @d_off Day offset (number of days to go back in the past).
+ *
* OUT:
* @rectime Current date and time expressed in UTC.
*
* Value of time in seconds since the Epoch.
***************************************************************************
*/
-time_t get_gmtime(struct tm *rectime)
+time_t get_gmtime(struct tm *rectime, int d_off)
{
time_t timer;
struct tm *ltm;
time(&timer);
+ timer -= SEC_PER_DAY * d_off;
ltm = gmtime(&timer);
*rectime = *ltm;
***************************************************************************
* Get date and time and take into account <ENV_TIME_DEFTM> variable.
*
+ * IN:
+ * @d_off Day offset (number of days to go back in the past).
+ *
* OUT:
* @rectime Current date and time.
*
* Value of time in seconds since the Epoch.
***************************************************************************
*/
-time_t get_time(struct tm *rectime)
+time_t get_time(struct tm *rectime, int d_off)
{
static int utc = 0;
char *e;
}
if (utc == 2)
- return get_gmtime(rectime);
+ return get_gmtime(rectime, d_off);
else
- return get_localtime(rectime);
+ return get_localtime(rectime, d_off);
}
/*
#define DISP_HDR 1
+/* Number of seconds per day */
+#define SEC_PER_DAY 3600 * 24
+
/* Maximum number of CPUs */
#ifdef __CPU_SETSIZE
#define NR_CPUS __CPU_SETSIZE
extern void
get_kb_shift(void);
extern time_t
- get_localtime(struct tm *);
+ get_localtime(struct tm *, int);
extern time_t
- get_time(struct tm *);
+ get_time(struct tm *, int);
unsigned long long
get_per_cpu_interval(struct stats_cpu *, struct stats_cpu *);
extern int
}
/* Get time */
- get_localtime(rectime);
+ get_localtime(rectime, 0);
/* Print results */
write_stats(curr, rectime);
presave_device_list();
}
- get_localtime(&rectime);
+ get_localtime(&rectime, 0);
/* Get system name, release number and hostname */
uname(&header);
-.TH SAR 1 "MAY 2011" Linux "Linux User's Manual" -*- nroff -*-
+.TH SAR 1 "JUNE 2012" Linux "Linux User's Manual" -*- nroff -*-
.SH NAME
sar \- Collect, report, or save system activity information.
.SH SYNOPSIS
.I filename
.B ] | -f [
.I filename
-.B ] ] [ -s [
+.B ] | -[0-9]+ ] [ -s [
.I hh:mm:ss
.B ] ] [ -e [
.I hh:mm:ss
saved in a file. This file can be either the one specified by the
.B -f
flag or, by default, the standard system activity daily data file.
+It is also possible to enter -1, -2 etc. as an argument to sar to
+display data
+of that days ago. For example, -1 will point at the standard system
+activity file of yesterday.
Without the
.B -P
}
/* Get time */
- get_localtime(&(mp_tstamp[curr]));
+ get_localtime(&(mp_tstamp[curr]), 0);
/* Read stats */
if (cpu_nr > 1) {
}
/* Get time */
- get_localtime(&(mp_tstamp[0]));
+ get_localtime(&(mp_tstamp[0]), 0);
/* Get system name, release number and hostname */
uname(&header);
read_nfs_stat(curr);
/* Get time */
- get_localtime(rectime);
+ get_localtime(rectime, 0);
/* Print results */
write_stats(curr, rectime);
/* Init structures according to machine architecture */
io_sys_init();
- get_localtime(&rectime);
+ get_localtime(&rectime, 0);
/* Get system name, release number and hostname */
uname(&header);
do {
/* Get time */
- get_localtime(&ps_tstamp[curr]);
+ get_localtime(&ps_tstamp[curr], 0);
if (cpu_nr > 1) {
/*
}
/* Get time */
- get_localtime(&(ps_tstamp[0]));
+ get_localtime(&(ps_tstamp[0]), 0);
/* Get system name, release number and hostname */
uname(&header);
extern void
set_bitmap(unsigned char [], unsigned char, unsigned int);
extern void
- set_default_file(struct tm *, char *);
+ set_default_file(struct tm *, char *, int);
extern void
set_hdr_rectime(unsigned int, struct tm *, struct file_header *);
***************************************************************************
* Set current daily data file name.
*
+ * IN:
+ * @d_off Day offset (number of days to go back in the past).
+ *
* OUT:
* @rectime Current date and time.
* @datafile Name of daily data file.
***************************************************************************
*/
-void set_default_file(struct tm *rectime, char *datafile)
+void set_default_file(struct tm *rectime, char *datafile, int d_off)
{
- get_time(rectime);
+ get_time(rectime, d_off);
snprintf(datafile, MAX_FILE_LEN,
"%s/sa%02d", SA_DIR, rectime->tm_mday);
datafile[MAX_FILE_LEN - 1] = '\0';
if (PRINT_TRUE_TIME(flags)) {
/* Get local time. This is just to fill HH:MM:SS fields */
- get_time(rectime);
+ get_time(rectime, 0);
rectime->tm_mday = file_hdr->sa_day;
rectime->tm_mon = file_hdr->sa_month;
memset(&file_hdr, 0, FILE_HEADER_SIZE);
/* Then get current date */
- file_hdr.sa_ust_time = get_time(&rectime);
+ file_hdr.sa_ust_time = get_time(&rectime, 0);
/* OK, now fill the header */
file_hdr.sa_nr_act = get_activity_nr(act, AO_COLLECTED, COUNT_ACTIVITIES);
record_hdr.record_type = rtype;
/* Save time */
- record_hdr.ust_time = get_time(&rectime);
+ record_hdr.ust_time = get_time(&rectime, 0);
record_hdr.hour = rectime.tm_hour;
record_hdr.minute = rectime.tm_min;
* as "-" on the command line) and it is from a past month,
* then overwrite (truncate) it.
*/
- get_time(&rectime);
+ get_time(&rectime, 0);
if (((file_hdr.sa_month != rectime.tm_mon) ||
(file_hdr.sa_year != rectime.tm_year)) &&
reset_stats();
/* Save time */
- record_hdr.ust_time = get_time(rectime);
+ record_hdr.ust_time = get_time(rectime, 0);
record_hdr.hour = rectime->tm_hour;
record_hdr.minute = rectime->tm_min;
record_hdr.second = rectime->tm_sec;
/* Rotate activity file if necessary */
if (WANT_SA_ROTAT(flags)) {
/* The user specified '-' as the filename to use */
- set_default_file(rectime, new_ofile);
+ set_default_file(rectime, new_ofile, 0);
if (strcmp(ofile, new_ofile)) {
do_sa_rotat = TRUE;
stdfd = -1; /* Don't write to STDOUT */
if (!strcmp(argv[opt], "-")) {
/* File name set to '-' */
- set_default_file(&rectime, ofile);
+ set_default_file(&rectime, ofile, 0);
flags |= S_F_SA_ROTAT;
}
else if (!strncmp(argv[opt], "-", 1)) {
if (!dfile[0]) {
if (!strcmp(argv[opt], "-")) {
/* File name set to '-' */
- set_default_file(&rectime, dfile);
+ set_default_file(&rectime, dfile, 0);
opt++;
}
else if (!strncmp(argv[opt], "-", 1)) {
/* sadf reads current daily data file by default */
if (!dfile[0]) {
- set_default_file(&rectime, dfile);
+ set_default_file(&rectime, dfile, 0);
}
if (tm_start.use && tm_end.use && (tm_end.tm_hour < tm_start.tm_hour)) {
"[ -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"
- "[ -o [ <filename> ] | -f [ <filename> ] ]\n"
+ "[ -o [ <filename> ] | -f [ <filename> ] | -[0-9]+ ]\n"
"[ -i <interval> ] [ -s [ <hh:mm:ss> ] ] [ -e [ <hh:mm:ss> ] ]\n"));
exit(1);
}
{
int i, opt = 1, args_idx = 2;
int fd[2];
+ int day_offset = 0;
char from_file[MAX_FILE_LEN], to_file[MAX_FILE_LEN];
char ltemp[20];
from_file[MAX_FILE_LEN - 1] = '\0';
}
else {
- set_default_file(&rectime, from_file);
+ set_default_file(&rectime, from_file, day_offset);
}
}
usage(argv[0]);
}
}
+
+ else if ((strlen(argv[opt]) > 1) &&
+ (strlen(argv[opt]) < 4) &&
+ !strncmp(argv[opt], "-", 1) &&
+ (strspn(argv[opt] + 1, DIGITS) == (strlen(argv[opt]) - 1))) {
+ day_offset = atoi(argv[opt++] + 1);
+ }
else if (!strncmp(argv[opt], "-", 1)) {
/* Other options not previously tested */
/* 'sar' is equivalent to 'sar -f' */
if ((argc == 1) ||
((interval < 0) && !from_file[0] && !to_file[0])) {
- set_default_file(&rectime, from_file);
+ set_default_file(&rectime, from_file, day_offset);
}
if (tm_start.use && tm_end.use && (tm_end.tm_hour < tm_start.tm_hour)) {
if (!interval && (from_file[0] || to_file[0])) {
usage(argv[0]);
}
+
+ /* Cannot enter a day shift with -o option */
+ if (to_file[0] && day_offset) {
+ usage(argv[0]);
+ }
if (USE_PRETTY_OPTION(flags)) {
dm_major = get_devmap_major();