Changes in benchmark/io/http/filecache.cfa [d9c2284:0aec496]
- File:
-
- 1 edited
-
benchmark/io/http/filecache.cfa (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/filecache.cfa
rd9c2284 r0aec496 56 56 } 57 57 58 static inline [unsigned size, char unit] human_size( size_t size ) {59 int idx = 0;60 static char units [] = { ' ', 'K', 'M', 'G', 'T' };61 while( size >= 1024 ) {62 idx++;63 size /= 1024;64 if(idx >= 5) {65 abort("File too large to print\n");66 }67 }68 69 return [size, units[idx]];70 }71 58 72 59 struct { … … 82 69 83 70 [int fd, size_t size] get_file( * const char file, size_t len ) { 84 uint32_t idx = murmur3_32( (const uint8_t *)file, len, options. file_cache.hash_seed ) % file_cache.size;71 uint32_t idx = murmur3_32( (const uint8_t *)file, len, options.hash_seed ) % file_cache.size; 85 72 86 73 for(int i = 0;; i++) { … … 99 86 100 87 int put_file( cache_line & entry ) { 101 uint32_t idx = murmur3_32( (const uint8_t *)entry.file, strlen(entry.file), options. file_cache.hash_seed ) % file_cache.size;88 uint32_t idx = murmur3_32( (const uint8_t *)entry.file, strlen(entry.file), options.hash_seed ) % file_cache.size; 102 89 103 90 int i = 0; … … 114 101 void fill_cache( const char * path ) { 115 102 int ret; 116 ret = chdir(path);117 if(ret < 0) {118 abort( "chdir error: (%d) %s\n", (int)errno, strerror(errno) );119 }120 121 103 size_t fcount = 0; 122 104 size_t fsize = 16; … … 136 118 raw[idx].file = strdup(fpath+2); 137 119 raw[idx].size = sb->st_size; 138 if( !options.file_cache.list ) { 139 raw[idx].fd = open( fpath, options.file_cache.open_flags ); 140 if(raw[idx].fd < 0) { 141 abort( "open file error: (%d) %s\n", (int)errno, strerror(errno) ); 142 } 120 raw[idx].fd = open( fpath, options.open_flags ); 121 if(raw[idx].fd < 0) { 122 abort( "open file error: (%d) %s\n", (int)errno, strerror(errno) ); 143 123 } 144 124 return 0; 145 125 } 146 126 147 ret = ftw( ".", walk, 10);127 ret = ftw(path, walk, 10); 148 128 if(ret < 0) { 149 129 abort( "ftw error: (%d) %s\n", (int)errno, strerror(errno) ); … … 155 135 156 136 // Step 2 create the cache 157 file_cache.size = options.file_cache .size > 0 ? options.file_cache.size : fsize;137 file_cache.size = options.file_cache_size > 0 ? options.file_cache_size : fsize; 158 138 if( file_cache.size < fcount ) { 159 139 abort("File Cache too small\n"); 160 140 } 161 141 162 file_cache.entries = anew(f ile_cache.size);142 file_cache.entries = anew(fsize); 163 143 164 144 // Step 3 fill the cache 165 145 int conflicts = 0; 166 146 for(i; fcount) { 147 printf("Added file %s\n", raw[i].file); 167 148 conflicts += put_file( raw[i] ); 168 149 } 169 150 printf("Filled cache from path \"%s\" with %zu files\n", path, fcount); 170 151 if( conflicts > 0 ) { 171 printf("Found %d conflicts (seed: %u)\n", conflicts, options. file_cache.hash_seed);152 printf("Found %d conflicts (seed: %u)\n", conflicts, options.hash_seed); 172 153 #if defined(REJECT_CONFLICTS) 173 154 abort("Conflicts found in the cache"); … … 175 156 } 176 157 177 if(options.file_cache.list) {178 printf("Listing files and exiting\n");179 for(i; fcount) {180 int s; char u;181 [s, u] = human_size(raw[i].size);182 printf("%4d%c - %s\n", s, u, raw[i].file);183 free(raw[i].file);184 }185 free(raw);186 adelete(file_cache.size, file_cache.entries);187 exit(0);188 }189 190 158 // Step 4 clean up 191 159 free( raw ); 192 160 } 193 194 [int *, int] filefds(int extra) {195 if(!file_cache.entries) {196 abort("File cache not filled!\n");197 }198 199 return [aalloc(extra), 0];200 }201 202 161 203 162 void close_cache() {
Note:
See TracChangeset
for help on using the changeset viewer.