According to the docs, if the sampling rate is s, and the number of samples that fall within some function f is n, then the expected error of the provided self-time is s*sqrt(n). That means that, in relative terms, if you want your error to be below some threeshold e, the amount of samples n you have to collect for f must be >= 1/e^2.
But the problem I see with that sentence is that the samples are not taken randomly, but deterministically each X ms. I think that's a big important detail when doing statistical estimations. Is that expected error formula correct? What would be the correct expected error?
Because you don't know if the firing rate is somehow "synchronized" with some specific function. For example, imagine a main containing a loop that calls A and B one after another per-iteration, and both functions take a similar time to execute. For example, 1/8 of the firing rate. It might totally happen that all fires during a very long time always happen inside B (each forth execution of B).
Of course, execution times and firing rate won't ever be exact multiples of one another, so the "fires" won't eternally observe the same portion of the iteration, but the point is that your error doesn't depend on the number of samples alone as claimed by the docs (only true if samples were random or pseudorandom at least), but also on the minimal number of samples required to have "observed" at least different portions of each iteration-time, in some evenly distributed manner, and you don't know how many time you need to wait for that to happen.
A potential solution would be to increase the sampling rate by some rate (for example, x10), but do nothing in the majority of the fires, but only choose randomly a subset of it (to keep the overhead as similar as before as possible). For example, if you want in average to collect a sample each 1ms to don't increase the profiler overhead too much, but you want to randomize it, you could use a firing rate of 0.1ms and randomly choose 1000 samples per-second (e.g., randomly discard 9 out of 10 fires; you can also pre-compute which samples to take).
Am I right?