Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Feb 20, 2020
1 parent 9e3b1f4 commit 304729e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifdef STATS
struct cycle_counter
{
uint64_t total_cycle_count;
uint64_t cycle_count;
uint64_t hit_count;
};

Expand All @@ -12,22 +12,21 @@ static struct cycle_counter event_counters[EVENT_TYPE_COUNT];

#define cycle_counter_report(name, hit_count, total_cycles, elapsed_cycles) \
fprintf(stdout, "%30s: hits %'25lld | cur %'25lld | avg %'25lld\n",\
name, hit_count, elapsed_cycles, total_cycles / hit_count);
name, hit_count, elapsed_cycles, total_cycles / hit_count)

static inline void cycle_counter_tick(const char *name, struct cycle_counter *counter, uint64_t elapsed_cycles)
{
counter->total_cycle_count += elapsed_cycles;
counter->cycle_count += elapsed_cycles;
++counter->hit_count;
cycle_counter_report(name, counter->hit_count, counter->total_cycle_count, elapsed_cycles)
cycle_counter_report(name, counter->hit_count, counter->cycle_count, elapsed_cycles);
}

static inline void cycle_counter_tick_atomic(const char *name, struct cycle_counter *counter, uint64_t elapsed_cycles)
{
uint64_t total_cycle_count = __sync_add_and_fetch(&counter->total_cycle_count, elapsed_cycles);
uint64_t cycle_count = __sync_add_and_fetch(&counter->cycle_count, elapsed_cycles);
uint64_t hit_count = __sync_add_and_fetch(&counter->hit_count, 1);
cycle_counter_report(name, hit_count, total_cycle_count, elapsed_cycles)
cycle_counter_report(name, hit_count, cycle_count, elapsed_cycles);
}

#endif

static bool queue_init(struct queue *queue)
Expand Down

0 comments on commit 304729e

Please sign in to comment.