If I add some AudioThumbnails to my plug, the cpu goes much higher!
I did some some profiling, and I see that about half of the running time take place in the TimeSliceThread of the AudioThumbnailCache!
Is that what you would expect?
a screenshot of the profiling : http://s30.postimg.org/ovj4jux41/profiling.png
I don't do anything particular with the audiothumbnails. just create it and add it to the editor. If I remove it everything is fine.
hum.. well I don't think so, but I'm not really confident with profiling, so that's why I wonder if that is an expected result.
It's just that as soon as I add those AudioThumbnails, the cpu goes high. So to figure out what was going on, I used the Time Profiler.
I would have thought that waiting would not be a cpu demanding task, but if it's at the top of the Time Profiler, it means that the cpu is really passing a lot of time calling __psynch_cvwait no?
Really, A plugin doing nothing (no editor, no audio process) except starting 20 TimeSliceThread in the constructor is eating up 30% of my cpu. Is that really normal? PluginProcessor.h :
Firstly, the point of a TimeSliceThread is that you only create one of them, and use it to do non-critical tasks in the background. If you need a pool of threads, that's what a ThreadPool is for. But even with a ThreadPool you'd never create 20 threads, there's no point in having more threads than your CPU has cores.
Secondly, 30% according to what? If some code is really running then your profiler will be able to show you where that 30% is actually being burned. If all it shows is idle time then you can ignore it.
> the point of a TimeSliceThread is that you only create one of them,
of course, but in my real use case I'm not creating TimeSliceThread directly. I'm just creating a bunch of AudioThumnails, whose AudioThumbnailCache are creating a TimeSliceThread. So that leads to several TimeSliceThread being creating.
Or is there a way to make those AudioThumnails sharing the same TimeSliceThread? There are other classes creating TimeSliceThreads as well, so there's no way to really reduce the total number of TimeSliceThreads I'm using.
That 30% is what the xcode monitor (or the activity monitor) says (compare to about 2% without those TimeSliceThreads). And if I got it correct, my profiler says this is burned in __psynch_cvwait
Are you saying that the time the cpu passes doing __psynch_cvwait should not be taken into account?
It's your code that creates the AudioThumbnailCache object that you give to each thumbnail, and yes, of course you should only create one of them! The comments for these classes do explain that.
And like I've said a couple of times already, the time that your profiler shows in a sleep/wait call is not "burned" by the CPU, it's good for most of your time to be spent waiting. Most likely if you're creating dozens of threads, it's just the general overhead of the OS switching between all those useless threads that's showing up in the task manager.
ah, good, I totally missed that AudioThumbnailCache thing.
I'm still not sure about the wait() not being shown by the monitor though. In my example, creating just 1 TimeSliceThread will double the cpu shown by the task manager (going from about 3% without any, to about 6%), which is quite huge :(