btreplay/btrecord man pages
[blktrace.git] / blktrace.h
CommitLineData
6fe4709e
JA
1#ifndef BLKTRACE_H
2#define BLKTRACE_H
d0ca268b 3
98f8386b 4#include <stdio.h>
6fe4709e 5#include <byteswap.h>
1e3c4225
JA
6#include <endian.h>
7
6fe4709e 8#include "blktrace_api.h"
210824c3 9#include "rbtree.h"
d0ca268b 10
71d5d4c9
JA
11#define MINORBITS 20
12#define MINORMASK ((1U << MINORBITS) - 1)
13#define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
14#define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
15
16#define SECONDS(x) ((unsigned long long)(x) / 1000000000)
17#define NANO_SECONDS(x) ((unsigned long long)(x) % 1000000000)
18#define DOUBLE_TO_NANO_ULL(d) ((unsigned long long)((d) * 1000000000))
19
20#define min(a, b) ((a) < (b) ? (a) : (b))
6a6d3f0f 21#define max(a, b) ((a) > (b) ? (a) : (b))
71d5d4c9 22
ae957cbc
JA
23#define t_sec(t) ((t)->bytes >> 9)
24#define t_kb(t) ((t)->bytes >> 10)
25
bf0720af
JA
26typedef __u32 u32;
27typedef __u8 u8;
28
71d5d4c9
JA
29struct io_stats {
30 unsigned long qreads, qwrites, creads, cwrites, mreads, mwrites;
4054070a 31 unsigned long ireads, iwrites, rrqueue, wrqueue;
71d5d4c9
JA
32 unsigned long long qread_kb, qwrite_kb, cread_kb, cwrite_kb;
33 unsigned long long iread_kb, iwrite_kb;
fb2ec796 34 unsigned long long mread_kb, mwrite_kb;
71d5d4c9
JA
35 unsigned long io_unplugs, timer_unplugs;
36};
37
38struct per_cpu_info {
e820abd7
JA
39 unsigned int cpu;
40 unsigned int nelems;
71d5d4c9
JA
41
42 int fd;
c0e0dbc2 43 int fdblock;
71d5d4c9
JA
44 char fname[128];
45
46 struct io_stats io_stats;
210824c3
JA
47
48 struct rb_root rb_last;
49 unsigned long rb_last_entries;
50 unsigned long last_sequence;
51 unsigned long smallest_seq_read;
66930177
JA
52
53 struct skip_info *skips_head;
54 struct skip_info *skips_tail;
71d5d4c9
JA
55};
56
57extern FILE *ofp;
017d1660 58extern int data_is_native;
7bd4fd0a 59extern struct timespec abs_start_time;
71d5d4c9 60
d0ca268b 61#define CHECK_MAGIC(t) (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
bfc70ad5 62#define SUPPORTED_VERSION (0x07)
d0ca268b 63
1e3c4225 64#if __BYTE_ORDER == __LITTLE_ENDIAN
6fe4709e
JA
65#define be16_to_cpu(x) __bswap_16(x)
66#define be32_to_cpu(x) __bswap_32(x)
67#define be64_to_cpu(x) __bswap_64(x)
68#define cpu_to_be16(x) __bswap_16(x)
69#define cpu_to_be32(x) __bswap_32(x)
70#define cpu_to_be64(x) __bswap_64(x)
ffcf46d8 71#elif __BYTE_ORDER == __BIG_ENDIAN
6fe4709e
JA
72#define be16_to_cpu(x) (x)
73#define be32_to_cpu(x) (x)
74#define be64_to_cpu(x) (x)
75#define cpu_to_be16(x) (x)
76#define cpu_to_be32(x) (x)
77#define cpu_to_be64(x) (x)
78#else
79#error "Bad arch"
80#endif
81
82static inline int verify_trace(struct blk_io_trace *t)
83{
84 if (!CHECK_MAGIC(t)) {
85 fprintf(stderr, "bad trace magic %x\n", t->magic);
86 return 1;
87 }
88 if ((t->magic & 0xff) != SUPPORTED_VERSION) {
89 fprintf(stderr, "unsupported trace version %x\n",
90 t->magic & 0xff);
91 return 1;
92 }
d0ca268b 93
6fe4709e
JA
94 return 0;
95}
d0ca268b 96
6fe4709e
JA
97static inline void trace_to_cpu(struct blk_io_trace *t)
98{
017d1660
JA
99 if (data_is_native)
100 return;
101
6fe4709e
JA
102 t->magic = be32_to_cpu(t->magic);
103 t->sequence = be32_to_cpu(t->sequence);
104 t->time = be64_to_cpu(t->time);
105 t->sector = be64_to_cpu(t->sector);
106 t->bytes = be32_to_cpu(t->bytes);
107 t->action = be32_to_cpu(t->action);
108 t->pid = be32_to_cpu(t->pid);
bfc70ad5
JA
109 t->device = be32_to_cpu(t->device);
110 t->cpu = be16_to_cpu(t->cpu);
6fe4709e
JA
111 t->error = be16_to_cpu(t->error);
112 t->pdu_len = be16_to_cpu(t->pdu_len);
113}
d0ca268b 114
017d1660
JA
115/*
116 * check whether data is native or not
117 */
e5413c3c 118static inline int check_data_endianness(u32 magic)
017d1660 119{
e5413c3c 120 if ((magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) {
017d1660
JA
121 data_is_native = 1;
122 return 0;
123 }
124
e5413c3c 125 magic = __bswap_32(magic);
017d1660 126 if ((magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) {
017d1660
JA
127 data_is_native = 0;
128 return 0;
129 }
130
131 return 1;
132}
133
71d5d4c9
JA
134extern void set_all_format_specs(char *);
135extern int add_format_spec(char *);
136extern void process_fmt(char *, struct per_cpu_info *, struct blk_io_trace *,
137 unsigned long long, int, unsigned char *);
98f8386b
AB
138extern int valid_act_opt(int);
139extern int find_mask_map(char *);
bfc70ad5 140extern char *find_process_name(pid_t);
71d5d4c9 141
d0ca268b 142#endif