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