I need to debug an application for an embedded device. A problem with this application might be timing related so I try to decrease the speed of execution on my development machine.
I have a setup which is quite useful but needs a little tweaking for convenience, basically I followed the advice given here:
https://blogs.msdn.microsoft.com/vijaysk/2012/10/26/tools-to-simulate-cpu-memory-disk-load/
Linked in the article there is the tool "CPUSTRES.exe" which generates high CPU usage. To prevent the tool to eat up all my CPU I start it like so (the tool will only run on the 8th core):
START "Stress" /affinity 0x80 /HIGH CPUSTRES.EXE
Then I start the debugging session in the Qt Creator (version 4.1.0). Using the windows task manager I can set the same processor affinity for the application as the stress tool has. Doing so gives me an app that more or less sluggish like on the embedded device but the debugger and all other apps behave nicely.
I find it a little inconvenient to set the affinity in the task manager manually. I want this application always only on the same single core. This is only for debugging purposes, so would not like to change this in code. How can I achieve that?
While I managed to start the application under test with the desired processor affinity I would not recomment it. It does not make my life easier. Instead I would recommend to set the affinity in code as commented by @ni1ight.
The easy way (that was not asked for):
#include <windows.h>
int main(int argc, char* argv[]) {
#ifdef _DEBUG
DWORD_PTR processAffinityMask = 1 << 7;
HANDLE process = GetCurrentProcess();
SetProcessAffinityMask(process, processAffinityMask);
#endif
[...]
The other way to do it (that is not reasonable):
START "" /affinity 0x80 AppUnderTest.EXE
). It should be possible to provide the application path as an argument to the cmd but I did not try this.