Changes in benchmark/io/http/filecache.cfa [0aec496:53e4562]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/filecache.cfa
r0aec496 r53e4562 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 { … … 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.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) ); … … 132 152 if(fcount == 0) { 133 153 abort("No file found in path %s\n", path); 154 } 155 156 if(options.file_cache_list) { 157 printf("Listing files and exiting\n"); 158 for(i; fcount) { 159 int s; char u; 160 [s, u] = human_size(raw[i].size); 161 printf("%4d%c - %s\n", s, u, raw[i].file); 162 free(raw[i].file); 163 } 164 free(raw); 165 exit(0); 134 166 } 135 167
Note: See TracChangeset
for help on using the changeset viewer.