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
50 struct files_db_s *next;
53 struct files_db_handle {
54 struct files_db_s *files_db_buckets[FILE_DB_HASHSIZE];
57 struct IO_operation_s {
63 u_int64_t bytes_written;
67 files_db_update_size(void *node, u_int64_t new_size)
69 struct files_db_s *db_node = (struct files_db_s *)node;
71 if (db_node->size < new_size)
72 db_node->size = new_size;
76 files_db_update_filename(void *node, char *filename)
78 ((struct files_db_s *)node)->filename = strdup(filename);
82 files_db_get_fileno(void *node)
84 return (((struct files_db_s *)node)->fileno);
88 files_db_get_fd(void *node)
90 return (((struct files_db_s *)node)->fd);
94 files_db_get_filename(void *node)
96 return (((struct files_db_s *)node)->filename);
99 static inline u_int64_t
100 get_msecs(struct timeval *tv)
102 return ((tv->tv_sec * 1000) + (tv->tv_usec / 1000));
105 static inline u_int64_t
106 get_usecs(struct timeval *tv)
108 return (tv->tv_usec % 1000);
112 update_delta_time(struct timeval *start,
113 struct timeval *destination)
115 struct timeval res, finish;
117 (void)gettimeofday(&finish, (struct timezone *)NULL);
118 timersub(&finish, start, &res);
119 timeradd(destination, &res, &finish);
120 *destination = finish;
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);