Skip to content

Commit

Permalink
RUMM-1086 Long tasks added
Browse files Browse the repository at this point in the history
RunLoopObservers added to RunLoop.main
they observe the intervals between run loop activities
and report long intervals.
  • Loading branch information
buranmert committed Sep 16, 2021
1 parent aceb149 commit 602db06
Show file tree
Hide file tree
Showing 30 changed files with 1,361 additions and 18 deletions.
32 changes: 32 additions & 0 deletions Datadog/Datadog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@
9E26E6B924C87693000B3270 /* RUMDataModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E26E6B824C87693000B3270 /* RUMDataModels.swift */; };
9E2EF44F2694FA14008A7DAE /* VitalInfoSamplerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E2EF44E2694FA14008A7DAE /* VitalInfoSamplerTests.swift */; };
9E307C3224C8846D0039607E /* RUMDataModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E26E6B824C87693000B3270 /* RUMDataModels.swift */; };
9E359F4E26CD518D001E25E9 /* LongTaskObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E359F4D26CD518D001E25E9 /* LongTaskObserver.swift */; };
9E36D92224373EA700BFBDB7 /* SwiftExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E36D92124373EA700BFBDB7 /* SwiftExtensionsTests.swift */; };
9E544A4F24753C6E00E83072 /* MethodSwizzler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E544A4E24753C6E00E83072 /* MethodSwizzler.swift */; };
9E544A5124753DDE00E83072 /* MethodSwizzlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E544A5024753DDE00E83072 /* MethodSwizzlerTests.swift */; };
Expand All @@ -485,6 +486,9 @@
9E989A4225F640D100235FC3 /* AppStateListenerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E989A4125F640D100235FC3 /* AppStateListenerTests.swift */; };
9E9973F1268DF69500D8059B /* VitalInfoSampler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E9973F0268DF69500D8059B /* VitalInfoSampler.swift */; };
9EA3CA6926775A3500B16871 /* VitalRefreshRateReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3CA6826775A3500B16871 /* VitalRefreshRateReader.swift */; };
9EC2835A26CFEE0B00FACF1C /* RUMMobileVitalsScenarioTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC2835926CFEE0B00FACF1C /* RUMMobileVitalsScenarioTests.swift */; };
9EC2835E26CFF57A00FACF1C /* RUMMobileVitalsScenario.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9EC2835D26CFF57A00FACF1C /* RUMMobileVitalsScenario.storyboard */; };
9EC2836026CFF59400FACF1C /* RUMMobileVitalsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC2835F26CFF59400FACF1C /* RUMMobileVitalsViewController.swift */; };
9EC8B5DA2668197B000F7529 /* VitalCPUReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC8B5D92668197B000F7529 /* VitalCPUReader.swift */; };
9EC8B5EE2668E4DB000F7529 /* VitalCPUReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC8B5ED2668E4DB000F7529 /* VitalCPUReaderTests.swift */; };
9ED6A6B425F2901800CB2E29 /* AppStateListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ED6A6B325F2901800CB2E29 /* AppStateListener.swift */; };
Expand Down Expand Up @@ -1108,6 +1112,7 @@
9E0542CA25F8EBBE007A3D0B /* Kronos.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Kronos.xcframework; path = ../Carthage/Build/Kronos.xcframework; sourceTree = "<group>"; };
9E26E6B824C87693000B3270 /* RUMDataModels.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RUMDataModels.swift; sourceTree = "<group>"; };
9E2EF44E2694FA14008A7DAE /* VitalInfoSamplerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VitalInfoSamplerTests.swift; sourceTree = "<group>"; };
9E359F4D26CD518D001E25E9 /* LongTaskObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LongTaskObserver.swift; sourceTree = "<group>"; };
9E36D92124373EA700BFBDB7 /* SwiftExtensionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftExtensionsTests.swift; sourceTree = "<group>"; };
9E544A4E24753C6E00E83072 /* MethodSwizzler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MethodSwizzler.swift; sourceTree = "<group>"; };
9E544A5024753DDE00E83072 /* MethodSwizzlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MethodSwizzlerTests.swift; sourceTree = "<group>"; };
Expand All @@ -1121,6 +1126,9 @@
9E9973F0268DF69500D8059B /* VitalInfoSampler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VitalInfoSampler.swift; sourceTree = "<group>"; };
9E9EB37624468CE90002C80B /* Datadog.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = Datadog.modulemap; sourceTree = "<group>"; };
9EA3CA6826775A3500B16871 /* VitalRefreshRateReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VitalRefreshRateReader.swift; sourceTree = "<group>"; };
9EC2835926CFEE0B00FACF1C /* RUMMobileVitalsScenarioTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RUMMobileVitalsScenarioTests.swift; sourceTree = "<group>"; };
9EC2835D26CFF57A00FACF1C /* RUMMobileVitalsScenario.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = RUMMobileVitalsScenario.storyboard; sourceTree = "<group>"; };
9EC2835F26CFF59400FACF1C /* RUMMobileVitalsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RUMMobileVitalsViewController.swift; sourceTree = "<group>"; };
9EC8B5D92668197B000F7529 /* VitalCPUReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VitalCPUReader.swift; sourceTree = "<group>"; };
9EC8B5ED2668E4DB000F7529 /* VitalCPUReaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VitalCPUReaderTests.swift; sourceTree = "<group>"; };
9ED6A6B325F2901800CB2E29 /* AppStateListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStateListener.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1942,6 +1950,7 @@
61337036250F84F100236D58 /* RUM */ = {
isa = PBXGroup;
children = (
9EC2835C26CFF56B00FACF1C /* MobileVitals */,
61D50C532580EF41006038A3 /* RUMScenarios.swift */,
61337037250F84FD00236D58 /* ManualInstrumentation */,
61F9CA7725125918000A5E61 /* NavigationControllerAutoInstrumentation */,
Expand Down Expand Up @@ -2330,6 +2339,7 @@
61F3CDA1251118DD00C816E5 /* Views */,
6141014D251A578D00E3C2D9 /* Actions */,
6157FA5C252767B3009A8A3B /* Resources */,
9E06058F26EF904200F5F935 /* LongTasks */,
);
path = AutoInstrumentation;
sourceTree = "<group>";
Expand Down Expand Up @@ -3024,6 +3034,7 @@
61163C49252E03D6007DD5BF /* RUMModalViewsScenarioTests.swift */,
6164AF2D252C9C51000D78C4 /* RUMResourcesScenarioTests.swift */,
612D8F8025AF1C74000E2E09 /* RUMScrubbingScenarioTests.swift */,
9EC2835926CFEE0B00FACF1C /* RUMMobileVitalsScenarioTests.swift */,
);
path = RUM;
sourceTree = "<group>";
Expand Down Expand Up @@ -3119,6 +3130,14 @@
path = RUMEventOutputs;
sourceTree = "<group>";
};
9E06058F26EF904200F5F935 /* LongTasks */ = {
isa = PBXGroup;
children = (
9E359F4D26CD518D001E25E9 /* LongTaskObserver.swift */,
);
path = LongTasks;
sourceTree = "<group>";
};
9E47010324471027000073A4 /* include */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3155,6 +3174,15 @@
path = ../Sources/_Datadog_Private;
sourceTree = "<group>";
};
9EC2835C26CFF56B00FACF1C /* MobileVitals */ = {
isa = PBXGroup;
children = (
9EC2835D26CFF57A00FACF1C /* RUMMobileVitalsScenario.storyboard */,
9EC2835F26CFF59400FACF1C /* RUMMobileVitalsViewController.swift */,
);
path = MobileVitals;
sourceTree = "<group>";
};
9EF49F1524476FBD004F2CA0 /* DatadogIntegrationTests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3562,6 +3590,7 @@
6137E649252DD88D00720485 /* RUMModalViewsAutoInstrumentationScenario.storyboard in Resources */,
61441C0C24616DE9003D8BB8 /* Main.storyboard in Resources */,
615AAC36251E353700C89EE9 /* RUMTabBarAutoInstrumentationScenario.storyboard in Resources */,
9EC2835E26CFF57A00FACF1C /* RUMMobileVitalsScenario.storyboard in Resources */,
6167AD19251A27B80012B4D0 /* URLSessionScenario.storyboard in Resources */,
61F9CA792512593A000A5E61 /* RUMNavigationControllerScenario.storyboard in Resources */,
61337035250F84BF00236D58 /* TracingManualInstrumentationScenario.storyboard in Resources */,
Expand Down Expand Up @@ -3850,6 +3879,7 @@
61C3E63724BF191F008053F2 /* RUMScope.swift in Sources */,
61133BE52423979B00786299 /* LogBuilder.swift in Sources */,
61133BD42423979B00786299 /* FileReader.swift in Sources */,
9E359F4E26CD518D001E25E9 /* LongTaskObserver.swift in Sources */,
61C5A88A24509A0C00DA608C /* SpanFileOutput.swift in Sources */,
61C3E63524BF1794008053F2 /* Attributes.swift in Sources */,
61133BD32423979B00786299 /* File.swift in Sources */,
Expand Down Expand Up @@ -4124,6 +4154,7 @@
61E5333824B84EE2003D6C4E /* DebugRUMViewController.swift in Sources */,
615C3155251C9D7A0018781C /* RUMTASVariousUIControllsViewController.swift in Sources */,
61441C9D2461A796003D8BB8 /* AppConfiguration.swift in Sources */,
9EC2836026CFF59400FACF1C /* RUMMobileVitalsViewController.swift in Sources */,
6164AF06252C9004000D78C4 /* ObjcSendFirstPartyRequestsViewController.m in Sources */,
6167AD20251A27CC0012B4D0 /* SendFirstPartyRequestsViewController.swift in Sources */,
6193DCE8251B9AB1009B8011 /* RUMTASCollectionViewController.swift in Sources */,
Expand Down Expand Up @@ -4156,6 +4187,7 @@
61B9ED212462089600C0DCFF /* TracingManualInstrumentationScenarioTests.swift in Sources */,
61B6811F25F0EA860015B4AF /* CrashReportingWithLoggingScenarioTests.swift in Sources */,
61C2C20D24C1831700C0321C /* RUMManualInstrumentationScenarioTests.swift in Sources */,
9EC2835A26CFEE0B00FACF1C /* RUMMobileVitalsScenarioTests.swift in Sources */,
61FF282924B8A31E000B3D9B /* RUMEventMatcher.swift in Sources */,
61F7F1DD266F9CB000F9F53B /* CodableValue.swift in Sources */,
61B9ED1F2461E57700C0DCFF /* UITestsHelpers.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
value = "LoggingManualInstrumentationScenario"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "DD_TEST_SCENARIO_CLASS_NAME"
value = "RUMMobileVitalsScenario"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "DD_TEST_SCENARIO_CLASS_NAME"
value = "TracingManualInstrumentationScenario"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<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"/>
</dependencies>
<scenes>
<!--Mobile Vitals View Controller-->
<scene sceneID="s0d-6b-0kx">
<objects>
<viewController id="Y6W-OH-hqX" customClass="RUMMobileVitalsViewController" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="5EZ-qb-Rvc">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<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"/>
<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"/>
<state key="normal" title="No-op"/>
<connections>
<action selector="noOpButtonTapped:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="aqU-RG-zDa"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jCt-PH-psR">
<rect key="frame" x="0.0" y="30" width="128" height="30"/>
<state key="normal" title="Block Main Thread"/>
<connections>
<action selector="blockMainThreadButtonTapped:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="CCI-ts-9al"/>
</connections>
</button>
</subviews>
</stackView>
</subviews>
<viewLayoutGuide key="safeArea" id="vDu-zF-Fre"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="ca2-aW-xR8" firstAttribute="centerX" secondItem="vDu-zF-Fre" secondAttribute="centerX" id="WMO-TA-5tP"/>
<constraint firstItem="ca2-aW-xR8" firstAttribute="centerY" secondItem="vDu-zF-Fre" secondAttribute="centerY" id="YHh-T6-UK3"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Ief-a0-LHa" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="28" y="75"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-2020 Datadog, Inc.
*/

