31 #ifdef PROFILE_LOCKING
45 typedef struct LockRecord_ {
60 pthread_mutex_t lock_records_mutex;
62 static uint32_t LockRecordHash(
HashListTable *ht,
void *buf, uint16_t buflen)
64 LockRecord *fn = (LockRecord *)buf;
65 uint32_t hash = strlen(fn->file) + fn->line;
68 for (u = 0; u < strlen(fn->file); u++) {
75 static char LockRecordCompare(
void *buf1, uint16_t len1,
void *buf2, uint16_t len2)
77 LockRecord *fn1 = (LockRecord *)buf1;
78 LockRecord *fn2 = (LockRecord *)buf2;
80 if (fn1->line != fn2->line)
83 if (fn1->file == fn2->file)
89 static void LockRecordFree(
void *data)
91 LockRecord *fn = (LockRecord *)data;
100 pthread_mutex_init(&lock_records_mutex, NULL);
101 pthread_mutex_lock(&lock_records_mutex);
103 lock_records =
HashListTableInit(512, LockRecordHash, LockRecordCompare, LockRecordFree);
104 BUG_ON(lock_records == NULL);
106 pthread_mutex_unlock(&lock_records_mutex);
113 LockRecord fn = { NULL, NULL, 0,0,0,0,0,0}, *ptr = &fn;
118 if (lookup_fn == NULL) {
119 LockRecord *
new =
SCMalloc(
sizeof(LockRecord));
127 new->ticks_max = l->
ticks;
128 new->ticks_total = l->
ticks;
133 lookup_fn->ticks_total += l->
ticks;
134 if (l->
ticks > lookup_fn->ticks_max)
135 lookup_fn->ticks_max = l->
ticks;
136 lookup_fn->ticks_cnt++;
137 lookup_fn->cont += l->
cont;
150 pthread_mutex_lock(&lock_records_mutex);
151 LockRecordAdd(&
locks[i]);
152 pthread_mutex_unlock(&lock_records_mutex);
156 static void SCProfilingListLocks(
void)
171 fprintf(fp,
"\n\nLock Cnt Avg ticks Max ticks Total ticks Cont Func\n");
172 fprintf(fp,
"------------------ ---------- --------- ------------ ------------ ------- ---------\n");
202 snprintf(
str,
sizeof(
str),
"(%s) %s:%d",
lock,r->file, r->line);
204 fprintf(fp,
"%-50s %-10u %-9"PRIu64
" %-12"PRIu64
" %-12"PRIu64
" %-7u %-s\n",
205 str, r->ticks_cnt, (uint64_t)((uint64_t)r->ticks_total/(uint64_t)r->ticks_cnt), r->ticks_max, r->ticks_total, r->cont, r->func);
207 total += r->ticks_total;
214 fprintf(fp,
"\nOverall: locks %"PRIu64
", average cost %"PRIu64
", contentions %"PRIu32
", total ticks %"PRIu64
"\n",
215 cnt, (uint64_t)((uint64_t)total/(uint64_t)
cnt), cont, total);
225 pthread_mutex_lock(&lock_records_mutex);
227 SCProfilingListLocks();
229 if (lock_records != NULL) {
233 pthread_mutex_unlock(&lock_records_mutex);
235 pthread_mutex_destroy(&lock_records_mutex);