]> granicus.if.org Git - sysstat/blob - tapestat.h
Update non regression tests
[sysstat] / tapestat.h
1 /*
2  * tapestat: report tape statistics
3  * (C) 2015 Hewlett-Packard Development Company, L.P.
4  *
5  * Initial revision by Shane M. SEYMOUR (shane.seymour <at> hpe.com)
6  * Modified for sysstat by Sebastien GODARD (sysstat <at> orange.fr)
7  */
8
9 #ifndef _TAPESTAT_H
10 #define _TAPESTAT_H
11
12 #include "common.h"
13
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
22
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)
30
31 enum {
32         TAPE_STATS_INVALID = 0,
33         TAPE_STATS_VALID   = 1
34 };
35
36 #define SYSFS_CLASS_TAPE_DIR    PRE "/sys/class/scsi_tape"
37 #define TAPE_STAT_PATH          PRE "/sys/class/scsi_tape/st%i/stats/"
38
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;   \
44                 }                                                       \
45                 fclose(fp);                                             \
46         } else {                                                        \
47                 tape_new_stats[i].valid = TAPE_STATS_INVALID;           \
48                 continue;                                               \
49         }
50
51
52 /*
53  * A - tape_stats structure member name, e.g. read_count
54  * B - calc_stats structure member name, e.g. reads_per_second
55  *
56  * These macros are not selfcontained they depend on some other
57  * variables defined either as global or local to the function.
58  */
59
60 #define CALC_STAT_CNT(A, B)                                     \
61         if ((tape_new_stats[i].A == tape_old_stats[i].A) ||     \
62                 (duration <= 0)) {                              \
63                 stats->B = 0;                                   \
64         } else {                                                \
65                 temp = (double) (tape_new_stats[i].A -          \
66                         tape_old_stats[i].A)                    \
67                         / (((double) duration) / 1000);         \
68                 stats->B = (uint64_t) temp;                     \
69         }
70 #define CALC_STAT_KB(A, B)                                      \
71         if ((tape_new_stats[i].A == tape_old_stats[i].A) ||     \
72                 (duration <= 0)) {                              \
73                 stats->B = 0;                                   \
74         } else {                                                \
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);          \
79         }
80
81 #define TAPE_MAX_PCT 999
82
83 #define CALC_STAT_PCT(A, B)                                             \
84         if ((tape_new_stats[i].A == tape_old_stats[i].A) ||             \
85                 (duration <= 0)) {                                      \
86                 stats->B = 0;                                           \
87         } else {                                                        \
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;                                \
94         }
95
96 struct tape_stats {
97         uint64_t read_time;
98         uint64_t write_time;
99         uint64_t other_time;
100         uint64_t read_bytes;
101         uint64_t write_bytes;
102         uint64_t read_count;
103         uint64_t write_count;
104         uint64_t other_count;
105         uint64_t resid_count;
106         char valid;
107         struct timeval tv;
108 };
109 struct calc_stats {
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;
119 };
120
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);
130
131 #endif  /* _TAPESTAT_H */