import UIKit

final class RUMMobileVitalsViewController: UIViewController {

@IBAction func noOpButtonTapped(_ sender: Any) {
print("No-op button tapped... Sending view update...")
}

@IBAction func blockMainThreadButtonTapped(_ sender: Any) {
print("❌ Blocking main thread at \(Date())...")
let startDate = Date()
var i = 1
while true {
i += 1
if Date().timeIntervalSince(startDate) > 3.0 {
print("✅ Main thread is unblocked!")
break
}
}
}

}
14 changes: 14 additions & 0 deletions Datadog/Example/Scenarios/RUM/RUMScenarios.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ final class RUMTapActionScenario: TestScenario {
}
}

/// Scenario which uses RUM only. Blocks the main thread and expects to have non-zero MobileVitals values
final class RUMMobileVitalsScenario: TestScenario {
static var storyboardName: String = "RUMMobileVitalsScenario"

func configureSDK(builder: Datadog.Configuration.Builder) {
_ = builder
.trackUIKitRUMViews()
.trackUIKitRUMActions()
.trackLongTasks()
.enableLogging(false)
.enableTracing(false)
}
}

/// Scenario which uses RUM and Tracing auto instrumentation features to track bunch of network requests
/// sent with `URLSession` from two VCs. The first VC calls first party resources, the second one calls third parties.
final class RUMURLSessionResourcesScenario: URLSessionBaseScenario, TestScenario {
Expand Down
10 changes: 8 additions & 2 deletions Sources/Datadog/Core/FeaturesConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal struct FeaturesConfiguration {
struct AutoInstrumentation {
let uiKitRUMViewsPredicate: UIKitRUMViewsPredicate?
let uiKitRUMUserActionsPredicate: UIKitRUMUserActionsPredicate?
let longTaskThreshold: TimeInterval?
}

let common: Common
Expand All @@ -50,6 +51,7 @@ internal struct FeaturesConfiguration {
let resourceEventMapper: RUMResourceEventMapper?
let actionEventMapper: RUMActionEventMapper?
let errorEventMapper: RUMErrorEventMapper?
let longTaskEventMapper: RUMLongTaskEventMapper?
/// RUM auto instrumentation configuration, `nil` if not enabled.
let autoInstrumentation: AutoInstrumentation?
let backgroundEventTrackingEnabled: Bool
Expand Down Expand Up @@ -182,10 +184,13 @@ extension FeaturesConfiguration {
if configuration.rumEnabled {
var autoInstrumentation: RUM.AutoInstrumentation?

if configuration.rumUIKitViewsPredicate != nil || configuration.rumUIKitUserActionsPredicate != nil {
if configuration.rumUIKitViewsPredicate != nil ||
configuration.rumUIKitUserActionsPredicate != nil ||
configuration.rumLongTaskDurationThreshold != nil {
autoInstrumentation = RUM.AutoInstrumentation(
uiKitRUMViewsPredicate: configuration.rumUIKitViewsPredicate,
uiKitRUMUserActionsPredicate: configuration.rumUIKitUserActionsPredicate
uiKitRUMUserActionsPredicate: configuration.rumUIKitUserActionsPredicate,
longTaskThreshold: configuration.rumLongTaskDurationThreshold
)
}

Expand All @@ -200,6 +205,7 @@ extension FeaturesConfiguration {
resourceEventMapper: configuration.rumResourceEventMapper,
actionEventMapper: configuration.rumActionEventMapper,
errorEventMapper: configuration.rumErrorEventMapper,
longTaskEventMapper: configuration.rumLongTaskEventMapper,
autoInstrumentation: autoInstrumentation,
backgroundEventTrackingEnabled: configuration.rumBackgroundEventTrackingEnabled,
onSessionStart: configuration.rumSessionsListener
Expand Down
Loading

0 comments on commit 602db06

Please sign in to comment.