Skip to content
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

RUMM-1278 RefreshRate is normalized to 0...60 #608

Merged
merged 3 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Sources/Datadog/RUM/RUMVitals/VitalInfoSampler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ internal protocol ContinuousVitalReader {
}

internal final class VitalInfoSampler {
struct Constants {
// We use normalized 0...60 range for refresh rate in Mobile Vitals,
// assuming 60 is the industry standard.
static let normalizedRefreshRate = 60.0
}

private static let frequency: TimeInterval = 1.0

let cpuReader: SamplingBasedVitalReader
Expand All @@ -39,7 +45,7 @@ internal final class VitalInfoSampler {

var refreshRate: VitalInfo {
let info = refreshRatePublisher.currentValue
return info.scaledDown(by: maximumRefreshRate)
return info.scaledDown(by: maximumRefreshRate / Constants.normalizedRefreshRate)
}

private var timer: Timer?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class VitalInfoSamplerTests: XCTestCase {
mockMemoryReader.vitalData = 321.0
mockRefreshRateReader.vitalInfo = {
var info = VitalInfo()
info.addSample(666.0)
info.addSample(60.0)
return info
}()

Expand All @@ -38,8 +38,7 @@ class VitalInfoSamplerTests: XCTestCase {
XCTAssertGreaterThan(sampler.cpu.sampleCount, 1)
XCTAssertEqual(sampler.memory.meanValue, 321.0)
XCTAssertGreaterThan(sampler.memory.sampleCount, 1)
let maxFPS = Double(UIScreen.main.maximumFramesPerSecond)
XCTAssertEqual(sampler.refreshRate.meanValue, 666.0 / maxFPS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have left the 666 value and then used:

XCTAssertEqual(sampler.refreshRate.meanValue, (666.0 / maxFPS) * 60.0)

XCTAssertEqual(sampler.refreshRate.meanValue, 60.0)
}
}

Expand Down