2 * tapestat: report tape statistics
3 * (C) 2015 Hewlett-Packard Development Company, L.P.
5 * Initial revision by Shane M. SEYMOUR (shane.seymour <at> hpe.com)
6 * Modified for sysstat by Sebastien GODARD (sysstat <at> orange.fr)
14 /* T_: tapestat - D_: Display - F_: Flag */
15 #define T_D_TIMESTAMP 0x00001
16 #define T_D_KILOBYTES 0x00002
17 #define T_D_MEGABYTES 0x00004
18 #define T_D_OMIT_SINCE_BOOT 0x00008
19 #define T_D_ISO 0x00010
20 #define T_D_ZERO_OMIT 0x00020
21 #define T_D_UNIT 0x00040
23 #define DISPLAY_TIMESTAMP(m) (((m) & T_D_TIMESTAMP) == T_D_TIMESTAMP)
24 #define DISPLAY_KILOBYTES(m) (((m) & T_D_KILOBYTES) == T_D_KILOBYTES)
25 #define DISPLAY_MEGABYTES(m) (((m) & T_D_MEGABYTES) == T_D_MEGABYTES)
26 #define DISPLAY_OMIT_SINCE_BOOT(m) (((m) & T_D_OMIT_SINCE_BOOT) == T_D_OMIT_SINCE_BOOT)
27 #define DISPLAY_ISO(m) (((m) & T_D_ISO) == T_D_ISO)
28 #define DISPLAY_ZERO_OMIT(m) (((m) & T_D_ZERO_OMIT) == T_D_ZERO_OMIT)
29 #define DISPLAY_UNIT(m) (((m) & T_D_UNIT) == T_D_UNIT)
32 TAPE_STATS_INVALID = 0,
36 #define SYSFS_CLASS_TAPE_DIR PRE "/sys/class/scsi_tape"
37 #define TAPE_STAT_PATH PRE "/sys/class/scsi_tape/st%i/stats/"
39 #define TAPE_STAT_FILE_VAL(A, B) \
40 snprintf(filename, MAXPATHLEN, A, i); \
41 if ((fp = fopen(filename, "r")) != NULL) { \
42 if (fscanf(fp, "%"PRId64, &tape_new_stats[i].B) != 1) { \
43 tape_new_stats[i].valid = TAPE_STATS_INVALID; \
47 tape_new_stats[i].valid = TAPE_STATS_INVALID; \
53 * A - tape_stats structure member name, e.g. read_count
54 * B - calc_stats structure member name, e.g. reads_per_second
56 * These macros are not selfcontained they depend on some other
57 * variables defined either as global or local to the function.
60 #define CALC_STAT_CNT(A, B) \
61 if ((tape_new_stats[i].A == tape_old_stats[i].A) || \
65 temp = (double) (tape_new_stats[i].A - \
66 tape_old_stats[i].A) \
67 / (((double) duration) / 1000); \
68 stats->B = (uint64_t) temp; \
70 #define CALC_STAT_KB(A, B) \
71 if ((tape_new_stats[i].A == tape_old_stats[i].A) || \
75 temp = (double) (tape_new_stats[i].A - \
76 tape_old_stats[i].A) \
77 / (((double) duration) / 1000.0); \
78 stats->B = (uint64_t) (temp / 1024.0); \
81 #define TAPE_MAX_PCT 999
83 #define CALC_STAT_PCT(A, B) \
84 if ((tape_new_stats[i].A == tape_old_stats[i].A) || \
88 temp = (double) (tape_new_stats[i].A - \
89 tape_old_stats[i].A) \
90 / (((double) duration)); \
91 stats->B = (uint64_t) (100.0 * temp / 1000000.0); \
92 if (stats->B > TAPE_MAX_PCT) \
93 stats->B = TAPE_MAX_PCT; \
101 uint64_t write_bytes;
103 uint64_t write_count;
104 uint64_t other_count;
105 uint64_t resid_count;
110 uint64_t reads_per_second;
111 uint64_t writes_per_second;
112 uint64_t other_per_second;
113 uint64_t kbytes_read_per_second;
114 uint64_t kbytes_written_per_second;
115 uint64_t read_pct_wait;
116 uint64_t write_pct_wait;
117 uint64_t all_pct_wait;
118 uint64_t resids_per_second;
121 void tape_get_updated_stats(void);
122 void tape_gather_initial_stats(void);
123 void tape_check_tapes_and_realloc(void);
124 int get_max_tape_drives(void);
125 void tape_uninitialise(void);
126 void tape_initialise(void);
127 void tape_calc_one_stats(struct calc_stats *, int);
128 void tape_write_headings(void);
129 void tape_write_stats(struct calc_stats *, int);
131 #endif /* _TAPESTAT_H */