int main(int ac, char** av) { tick_counter_t ticks[4]; uint64_t sum = 0; unsigned int j; tick_initialize(0); srand(getpid() * time(NULL)); #define ITER_COUNT 100 for (j = 0; j < ITER_COUNT; ++j) { const unsigned int id = rand() % TICK_CPU_COUNT; read_ticks_on(&ticks[0], id); fubar(); read_ticks_on(&ticks[1], id); tick_sub_counters(&ticks[2], &ticks[1], &ticks[0]); sum += tick_get_value(&ticks[2]); } tick_set_value(&ticks[3], sum / ITER_COUNT); for (j = 0; j < 1000; ++j) { unsigned int ids[2]; ids[0] = rand() % TICK_CPU_COUNT; ids[1] = ids[0]; while (ids[0] == ids[1]) ids[1] = rand() % TICK_CPU_COUNT; read_ticks_on(&ticks[0], ids[0]); fubar(); read_ticks_on(&ticks[1], ids[1]); tick_sub_counters(&ticks[2], &ticks[1], &ticks[0]); #ifndef PRId64 # define PRId64 "ld" #endif #ifndef PRIu64 # define PRIu64 "lu" #endif printf("[%u:%u] (%" PRId64 " %" PRIu64 " - %" PRIu64\ " = %" PRIu64 " (%" PRIu64 ")\n", ids[0], ids[1], tick_get_diff(ids[0], ids[1]), tick_get_value(&ticks[1]), tick_get_value(&ticks[0]), tick_get_value(&ticks[2]), tick_get_value(&ticks[3])); } tick_cleanup(); return 0; }
int foo(void) /* use ANSI prototypes on every compiler that supports 'em */ { int local1, local2; /* local variable declarations are always followed by a blank line */ do_stuff(); if (bar(local1)) { /* long comments here *//* this lines up with -----------+ */ char *local3; /* autos declared close to use | */ /* | */ do_more_stuff(); /* (everything else indented) | */ local2 = strlen(local3);/* | */ } /* this <------------------------+ */ else local2 = fubar(); /* using tab >= 6, else's line up */ return local2; } /* no question where functions end! */
/* * Sanity Check */ static void sanity(tdfxContextPtr fxMesa) { tdfxMemRange *tmp, *prev, *pos; prev = 0; tmp = fxMesa->tmFree[0]; while (tmp) { if (!tmp->startAddr && !tmp->endAddr) { fprintf(stderr, "Textures fubar\n"); fubar(); } if (tmp->startAddr >= tmp->endAddr) { fprintf(stderr, "Node fubar\n"); fubar(); } if (prev && (prev->startAddr >= tmp->startAddr || prev->endAddr > tmp->startAddr)) { fprintf(stderr, "Sorting fubar\n"); fubar(); } prev = tmp; tmp = tmp->next; } prev = 0; tmp = fxMesa->tmFree[1]; while (tmp) { if (!tmp->startAddr && !tmp->endAddr) { fprintf(stderr, "Textures fubar\n"); fubar(); } if (tmp->startAddr >= tmp->endAddr) { fprintf(stderr, "Node fubar\n"); fubar(); } if (prev && (prev->startAddr >= tmp->startAddr || prev->endAddr > tmp->startAddr)) { fprintf(stderr, "Sorting fubar\n"); fubar(); } prev = tmp; tmp = tmp->next; } }