-
Notifications
You must be signed in to change notification settings - Fork 28
/
twrBin.h
70 lines (57 loc) · 1.51 KB
/
twrBin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* format
*
* struct {
* int32_t real_time;
* int64_t obj_id;
* int32_t key_size:10;
* int32_t value_size:22;
* int32_t op:8;
* int32_t ttl:24;
*
* }
*
*/
#pragma once
#include "../../include/libCacheSim/reader.h"
#include "binaryUtils.h"
#ifdef __cplusplus
extern "C" {
#endif
static inline int twrReader_setup(reader_t *reader) {
reader->trace_type = TWR_TRACE;
reader->trace_format = BINARY_TRACE_FORMAT;
reader->item_size = 20;
reader->n_total_req = (uint64_t)reader->file_size / (reader->item_size);
reader->obj_id_is_num = true;
return 0;
}
static int twr_read_one_req(reader_t *reader, request_t *req) {
char *record = read_bytes(reader);
if (record == NULL) {
req->valid = FALSE;
return 1;
}
req->clock_time = *(uint32_t *)record;
req->obj_id = *(uint64_t *)(record + 4);
uint32_t kv_size = *(uint32_t *)(record + 12);
uint32_t op_ttl = *(uint32_t *)(record + 16);
uint32_t key_size = (kv_size >> 22) & (0x00000400 - 1);
uint32_t val_size = kv_size & (0x00400000 - 1);
uint32_t op = ((op_ttl >> 24) & (0x00000100 - 1));
uint32_t ttl = op_ttl & (0x01000000 - 1);
req->key_size = key_size;
req->val_size = val_size;
req->obj_size = key_size + val_size;
req->op = (req_op_e)(op);
req->ttl = (int32_t)ttl;
if (req->val_size == 0 && reader->ignore_size_zero_req &&
(req->op == OP_GET || req->op == OP_GETS) &&
reader->read_direction == READ_FORWARD) {
return twr_read_one_req(reader, req);
}
return 0;
}
#ifdef __cplusplus
}
#endif