Repository navigation
[board] Measure session, view and timed event durations on a monotonic clock - #491
Draft
arifBurakDemiray wants to merge 1 commit into
Draft
arifBurakDemiray wants to merge 1 commit into
arifBurakDemiray wants to merge 1 commit into
Conversation
…lock Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Board card C-111: Session/view/event durations use wall-clock differences on Android, iOS and Web; C++ fixed this on 10-17 (ios). Part 2 of 3 of C-108.
Source: https://test-deniz.count.ly/e6a1f3cbb85c4db89d3c7d5b9ab739ab1e99969785c99aec6347327c1ac7d8a5/2026-10-19.html (reference fix: Countly/countly-sdk-cpp#161)
What breaks without it
Session, view and timed event durations are differences of
NSDate.date.timeIntervalSince1970readings. When the user or the network time sync moves the system clock while one of them is running, the duration moves with it: backwards gives a negative or too shortsession_duration/dur, forwards inflates engagement. Reasoned from the code, not reproduced on a device.What changed
CountlyCommon.monotonicTime: seconds fromclock_gettime_nsec_np(CLOCK_MONOTONIC_RAW).lastSessionStartTimeandsessionLengthInSecondsread it.CountlyViewData.viewStartTimeanddurationread it (start, pause, resume).startEvent:also storesmonotonicStartTimeon the startedCountlyEvent(in memory only, not encoded or sent);endEvent:takes the duration from it.## XX.XX.XX(26.8.0 is released).Choice for the reviewer: which monotonic clock
The card suggests
CACurrentMediaTime/systemUptime. Both stop while the device sleeps, so time asleep would drop out of a duration that the wall clock counts today (a timed event or a manual session spanning a sleep, or a Mac that sleeps with the app in front).CLOCK_MONOTONIC_RAWkeeps counting through sleep and is what libc++'sstd::chrono::steady_clockreads on Apple platforms, so this matches the C++ SDK. Checked on a Mac about 10 days after boot:CLOCK_MONOTONIC_RAW=steady_clock= 850,468 s,CLOCK_UPTIME_RAW= 378,474 s. Available from iOS 10 / macOS 10.12 / tvOS 10 / watchOS 3, so the minimum versions do not change.Android (C-110) and Web (C-112) have no PR yet, so this could not be matched against the Android reference.
Verified
swift build(macOS) compiles with no new warnings.CountlyViewTrackingTestsandCountlyViewForegroundBackgroundTests27/27 pass (they assert view durations).CountlyUserProfileTests(assertssession_duration) and the log gathering test that starts and ends a timed event: 26/27 pass.test_210_CNR_Mtimed out once waiting for a main-queue timer during the full class run; it passes on its own both on this branch and on staging, so it looks timing-dependent.Not verified
timeSinceLaunch(crash_run, content initial delay) also uses the wall clock; it is outside this card and left unchanged.🤖 Generated with Claude Code