Changes in benchmark/io/http/filecache.cfa [0aec496:d9c2284]
- File:
-
- 1 edited
-
benchmark/io/http/filecache.cfa (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/filecache.cfa
r0aec496 rd9c2284 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 } 58 71 59 72 struct { … … 69 82 70 83 [int fd, size_t size] get_file( * const char file, size_t len ) { 71 uint32_t idx = murmur3_32( (const uint8_t *)file, len, options. hash_seed ) % file_cache.size;84 uint32_t idx = murmur3_32( (const uint8_t *)file, len, options.file_cache.hash_seed ) % file_cache.size; 72 85 73 86 for(int i = 0;; i++) { … … 86 99 87 100 int put_file( cache_line & entry ) { 88 uint32_t idx = murmur3_32( (const uint8_t *)entry.file, strlen(entry.file), options. hash_seed ) % file_cache.size;101 uint32_t idx = murmur3_32( (const uint8_t *)entry.file, strlen(entry.file), options.file_cache.hash_seed ) % file_cache.size; 89 102 90 103 int i = 0; … … 101 114 void fill_cache( const char * path ) { 102 115 int ret; 116 ret = chdir(path); 117 if(ret < 0) { 118 abort( "chdir error: (%d) %s\n", (int)errno, strerror(errno) ); 119 } 120 103 121 size_t fcount = 0; 104 122 size_t fsize = 16; … … 118 136 raw[idx].file = strdup(fpath+2); 119 137 raw[idx].size = sb->st_size; 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) ); 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 } 123 143 } 124 144 return 0; 125 145 } 126 146 127 ret = ftw( path, walk, 10);147 ret = ftw(".", walk, 10); 128 148 if(ret < 0) { 129 149 abort( "ftw error: (%d) %s\n", (int)errno, strerror(errno) ); … … 135 155 136 156 // Step 2 create the cache 137 file_cache.size = options.file_cache _size > 0 ? options.file_cache_size : fsize;157 file_cache.size = options.file_cache.size > 0 ? options.file_cache.size : fsize; 138 158 if( file_cache.size < fcount ) { 139 159 abort("File Cache too small\n"); 140 160 } 141 161 142 file_cache.entries = anew(f size);162 file_cache.entries = anew(file_cache.size); 143 163 144 164 // Step 3 fill the cache 145 165 int conflicts = 0; 146 166 for(i; fcount) { 147 printf("Added file %s\n", raw[i].file);148 167 conflicts += put_file( raw[i] ); 149 168 } 150 169 printf("Filled cache from path \"%s\" with %zu files\n", path, fcount); 151 170 if( conflicts > 0 ) { 152 printf("Found %d conflicts (seed: %u)\n", conflicts, options. hash_seed);171 printf("Found %d conflicts (seed: %u)\n", conflicts, options.file_cache.hash_seed); 153 172 #if defined(REJECT_CONFLICTS) 154 173 abort("Conflicts found in the cache"); … … 156 175 } 157 176 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 158 190 // Step 4 clean up 159 191 free( raw ); 160 192 } 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 161 202 162 203 void close_cache() {
Note:
See TracChangeset
for help on using the changeset viewer.