Skip to content

Commit

Permalink
Merge pull request #1182 from DataDog/xgouchet/RUMM-3081/fix_cpu_tick…
Browse files Browse the repository at this point in the history
…s_per_seconds

RUMM-3081 fix invalid cpu ticks per seconds
  • Loading branch information
xgouchet authored Mar 1, 2023
2 parents e29d1f5 + 9653a42 commit aa7c96e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Y6W-OH-hqX">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Y6W-OH-hqX">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -18,7 +18,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="ca2-aW-xR8">
<rect key="frame" x="143" y="423" width="128" height="60"/>
<rect key="frame" x="143" y="410" width="128" height="90"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="SSx-AL-9bb">
<rect key="frame" x="0.0" y="0.0" width="128" height="30"/>
Expand All @@ -34,6 +34,13 @@
<action selector="blockMainThreadButtonTapped:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="CCI-ts-9al"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6oU-go-pxW" userLabel="Start New View">
<rect key="frame" x="0.0" y="60" width="128" height="30"/>
<state key="normal" title="Start New View"/>
<connections>
<action selector="startNewViewButtonTapped:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="oCj-5m-88S"/>
</connections>
</button>
</subviews>
</stackView>
</subviews>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import UIKit
import Datadog

final class RUMMobileVitalsViewController: UIViewController {

Expand All @@ -25,4 +26,11 @@ final class RUMMobileVitalsViewController: UIViewController {
}
}

@IBAction func startNewViewButtonTapped(_ sender: Any){
print("Start New View button tapped... Starting new view...")

Global.rum.startView(key: "sample view")
Global.rum.stopView(key: "sample view")
}

}
2 changes: 1 addition & 1 deletion Sources/Datadog/RUM/RUMMonitor/Scopes/RUMViewScope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ internal class RUMViewScope: RUMScope, RUMContextProvider {
view: .init(
action: .init(count: actionsCount.toInt64),
cpuTicksCount: cpuInfo?.greatestDiff,
cpuTicksPerSecond: cpuInfo?.greatestDiff?.divideIfNotZero(by: Double(timeSpent)),
cpuTicksPerSecond: timeSpent > 1.0 ? cpuInfo?.greatestDiff?.divideIfNotZero(by: Double(timeSpent)) : nil,
crash: isCrash ? .init(count: 1) : .init(count: 0),
cumulativeLayoutShift: nil,
customTimings: customTimings.reduce(into: [:]) { acc, element in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ private extension ExampleApplication {
func tapBlockMainThreadButton() {
buttons["Block Main Thread"].tap()
}

func tapStartNewViewButton() {
buttons["Start New View"].tap()
}
}

class RUMMobileVitalsScenarioTests: IntegrationTests, RUMCommonAsserts {
Expand Down Expand Up @@ -66,4 +70,35 @@ class RUMMobileVitalsScenarioTests: IntegrationTests, RUMCommonAsserts {
let longTask2 = longTaskEvents[1]
XCTAssertGreaterThan(longTask2.longTask.duration, 3_000_000_000)
}

func testRUMShortTimeSpentCPUScenario() throws {
// Server session recording RUM events send to `HTTPServerMock`.
let rumServerSession = server.obtainUniqueRecordingSession()

let app = ExampleApplication()
app.launchWith(
testScenarioClassName: "RUMMobileVitalsScenario",
serverConfiguration: HTTPServerMockConfiguration(
rumEndpoint: rumServerSession.recordingURL
)
)

// NOTE: RUMM-1086 even tapNoOpButton() can take up to 0.25sec in my local,
// therefore i used `threshold: 2.5` for long tasks in this scenario
app.tapStartNewViewButton()
try app.endRUMSession()

// Get RUM Sessions with expected number of View visits
let recordedRUMRequests = try rumServerSession.pullRecordedRequests(timeout: dataDeliveryTimeout) { requests in
try RUMSessionMatcher.singleSession(from: requests)?.hasEnded() ?? false
}

assertRUM(requests: recordedRUMRequests)

let session = try XCTUnwrap(RUMSessionMatcher.singleSession(from: recordedRUMRequests))
sendCIAppLog(session)

let lastViewEvent = try XCTUnwrap(session.viewVisits[1].viewEvents.last)
XCTAssertNil(lastViewEvent.view.cpuTicksPerSecond)
}
}

0 comments on commit aa7c96e

Please sign in to comment.