[PATCH] blkparse: fix remap sectors dump, it was in kb
[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"
d0ca268b 9
71d5d4c9
JA
10#define MINORBITS 20
11#define MINORMASK ((1U << MINORBITS) - 1)
12#define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
13#define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
14
15#define SECONDS(x) ((unsigned long long)(x) / 1000000000)
16#define NANO_SECONDS(x) ((unsigned long long)(x) % 1000000000)
17#define DOUBLE_TO_NANO_ULL(d) ((unsigned long long)((d) * 1000000000))
18
19#define min(a, b) ((a) < (b) ? (a) : (b))
20
ae957cbc
JA
21#define t_sec(t) ((t)->bytes >> 9)
22#define t_kb(t) ((t)->bytes >> 10)
23
bf0720af
JA
24typedef __u32 u32;
25typedef __u8 u8;
26
71d5d4c9
JA
27struct io_stats {
28 unsigned long qreads, qwrites, creads, cwrites, mreads, mwrites;
29 unsigned long ireads, iwrites;
30 unsigned long long qread_kb, qwrite_kb, cread_kb, cwrite_kb;
31 unsigned long long iread_kb, iwrite_kb;
32 unsigned long io_unplugs, timer_unplugs;
33};
34
35struct per_cpu_info {
e820abd7
JA
36 unsigned int cpu;
37 unsigned int nelems;
71d5d4c9
JA
38
39 int fd;
40 char fname[128];
41
42 struct io_stats io_stats;
43};
44
45extern FILE *ofp;
46
d0ca268b 47#define CHECK_MAGIC(t) (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
e7c9f3ff 48#define SUPPORTED_VERSION (0x05)
d0ca268b 49
1e3c4225 50#if __BYTE_ORDER == __LITTLE_ENDIAN
6fe4709e
JA
51#define be16_to_cpu(x) __bswap_16(x)
52#define be32_to_cpu(x) __bswap_32(x)
53#define be64_to_cpu(x) __bswap_64(x)
54#define cpu_to_be16(x) __bswap_16(x)
55#define cpu_to_be32(x) __bswap_32(x)
56#define cpu_to_be64(x) __bswap_64(x)
ffcf46d8 57#elif __BYTE_ORDER == __BIG_ENDIAN
6fe4709e
JA
58#define be16_to_cpu(x) (x)
59#define be32_to_cpu(x) (x)
60#define be64_to_cpu(x) (x)
61#define cpu_to_be16(x) (x)
62#define cpu_to_be32(x) (x)
63#define cpu_to_be64(x) (x)
64#else
65#error "Bad arch"
66#endif
67
68static inline int verify_trace(struct blk_io_trace *t)
69{
70 if (!CHECK_MAGIC(t)) {
71 fprintf(stderr, "bad trace magic %x\n", t->magic);
72 return 1;
73 }
74 if ((t->magic & 0xff) != SUPPORTED_VERSION) {
75 fprintf(stderr, "unsupported trace version %x\n",
76 t->magic & 0xff);
77 return 1;
78 }
d0ca268b 79
6fe4709e
JA
80 return 0;
81}
d0ca268b 82
6fe4709e
JA
83static inline void trace_to_be(struct blk_io_trace *t)
84{
85 t->magic = cpu_to_be32(t->magic);
86 t->sequence = cpu_to_be32(t->sequence);
87 t->time = cpu_to_be64(t->time);
88 t->sector = cpu_to_be64(t->sector);
89 t->bytes = cpu_to_be32(t->bytes);
90 t->action = cpu_to_be32(t->action);
91 t->pid = cpu_to_be32(t->pid);
654aaa52 92 t->cpu = cpu_to_be32(t->cpu);
6fe4709e
JA
93 t->error = cpu_to_be16(t->error);
94 t->pdu_len = cpu_to_be16(t->pdu_len);
e7c9f3ff 95 t->device = cpu_to_be32(t->device);
654aaa52 96 /* t->comm is a string (endian neutral) */
6fe4709e 97}
d0ca268b 98
6fe4709e
JA
99static inline void trace_to_cpu(struct blk_io_trace *t)
100{
101 t->magic = be32_to_cpu(t->magic);
102 t->sequence = be32_to_cpu(t->sequence);
103 t->time = be64_to_cpu(t->time);
104 t->sector = be64_to_cpu(t->sector);
105 t->bytes = be32_to_cpu(t->bytes);
106 t->action = be32_to_cpu(t->action);
107 t->pid = be32_to_cpu(t->pid);
654aaa52 108 t->cpu = be32_to_cpu(t->cpu);
6fe4709e
JA
109 t->error = be16_to_cpu(t->error);
110 t->pdu_len = be16_to_cpu(t->pdu_len);
e7c9f3ff 111 t->device = be32_to_cpu(t->device);
654aaa52 112 /* t->comm is a string (endian neutral) */
6fe4709e 113}
d0ca268b 114
71d5d4c9
JA
115extern void set_all_format_specs(char *);
116extern int add_format_spec(char *);
117extern void process_fmt(char *, struct per_cpu_info *, struct blk_io_trace *,
118 unsigned long long, int, unsigned char *);
98f8386b
AB
119extern int valid_act_opt(int);
120extern int find_mask_map(char *);
71d5d4c9 121
d0ca268b 122#endif