Very high 'context switch delta' after running some scripts multiple times. What is the best way to find the culprit?

I have some scripts that are used in conjunction to automatically extract metadata from the full path of files, embed them and then rename these files.

After using that chain of scripts multiple times, I noticed Opus had become very sluggish. Looking on my process manager, I then saw the Opus' process doing 20K-100K+ context switch per second, while idle. That seems abnormal, as it is usually stays at 3K after a fresh start of the process.

This issue seems quite easy to reproduce by just using these scripts. I am thinking about trying to isolate which one is the culprit, but I wonder if you guys have any suggestion of a good way to find the culprit. For memory leaks, VMMap is recommended. Is there some tool appropriate for this case?

It's probably re-reading the new media files to extract information about them.

Do you see similar when you refresh the folder they are in?

The high context switch delta continues long after finishing a run of these scripts, even after moving out of the directories in which they were used.

It also seems to grow a bit with every run. It is not that it stays between any number on the range 20K-100K, its more like it steadily stays at 5K-6K, then after a run, 7K-8K, until it reaches 100K-101K.

As there is a lot of small variations, it is hard to see exactly when the number steps up one range.

Try the Threads tab in Process Monitor, find the thread which is doing the most and click the Stack button, then see which DLLs are involved.

It could be there's a video demuxer going haywire, perhaps in response to seeing a partially written file. That used to happen a lot with some video DLLs, and may still happen with some (or some versions of them).

Is it actually using lots of CPU, or just context switching a lot? Is the metric you're looking at meaningful and is it causing a real problem or just a curiosity?

The lister becomes painfully slow at some point, so I [hard] restart Opus and it gets back to normal (responsive to user input and with a low context switch delta). I think there is at least a correlation between the sluggish behavior and that factor, but the cause of both is still unknown.

I haven't been managing video files lately, only images.

Previously I took a look at the thread list, but none of the "external/hooked" ones were consuming much CPU cycles in comparison to the ones that seem to be from Opus.

I will wait until the slow down begin again and try your suggestion.

EDIT: Oops, edited to correct a typo and the thread was sent to the front page under "latest". Ignore.