2 * 2008+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <sys/types.h>
18 #include <sys/socket.h>
31 #include "elliptics/packet.h"
32 #include "elliptics/interface.h"
36 static int hparser_region_match(struct dnet_history_entry
*e
,
37 unsigned long long offset
, unsigned long long size
)
39 if ((e
->offset
> offset
) && (e
->offset
< offset
+ size
))
42 if ((e
->offset
< offset
) && (e
->offset
+ e
->size
> offset
))
48 static void hparser_usage(const char *p
)
50 fprintf(stderr
, "Usage: %s args\n", p
);
51 fprintf(stderr
, " -f file - history file to parse\n"
52 " -d - history database to parse\n"
53 " -o offset - offset of the region to highlight\n"
54 " -s size - size of the region to highlight\n"
59 static void hparser_dump_history(struct dnet_history_map
*m
, unsigned long long offset
,
60 unsigned long long size
)
65 char id_str
[DNET_ID_SIZE
*2 + 1];
67 for (i
=m
->num
-1; i
>=0; --i
) {
68 struct dnet_history_entry e
= m
->ent
[i
];
71 dnet_convert_history_entry(&e
);
75 strftime(str
, sizeof(str
), "%F %R:%S", &tm
);
77 printf("%s.%09llu: %s: flags: %08x [removed: %s], offset: %8llu, size: %8llu: %c\n",
78 str
, (unsigned long long)e
.tnsec
,
79 dnet_dump_id_len_raw(e
.id
, DNET_ID_SIZE
, id_str
), e
.flags
,
80 (e
.flags
& DNET_IO_FLAGS_REMOVED
) ? "yes" : "no",
81 (unsigned long long)e
.offset
, (unsigned long long)e
.size
,
82 hparser_region_match(&e
, offset
, size
) ? '+' : '-');
87 int main(int argc
, char *argv
[])
89 struct dnet_history_map m
;
91 char *file
= NULL
, *database
= NULL
;
92 unsigned long long offset
, size
;
96 while ((ch
= getopt(argc
, argv
, "s:o:f:d:h")) != -1) {
99 size
= strtoull(optarg
, NULL
, 0);
102 offset
= strtoull(optarg
, NULL
, 0);
111 hparser_usage(argv
[0]);
115 if (!file
&& !database
) {
116 fprintf(stderr
, "You have to provide history file or database to parse.\n");
117 hparser_usage(argv
[0]);
121 err
= dnet_map_history(NULL
, file
, &m
);
123 fprintf(stderr
, "Failed to map history file '%s': %d.\n", file
, err
);
127 printf("%s: objects: %ld, range: %llu-%llu, counting from the most recent (nanoseconds resolution).\n",
128 file
, m
.num
, offset
, offset
+size
);
130 hparser_dump_history(&m
, offset
, size
);
132 dnet_unmap_history(NULL
, &m
);
136 printf("not yet supported\n");