-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: calculate the duration for single-shot events #53
fix: calculate the duration for single-shot events #53
Conversation
I appreciate you taking the time to investigate and making this PR, but I don't think this is the right way to go about fixing this issue. The reasoning here is that if you only poll every 5s (or more) you can't really say with any reasonable degree of certainty that the new event has actually been active for the last 5 seconds. If an event is the exact same as in the last poll, however, we think it's a reasonable assumption (which is how When Reconfiguring |
I can understand your consideration of minimizing the assumptions. My issue here is that the default As the 0s-duration events are intended, I am okay if aw-client remains unchanged. (BTW, sorry for not noticing the discussion about flooding before, my bad.) Now coming back to my issue, I personally can tolerate some seconds of inaccuracy caused by expanding the 0s-duration events, but I don't want the 0s-duration events to be totally ignored in the timeline and in the calculation of my total time. Considering a scenario where I am writing a document according to some web pages, the focus switches frequently between my editor and my browser, and ignoring 0s-duration event can half my recorded work time. There seems to be several options to deal with a long
So, what do you think? |
Honestly, I think the solution here would be to improve how aw-watcher-window works on macOS. It doesn't fundamentally need that much CPU, it's just that we've implemented it in a very inefficient way. @xylix did some great work to improve the situation, but the PR has gotten stale: ActivityWatch/aw-watcher-window#40 I'm not opposed to the other things you suggested (especially point 2), but I'd rather just fix the problem (high CPU) at its core. |
AFAIK, xylix's PR acquires the window title using According to the apple document, "few applications set the Quartz window name." So I doubt whether xylix's method still works. A quick way to verify is to use the script in kenorb's stackoverflow answer and run something like watch python3 the_script.py in the shell. Then switch the focus to different apps and inspect the output of the script. On my Mac, the script gets the active application name correctly but the window title is always |
@mkvoya The window title is 'Unknown' likely due to a permissions issue, not because the applications do not expose the information (it should be the same information as that which is fetched by the AppleScript after all). See the updated PR and a similar issue in another application: |
I'm closing this since the discussion is moved to the aw-watcher-window repo. Thanks. :) |
I found several 0s-duration events when I use aw-watcher-window. (I have configured the
poll_time
of aw-watcher-window to 30 seconds, which may help present the issue.)After some investigation, the reason seems to be the calculation of event duration. The calculation of the event duration is in the
heartbeat_merge
function. However, if an event occurs once and cannot be merged to the next event, the event will have a default duration of 0s, causing the above problem.This MR detects such a situation and calculate the duration before sending such an event.