Programmatically log the caller of a function in C++
I have a Mutex object whose locking function is mysteriously called many times in some condition/time (it is tracked by an internal per-thread counter and reports the total number of occurrences at a fixed frequency). If I could add a check to the code, for example, every 100 or so calls in a fixed bucket of time, it would record who called it to better understand who might be having the problem. I think this should be achievable with some stack traces, but I’m not sure where to start or what to reference. Is there an easy way to solve this problem?