Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/http/filecache.cfa

    rd9c2284 r0aec496  
    5656}
    5757
    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 }
    7158
    7259struct {
     
    8269
    8370[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;
    8572
    8673        for(int i = 0;; i++) {
     
    9986
    10087int 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;
    10289
    10390        int i = 0;
     
    114101void fill_cache( const char * path ) {
    115102        int ret;
    116         ret = chdir(path);
    117         if(ret < 0) {
    118                 abort( "chdir error: (%d) %s\n", (int)errno, strerror(errno) );
    119         }
    120 
    121103        size_t fcount = 0;
    122104        size_t fsize = 16;
     
    136118                raw[idx].file = strdup(fpath+2);
    137119                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) );
    143123                }
    144124                return 0;
    145125        }
    146126
    147         ret = ftw(".", walk, 10);
     127        ret = ftw(path, walk, 10);
    148128        if(ret < 0) {
    149129                abort( "ftw error: (%d) %s\n", (int)errno, strerror(errno) );
     
    155135
    156136        // 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;
    158138        if( file_cache.size < fcount ) {
    159139                abort("File Cache too small\n");
    160140        }
    161141
    162         file_cache.entries = anew(file_cache.size);
     142        file_cache.entries = anew(fsize);
    163143
    164144        // Step 3 fill the cache
    165145        int conflicts = 0;
    166146        for(i; fcount) {
     147                printf("Added file %s\n", raw[i].file);
    167148                conflicts += put_file( raw[i] );
    168149        }
    169150        printf("Filled cache from path \"%s\" with %zu files\n", path, fcount);
    170151        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);
    172153                #if defined(REJECT_CONFLICTS)
    173154                        abort("Conflicts found in the cache");
     
    175156        }
    176157
    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 
    190158        // Step 4 clean up
    191159        free( raw );
    192160}
    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 
    202161
    203162void close_cache() {
Note: See TracChangeset for help on using the changeset viewer.