Repository navigation
screenshot-detector: only name the processes that changed between polls - #12
Merged
Merged
Conversation
The monitor scans the process table every 30 ms and asked every process for its name each time: about 20,000 system calls a second and 6% of a CPU core on a Mac with 600 processes, around the clock. The scan now lists the pids (one call) and names only new ones, ones under a second old (a process takes its own name a moment after it is created), and everything again every 2 seconds. Same poll interval, same result; the scan costs about 0.9% of a core.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
why
the monitor scans the process table every 30 ms, and each scan asked every process for its name. on a mac with about 600 processes that is roughly 20,000 system calls a second: about 6% of a cpu core, all the time, in every app that embeds
ScreenshotMonitorKit.what
ProcessScannergives the same answer asScreenshotProcessScan.scan()but only names:the poll interval is unchanged, so a new
screencaptureis still seen on the next poll.one case is slower: a process more than a second old that replaces itself with
screencaptureis noticed within 2 seconds instead of 30 ms.measured
sampled inside an app that embeds the kit, idle: the monitor queue went from 6.3% of a core to 0.9%.
tests
ScreenshotHelperfrom this branch and took threescreencapture -xshots: all three detected and captured