[PATCH] blkparse: Add option to hash process by name
[blktrace.git] / blktrace.h
1 #ifndef BLKTRACE_H
2 #define BLKTRACE_H
3
4 #include <byteswap.h>
5 #include <asm/types.h>
6 #include <asm/byteorder.h>
7 #include "blktrace_api.h"
8
9 #define MINORBITS       20
10 #define MINORMASK       ((1U << MINORBITS) - 1)
11 #define MAJOR(dev)      ((unsigned int) ((dev) >> MINORBITS))
12 #define MINOR(dev)      ((unsigned int) ((dev) & MINORMASK))
13
14 #define SECONDS(x)              ((unsigned long long)(x) / 1000000000)
15 #define NANO_SECONDS(x)         ((unsigned long long)(x) % 1000000000)
16 #define DOUBLE_TO_NANO_ULL(d)   ((unsigned long long)((d) * 1000000000))
17
18 #define min(a, b)       ((a) < (b) ? (a) : (b))
19
20 typedef __u32 u32;
21 typedef __u8 u8;
22
23 struct io_stats {
24         unsigned long qreads, qwrites, creads, cwrites, mreads, mwrites;
25         unsigned long ireads, iwrites;
26         unsigned long long qread_kb, qwrite_kb, cread_kb, cwrite_kb;
27         unsigned long long iread_kb, iwrite_kb;
28         unsigned long io_unplugs, timer_unplugs;
29 };
30
31 struct per_cpu_info {
32         int cpu;
33         int nelems;
34
35         int fd;
36         char fname[128];
37
38         struct io_stats io_stats;
39 };
40
41 extern FILE *ofp;
42
43 #define CHECK_MAGIC(t)          (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
44 #define SUPPORTED_VERSION       (0x05)
45
46 #if defined(__LITTLE_ENDIAN_BITFIELD)
47 #define be16_to_cpu(x)          __bswap_16(x)
48 #define be32_to_cpu(x)          __bswap_32(x)
49 #define be64_to_cpu(x)          __bswap_64(x)
50 #define cpu_to_be16(x)          __bswap_16(x)
51 #define cpu_to_be32(x)          __bswap_32(x)
52 #define cpu_to_be64(x)          __bswap_64(x)
53 #elif defined(__BIG_ENDIAN_BITFIELD)
54 #define be16_to_cpu(x)          (x)
55 #define be32_to_cpu(x)          (x)
56 #define be64_to_cpu(x)          (x)
57 #define cpu_to_be16(x)          (x)
58 #define cpu_to_be32(x)          (x)
59 #define cpu_to_be64(x)          (x)
60 #else
61 #error "Bad arch"
62 #endif
63
64 static inline int verify_trace(struct blk_io_trace *t)
65 {
66         if (!CHECK_MAGIC(t)) {
67                 fprintf(stderr, "bad trace magic %x\n", t->magic);
68                 return 1;
69         }
70         if ((t->magic & 0xff) != SUPPORTED_VERSION) {
71                 fprintf(stderr, "unsupported trace version %x\n", 
72                         t->magic & 0xff);
73                 return 1;
74         }
75
76         return 0;
77 }
78
79 static inline void trace_to_be(struct blk_io_trace *t)
80 {
81         t->magic        = cpu_to_be32(t->magic);
82         t->sequence     = cpu_to_be32(t->sequence);
83         t->time         = cpu_to_be64(t->time);
84         t->sector       = cpu_to_be64(t->sector);
85         t->bytes        = cpu_to_be32(t->bytes);
86         t->action       = cpu_to_be32(t->action);
87         t->pid          = cpu_to_be32(t->pid);
88         t->cpu          = cpu_to_be32(t->cpu);
89         t->error        = cpu_to_be16(t->error);
90         t->pdu_len      = cpu_to_be16(t->pdu_len);
91         t->device       = cpu_to_be32(t->device);
92         /* t->comm is a string (endian neutral) */
93 }
94
95 static inline void trace_to_cpu(struct blk_io_trace *t)
96 {
97         t->magic        = be32_to_cpu(t->magic);
98         t->sequence     = be32_to_cpu(t->sequence);
99         t->time         = be64_to_cpu(t->time);
100         t->sector       = be64_to_cpu(t->sector);
101         t->bytes        = be32_to_cpu(t->bytes);
102         t->action       = be32_to_cpu(t->action);
103         t->pid          = be32_to_cpu(t->pid);
104         t->cpu          = be32_to_cpu(t->cpu);
105         t->error        = be16_to_cpu(t->error);
106         t->pdu_len      = be16_to_cpu(t->pdu_len);
107         t->device       = be32_to_cpu(t->device);
108         /* t->comm is a string (endian neutral) */
109 }
110
111 extern void set_all_format_specs(char *);
112 extern int add_format_spec(char *);
113 extern void process_fmt(char *, struct per_cpu_info *, struct blk_io_trace *,
114                         unsigned long long, int, unsigned char *);
115
116 #endif