Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/stats.cfa

    r73f4d08 rec43cf9  
    55#include <inttypes.h>
    66#include "bits/debug.hfa"
    7 #include "bits/locks.hfa"
    87#include "stats.hfa"
    98
     
    4544                        stats->io.calls.errors.busy = 0;
    4645                        stats->io.poller.sleeps     = 0;
    47                 #endif
    48 
    49                 #if defined(CFA_STATS_ARRAY)
    50                         stats->array.values = alloc(CFA_STATS_ARRAY);
    51                         stats->array.cnt = 0;
    5246                #endif
    5347        }
     
    157151                #endif
    158152        }
    159 
    160         #if defined(CFA_STATS_ARRAY)
    161                 extern "C" {
    162                         #include <stdio.h>
    163                         #include <errno.h>
    164                         #include <sys/stat.h>
    165                         #include <fcntl.h>
    166                 }
    167 
    168                 void __flush_stat( struct __stats_t * this, const char * name, void * handle) {
    169                         int ret = mkdir(".cfadata", 0755);
    170                         if(ret < 0 && errno != EEXIST) abort("Failed to create directory .cfadata: %d\n", errno);
    171 
    172                         char filename[100];
    173                         snprintf(filename, 100, ".cfadata/%s%p.data", name, handle);
    174 
    175                         int fd = open(filename, O_WRONLY | O_APPEND | O_CREAT, 0644);
    176                         if(fd < 0) abort("Failed to create file %s: %d\n", filename, errno);
    177 
    178                         for(i; this->array.cnt) {
    179                                 char line[100];
    180                                 size_t n = snprintf(line, 100, "%llu, %lld\n", this->array.values[i].ts, this->array.values[i].value);
    181                                 write(fd, line, n);
    182                         }
    183 
    184                         this->array.cnt = 0;
    185                         close(fd);
    186                 }
    187 
    188                 static __spinlock_t stats_lock;
    189 
    190                 void __push_stat( struct __stats_t * this, int64_t value, bool external, const char * name, void * handle ) {
    191                         if(external) lock(stats_lock __cfaabi_dbg_ctx2);
    192 
    193                         if( this->array.cnt >= CFA_STATS_ARRAY ) __flush_stat( this, name, handle );
    194 
    195                         size_t idx = this->array.cnt;
    196                         this->array.cnt++;
    197 
    198                         if(external) unlock(stats_lock);
    199 
    200                         this->array.values[idx].ts = rdtscl();
    201                         this->array.values[idx].value = value;
    202                 }
    203         #endif
    204153#endif
Note: See TracChangeset for help on using the changeset viewer.