Skip to content

Commit 393309e

Browse files
authored
added coverage queue priority variable (#132)
1 parent 751e150 commit 393309e

File tree

6 files changed

+46
-4
lines changed

6 files changed

+46
-4
lines changed

DatadogSDKTesting.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
A71E64802BAB442300F2ACA5 /* ConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A71E647F2BAB442300F2ACA5 /* ConfigTests.swift */; };
3535
A74246002BFF94FA00F7EC64 /* ITRSkippabble.swift in Sources */ = {isa = PBXBuildFile; fileRef = A74245FF2BFF94FA00F7EC64 /* ITRSkippabble.swift */; };
3636
A78557812BFE015B0031E2D8 /* SkippedTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = A78557802BFE015B0031E2D8 /* SkippedTest.swift */; };
37+
A7A98C202C8F44BC00C93E59 /* CoveragePriority.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7A98C1F2C8F44BC00C93E59 /* CoveragePriority.swift */; };
3738
A7B39C6C2BCFC799007F98B2 /* CDatadogSDKTesting.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7E232DC2BC6E68B0087D8F8 /* CDatadogSDKTesting.framework */; };
3839
A7B39C702BCFCD77007F98B2 /* SubprocessWait.c in Sources */ = {isa = PBXBuildFile; fileRef = A7B39C6F2BCFCD77007F98B2 /* SubprocessWait.c */; };
3940
A7B39C722BCFD234007F98B2 /* SubprocessWait.h in Headers */ = {isa = PBXBuildFile; fileRef = A7B39C712BCFD234007F98B2 /* SubprocessWait.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -324,6 +325,7 @@
324325
A71E647F2BAB442300F2ACA5 /* ConfigTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigTests.swift; sourceTree = "<group>"; };
325326
A74245FF2BFF94FA00F7EC64 /* ITRSkippabble.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ITRSkippabble.swift; sourceTree = "<group>"; };
326327
A78557802BFE015B0031E2D8 /* SkippedTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkippedTest.swift; sourceTree = "<group>"; };
328+
A7A98C1F2C8F44BC00C93E59 /* CoveragePriority.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoveragePriority.swift; sourceTree = "<group>"; };
327329
A7B39C6F2BCFCD77007F98B2 /* SubprocessWait.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = SubprocessWait.c; sourceTree = "<group>"; };
328330
A7B39C712BCFD234007F98B2 /* SubprocessWait.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SubprocessWait.h; sourceTree = "<group>"; };
329331
A7B4D4C02C21DC510059F39B /* TagsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsTests.swift; sourceTree = "<group>"; };
@@ -580,6 +582,7 @@
580582
children = (
581583
81EDADB2292698A200279027 /* LLVMTotalsCoverageFormat.swift */,
582584
E1C8DEF4268363EC005B5411 /* DDCoverageHelper.swift */,
585+
A7A98C1F2C8F44BC00C93E59 /* CoveragePriority.swift */,
583586
);
584587
path = Coverage;
585588
sourceTree = "<group>";
@@ -1529,6 +1532,7 @@
15291532
A7FC25C22BA1EAF500067E26 /* IntelligentTestRunner.swift in Sources */,
15301533
A7CC6D862C07D624003C13BC /* Tags.swift in Sources */,
15311534
A74246002BFF94FA00F7EC64 /* ITRSkippabble.swift in Sources */,
1535+
A7A98C202C8F44BC00C93E59 /* CoveragePriority.swift in Sources */,
15321536
);
15331537
runOnlyForDeploymentPostprocessing = 0;
15341538
};

