feat: add advanced thread metrics (peak UPS, state transitions, queue depth, memory, jitter) - #63
Merged
Merged
Conversation
… depth, memory, jitter) Closes #12 Expands ThreadMonitor with five new metrics: - Peak updates/sec via 1-second sliding window - Thread state transition counting (RUNNABLE↔WAITING etc.) - Queue depth tracking via atomic counter wired to channel send/receive - Process-wide native heap memory via Android Debug API - Jitter as standard deviation of inter-update intervals Updated MetricsExporter (CSV + JSON), ThreadMetricsDisplay UI, and added 6 new unit tests covering all advanced metrics.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements five advanced thread metrics to enhance the monitoring capabilities of the ThreadSimulator app: peak updates per second (using 1-second sliding window), thread state transitions, queue depth tracking, process-level memory allocation, and jitter measurements (standard deviation of inter-update intervals). The feature addresses issue #12 and extends the existing ThreadMetrics data class with backward-compatible default values while adding corresponding tracking structures in ThreadMonitor, UI display components, export functionality, and comprehensive unit tests.
Changes:
- Extended
ThreadMetricswith 5 new fields, all with default values for backward compatibility - Implemented tracking structures and computation methods in
ThreadMonitorfor advanced metrics - Integrated queue depth tracking in
HomeViewModelby adding increment/decrement calls around channel operations - Updated UI to display all new metrics in
ThreadMetricsDisplaycards with appropriate formatting - Extended CSV and JSON export to include all new metric fields
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| app/src/main/java/com/bs/threadsimulator/common/ThreadMetrics.kt | Added 5 new fields to ThreadMetrics data class, implemented tracking structures (updateTimestamps, stateTransitionCounts, lastThreadStates, queueDepthCounter), and computation methods (peak UPS, jitter, memory) |
| app/src/main/java/com/bs/threadsimulator/ui/screens/HomeViewModel.kt | Integrated queue depth tracking by calling incrementQueueDepth() after channel.send() and decrementQueueDepth() on receive |
| app/src/main/java/com/bs/threadsimulator/ui/screens/HomeScreenRoute.kt | Updated ThreadMetricsDisplay to show all 5 new metrics with formatting, increased card width to accommodate content |
| app/src/main/java/com/bs/threadsimulator/common/MetricsExporter.kt | Extended ExportedThreadMetric with new fields and updated buildCSVContent/buildJSONContent to export them |
| app/src/test/java/com/bs/threadsimulator/common/ThreadMonitorTest.kt | Added 6 new test cases for advanced metrics (peak UPS, queue depth, jitter, memory, clear resets, default values) and updated existing data class test |
- Set queue depth increment before channel.send() wrapped in try-catch - Optimize computePeakUpdatesPerSec to O(n) sliding window - Bound updateTimestamps retention to 10 seconds to prevent OOM - Remove unused perThreadTotalTime - Format memory in UI to display with %.2f KB - Fix computeJitter threshold - Add queue depth edge-case tests
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.
Summary
Closes #12
Adds five advanced thread metrics beyond basic update-count/avg-time tracking.
New Metrics
Thread.statechanges between consecutiverecordUpdate()callschannel.send(), decremented on receiveDebug.getNativeHeapAllocatedSize()(process-level; per-thread unavailable on Android)Changes
Core (
ThreadMetrics.kt)ThreadMetricsdata class with 5 new fields (all with defaults for backward compatibility)ThreadMonitor:updateTimestamps,stateTransitionCounts,lastThreadStates, queue depth atomic countercomputePeakUpdatesPerSec(),computeJitter(),getThreadAllocatedBytes()incrementQueueDepth()/decrementQueueDepth()public methodsViewModel (
HomeViewModel.kt)threadMonitor.incrementQueueDepth()after eachchannel.send()in all three fetch methodsthreadMonitor.decrementQueueDepth()ininitChannelon each receiveUI (
HomeScreenRoute.kt)ThreadMetricsDisplaycards now show all 5 new metrics alongside existing onesExport (
MetricsExporter.kt)ExportedThreadMetricbuildCSVContentandbuildJSONContentTests (
ThreadMonitorTest.kt)testThreadMetricsDataClassfor new fieldsVerification