Home | History | Annotate | Download | only in ioshark
      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 #define FILE_DB_HASHSIZE	8192
     18 
     19 struct files_db_s {
     20 	char *filename;
     21 	int fileno;
     22 	struct files_db_s *next;
     23 	size_t	size;
     24 	int	global_filename_ix;
     25 };
     26 
     27 /* Lifted from Wikipedia Jenkins Hash function page */
     28 static inline u_int32_t
     29 jenkins_one_at_a_time_hash(char *key, size_t len)
     30 {
     31 	u_int32_t hash, i;
     32 
     33 	for(hash = i = 0; i < len; ++i) {
     34 		hash += key[i];
     35 		hash += (hash << 10);
     36 		hash ^= (hash >> 6);
     37 	}
     38 	hash += (hash << 3);
     39 	hash ^= (hash >> 11);
     40 	hash += (hash << 15);
     41 	return hash;
     42 }
     43 
     44 static inline void
     45 files_db_update_size(void *node, u_int64_t new_size)
     46 {
     47 	struct files_db_s *db_node = (struct files_db_s *)node;
     48 
     49 	if (db_node->size < new_size)
     50 		db_node->size = new_size;
     51 }
     52 
     53 static inline void
     54 files_db_add_to_size(void *node, u_int64_t size_incr)
     55 {
     56 	((struct files_db_s *)node)->size += size_incr;
     57 }
     58 
     59 static inline int
     60 files_db_get_fileno(void *node)
     61 {
     62 	return (((struct files_db_s *)node)->fileno);
     63 }
     64 
     65 static inline char *
     66 files_db_get_filename(void *node)
     67 {
     68 	return (((struct files_db_s *)node)->filename);
     69 }
     70 
     71 void *files_db_create_handle(void);
     72 void files_db_write_objects(FILE *fp);
     73 void *files_db_add(char *filename);
     74 void *files_db_lookup(char *filename);
     75 int files_db_get_total_obj(void);
     76 void init_filename_cache(void);
     77 void store_filename_cache(void);
     78 
     79 int ioshark_write_header(FILE *fp, struct ioshark_header *header);
     80 int ioshark_write_file_state(FILE *fp, struct ioshark_file_state *state);
     81 int ioshark_write_file_op(FILE *fp, struct ioshark_file_operation *file_op);
     82