Sources/DatadogSDKTesting/Config.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ final class Config {
4343
var coverageEnabled: Bool = true
4444
var itrEnabled: Bool = true
4545
var excludedBranches: Set<String> = []
46+
var codeCoveragePriority: CodeCoveragePriority = .utility
4647

4748
/// Datadog Endpoint
4849
var endpoint: Endpoint = .us1
@@ -135,6 +136,8 @@ final class Config {
135136
endpoint = .other(testsBaseURL: url, logsBaseURL: url)
136137
}
137138

139+
codeCoveragePriority = env[.ciVisibilityCodeCoveragePriority] ?? .utility
140+
138141
disableTracesExporting = env[.dontExport] ?? false
139142
reportHostname = env[.ciVisibilityReportHostname] ?? false
140143
extraDebugCallStack = env[.traceDebugCallStack] ?? false
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2020-Present Datadog, Inc.
5+
*/
6+
7+
import Foundation
8+
9+
enum CodeCoveragePriority: Int, EnvironmentValue {
10+
case background = 0
11+
case utility = 1
12+
case userInitiated = 2
13+
case userInteractive = 3
14+
15+
var qos: QualityOfService {
16+
switch self {
17+
case .background: return .background
18+
case .utility: return .utility
19+
case .userInitiated: return .userInitiated
20+
case .userInteractive: return .userInteractive
21+
}
22+
}
23+
24+
init?(configValue: String) {
25+
guard let int = Int(configValue: configValue) else {
26+
return nil
27+
}
28+
guard let priority = Self(rawValue: int) else {
29+
return nil
30+
}
31+
self = priority
32+
}
33+
}

Sources/DatadogSDKTesting/Coverage/DDCoverageHelper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DDCoverageHelper {
1616
var initialCoverageSaved: Bool
1717
let coverageWorkQueue: OperationQueue
1818

19-
init?(storagePath: Directory) {
19+
init?(storagePath: Directory, priority: CodeCoveragePriority) {
2020
guard let profilePath = Self.profileGetFileName(), BinaryImages.profileImages.count > 0 else {
2121
Log.print("Coverage not properly enabled in project, check documentation")
2222
Log.debug("LLVM_PROFILE_FILE: \(Self.profileGetFileName() ?? "NIL")")
@@ -35,7 +35,7 @@ class DDCoverageHelper {
3535
Log.debug("DDCoverageHelper location: \(path.url.path)")
3636
initialCoverageSaved = false
3737
coverageWorkQueue = OperationQueue()
38-
coverageWorkQueue.qualityOfService = .utility
38+
coverageWorkQueue.qualityOfService = priority.qos
3939
coverageWorkQueue.maxConcurrentOperationCount = max(ProcessInfo.processInfo.activeProcessorCount - 1, 1)
4040
setFileLimit()
4141
}

Sources/DatadogSDKTesting/DDTestMonitor.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ internal class DDTestMonitor {
322322
coverageHelper = nil
323323
return
324324
}
325-
coverageHelper = DDCoverageHelper(storagePath: temp)
325+
coverageHelper = DDCoverageHelper(storagePath: temp,
326+
priority: DDTestMonitor.config.codeCoveragePriority)
326327
} else {
327328
Log.debug("Coverage Disabled")
328329
coverageHelper = nil

Sources/DatadogSDKTesting/Environment/EnvironmentKeys.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal enum EnvironmentKey: String, CaseIterable {
3939
case enableCiVisibilityLogs = "DD_CIVISIBILITY_LOGS_ENABLED"
4040
case enableCiVisibilityGitUpload = "DD_CIVISIBILITY_GIT_UPLOAD_ENABLED"
4141
case enableCiVisibilityCodeCoverage = "DD_CIVISIBILITY_CODE_COVERAGE_ENABLED"
42+
case ciVisibilityCodeCoveragePriority = "DD_CIVISIBILITY_CODE_COVERAGE_PRIORITY"
4243
case enableCiVisibilityITR = "DD_CIVISIBILITY_ITR_ENABLED"
4344
case ciVisibilityExcludedBranches = "DD_CIVISIBILITY_EXCLUDED_BRANCHES"
4445
case ciVisibilityReportHostname = "DD_CIVISIBILITY_REPORT_HOSTNAME"
@@ -58,7 +59,7 @@ extension EnvironmentKey {
5859
[.isEnabled, .apiKey, .environment, .service, .sourcesDir, .tags,
5960
.disableTestInstrumenting, .disableNetworkInstrumentation, .disableHeadersInjection,
6061
.instrumentationExtraHeaders, .excludedURLs, .enableRecordPayload, disableNetworkCallStack,
61-
.enableNetworkCallStackSymbolicated, .disableRumIntegration, .maxPayloadSize,
62+
.enableNetworkCallStackSymbolicated, .disableRumIntegration, .maxPayloadSize, .ciVisibilityCodeCoveragePriority,
6263
.enableCiVisibilityLogs, .enableStdoutInstrumentation, .enableStderrInstrumentation,
6364
.disableSdkIosIntegration, .disableCrashHandler, .disableMachCrashHandler, .site, .customURL,
6465
.dontExport, .traceDebug, .traceDebugNetwork, .traceDebugCallStack, .disableNTPClock]

0 commit comments

Comments
 (0)