OSDN Git Service

Merge "Add libbase dependency for recovery_test/boot_control_copy" am: a284424d6c...
[android-x86/system-extras.git] / ioshark / ioshark_bench.h
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifdef IOSHARK_MAIN
18 const char *IO_op[] = {
19         "LSEEK",
20         "LLSEEK",
21         "PREAD64",
22         "PWRITE64",
23         "READ",
24         "WRITE",
25         "MMAP",
26         "MMAP2",
27         "OPEN",
28         "FSYNC",
29         "FDATASYNC",
30         "CLOSE",
31         "MAPPED_PREAD",
32         "MAPPED_PWRITE",
33         "MAX_FILE_OP"
34 };
35 #endif
36
37 #define MAX(A, B)       ((A) > (B) ? (A) : (B))
38 #define MIN(A, B)       ((A) < (B) ? (A) : (B))
39
40 #define MINBUFLEN       (16*1024)
41
42 #define FILE_DB_HASHSIZE        8192
43
44 struct files_db_s {
45         char *filename;
46         int fileno;
47         size_t  size;
48         int fd;
49         int debug_open_flags;
50         struct files_db_s *next;
51 };
52
53 struct files_db_handle {
54         struct files_db_s *files_db_buckets[FILE_DB_HASHSIZE];
55 };
56
57 struct IO_operation_s {
58         char *IO_op;
59 };
60
61 struct rw_bytes_s {
62         u_int64_t bytes_read;
63         u_int64_t bytes_written;
64 };
65
66 static inline void
67 files_db_update_size(void *node, u_int64_t new_size)
68 {
69         struct files_db_s *db_node = (struct files_db_s *)node;
70
71         if (db_node->size < new_size)
72                 db_node->size = new_size;
73 }
74
75 static inline void
76 files_db_update_filename(void *node, char *filename)
77 {
78         ((struct files_db_s *)node)->filename = strdup(filename);
79 }
80
81 static inline int
82 files_db_get_fileno(void *node)
83 {
84         return (((struct files_db_s *)node)->fileno);
85 }
86
87 static inline int
88 files_db_get_fd(void *node)
89 {
90         return (((struct files_db_s *)node)->fd);
91 }
92
93 static inline char *
94 files_db_get_filename(void *node)
95 {
96         return (((struct files_db_s *)node)->filename);
97 }
98
99 static inline u_int64_t
100 get_msecs(struct timeval *tv)
101 {
102         return ((tv->tv_sec * 1000) + (tv->tv_usec / 1000));
103 }
104
105 static inline u_int64_t
106 get_usecs(struct timeval *tv)
107 {
108         return (tv->tv_usec % 1000);
109 }
110
111 static inline void
112 update_delta_time(struct timeval *start,
113                   struct timeval *destination)
114 {
115         struct timeval res, finish;
116
117         (void)gettimeofday(&finish, (struct timezone *)NULL);
118         timersub(&finish, start, &res);
119         timeradd(destination, &res, &finish);
120         *destination = finish;
121 }
122
123 void *files_db_create_handle(void);
124 void *files_db_lookup_byfileno(void *handle, int fileno);
125 void *files_db_add_byfileno(void *handle, int fileno);
126 void files_db_update_fd(void *node, int fd);
127 void files_db_unlink_files(void *db_handle);
128 void files_db_close_files(void *handle);
129 void files_db_close_fd(void *node);
130 void files_db_free_memory(void *handle);
131 void create_file(char *path, size_t size,
132                  struct rw_bytes_s *rw_bytes);
133 char *get_buf(char **buf, int *buflen, int len, int do_fill);
134 void files_db_fsync_discard_files(void *handle);
135 void print_op_stats(u_int64_t *op_counts);
136 void print_bytes(char *desc, struct rw_bytes_s *rw_bytes);
137 void ioshark_handle_mmap(void *db_node,
138                          struct ioshark_file_operation *file_op,
139                          char **bufp, int *buflen, u_int64_t *op_counts,
140                          struct rw_bytes_s *rw_bytes);
141 void capture_util_state_before(void);
142 void report_cpu_disk_util(void);
143
144
145
146
147
148
149
150
151
152
153