2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 const char *IO_op[] = {
37 #define MAX(A, B) ((A) > (B) ? (A) : (B))
38 #define MIN(A, B) ((A) < (B) ? (A) : (B))
40 #define MINBUFLEN (16*1024)
42 #define FILE_DB_HASHSIZE 8192
51 struct files_db_s *next;
54 struct files_db_handle {
55 struct files_db_s *files_db_buckets[FILE_DB_HASHSIZE];
58 struct IO_operation_s {
64 u_int64_t bytes_written;
68 files_db_update_size(void *node, u_int64_t new_size)
70 struct files_db_s *db_node = (struct files_db_s *)node;
72 if (db_node->size < new_size)
73 db_node->size = new_size;
77 files_db_update_filename(void *node, char *filename)
79 ((struct files_db_s *)node)->filename = strdup(filename);
83 files_db_get_fileno(void *node)
85 return (((struct files_db_s *)node)->fileno);
89 files_db_get_fd(void *node)
91 return (((struct files_db_s *)node)->fd);
95 files_db_get_filename(void *node)
97 return (((struct files_db_s *)node)->filename);
101 files_db_readonly(void *node)
103 return (((struct files_db_s *)node)->readonly);
106 static inline u_int64_t
107 get_msecs(struct timeval *tv)
109 return ((tv->tv_sec * 1000) + (tv->tv_usec / 1000));
112 static inline u_int64_t
113 get_usecs(struct timeval *tv)
115 return (tv->tv_usec % 1000);
119 update_delta_time(struct timeval *start,
120 struct timeval *destination)
122 struct timeval res, finish;
124 (void)gettimeofday(&finish, (struct timezone *)NULL);
125 timersub(&finish, start, &res);
126 timeradd(destination, &res, &finish);
127 *destination = finish;
130 void *files_db_create_handle(void);
131 void *files_db_lookup_byfileno(void *handle, int fileno);
132 void *files_db_add_byfileno(void *handle, int fileno, int readonly);
133 void files_db_update_fd(void *node, int fd);
134 void files_db_unlink_files(void *db_handle);
135 void files_db_close_files(void *handle);
136 void files_db_close_fd(void *node);
137 void files_db_free_memory(void *handle);
138 void create_file(char *path, size_t size,
139 struct rw_bytes_s *rw_bytes);
140 char *get_buf(char **buf, int *buflen, int len, int do_fill);
141 void files_db_fsync_discard_files(void *handle);
142 void print_op_stats(u_int64_t *op_counts);
143 void print_bytes(char *desc, struct rw_bytes_s *rw_bytes);
144 void ioshark_handle_mmap(void *db_node,
145 struct ioshark_file_operation *file_op,
146 char **bufp, int *buflen, u_int64_t *op_counts,
147 struct rw_bytes_s *rw_bytes);
148 void capture_util_state_before(void);
149 void report_cpu_disk_util(void);
151 char *get_ro_filename(int ix);
152 void init_filename_cache(void);
153 void free_filename_cache(void);
154 int is_readonly_mount(char *filename, size_t size);