Don't like btrecord against libaio and librt, as it doesn't use any of their symbols
[blktrace.git] / blktrace.h
index cd0caa836a4a59afa54f51d675f559e54007ba34..7e844ca077982a374c78c6d696f270d3010a5db7 100644 (file)
@@ -6,6 +6,7 @@
 #include <endian.h>
 
 #include "blktrace_api.h"
+#include "rbtree.h"
 
 #define MINORBITS      20
 #define MINORMASK      ((1U << MINORBITS) - 1)
@@ -17,6 +18,7 @@
 #define DOUBLE_TO_NANO_ULL(d)  ((unsigned long long)((d) * 1000000000))
 
 #define min(a, b)      ((a) < (b) ? (a) : (b))
+#define max(a, b)      ((a) > (b) ? (a) : (b))
 
 #define t_sec(t)       ((t)->bytes >> 9)
 #define t_kb(t)                ((t)->bytes >> 10)
@@ -26,9 +28,10 @@ typedef __u8 u8;
 
 struct io_stats {
        unsigned long qreads, qwrites, creads, cwrites, mreads, mwrites;
-       unsigned long ireads, iwrites;
+       unsigned long ireads, iwrites, rrqueue, wrqueue;
        unsigned long long qread_kb, qwrite_kb, cread_kb, cwrite_kb;
        unsigned long long iread_kb, iwrite_kb;
+       unsigned long long mread_kb, mwrite_kb;
        unsigned long io_unplugs, timer_unplugs;
 };
 
@@ -37,15 +40,26 @@ struct per_cpu_info {
        unsigned int nelems;
 
        int fd;
+       int fdblock;
        char fname[128];
 
        struct io_stats io_stats;
+
+       struct rb_root rb_last;
+       unsigned long rb_last_entries;
+       unsigned long last_sequence;
+       unsigned long smallest_seq_read;
+
+       struct skip_info *skips_head;
+       struct skip_info *skips_tail;
 };
 
 extern FILE *ofp;
+extern int data_is_native;
+extern struct timespec abs_start_time;
 
 #define CHECK_MAGIC(t)         (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
-#define SUPPORTED_VERSION      (0x05)
+#define SUPPORTED_VERSION      (0x07)
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 #define be16_to_cpu(x)         __bswap_16(x)
@@ -80,24 +94,11 @@ static inline int verify_trace(struct blk_io_trace *t)
        return 0;
 }
 
-static inline void trace_to_be(struct blk_io_trace *t)
-{
-       t->magic        = cpu_to_be32(t->magic);
-       t->sequence     = cpu_to_be32(t->sequence);
-       t->time         = cpu_to_be64(t->time);
-       t->sector       = cpu_to_be64(t->sector);
-       t->bytes        = cpu_to_be32(t->bytes);
-       t->action       = cpu_to_be32(t->action);
-       t->pid          = cpu_to_be32(t->pid);
-       t->cpu          = cpu_to_be32(t->cpu);
-       t->error        = cpu_to_be16(t->error);
-       t->pdu_len      = cpu_to_be16(t->pdu_len);
-       t->device       = cpu_to_be32(t->device);
-       /* t->comm is a string (endian neutral) */
-}
-
 static inline void trace_to_cpu(struct blk_io_trace *t)
 {
+       if (data_is_native)
+               return;
+
        t->magic        = be32_to_cpu(t->magic);
        t->sequence     = be32_to_cpu(t->sequence);
        t->time         = be64_to_cpu(t->time);
@@ -105,11 +106,29 @@ static inline void trace_to_cpu(struct blk_io_trace *t)
        t->bytes        = be32_to_cpu(t->bytes);
        t->action       = be32_to_cpu(t->action);
        t->pid          = be32_to_cpu(t->pid);
-       t->cpu          = be32_to_cpu(t->cpu);
+       t->device       = be32_to_cpu(t->device);
+       t->cpu          = be16_to_cpu(t->cpu);
        t->error        = be16_to_cpu(t->error);
        t->pdu_len      = be16_to_cpu(t->pdu_len);
-       t->device       = be32_to_cpu(t->device);
-       /* t->comm is a string (endian neutral) */
+}
+
+/*
+ * check whether data is native or not
+ */
+static inline int check_data_endianness(u32 magic)
+{
+       if ((magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) {
+               data_is_native = 1;
+               return 0;
+       }
+
+       magic = __bswap_32(magic);
+       if ((magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) {
+               data_is_native = 0;
+               return 0;
+       }
+
+       return 1;
 }
 
 extern void set_all_format_specs(char *);
@@ -118,5 +137,6 @@ extern void process_fmt(char *, struct per_cpu_info *, struct blk_io_trace *,
                        unsigned long long, int, unsigned char *);
 extern int valid_act_opt(int);
 extern int find_mask_map(char *);
+extern char *find_process_name(pid_t);
 
 #endif