Skip to content

Commit

Permalink
increase amount of open files for code coverage (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
ypopovych authored Aug 22, 2024
1 parent 6a0dd8c commit 727835f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Sources/DatadogSDKTesting/Coverage/DDCoverageHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DDCoverageHelper {
coverageWorkQueue = OperationQueue()
coverageWorkQueue.qualityOfService = .utility
coverageWorkQueue.maxConcurrentOperationCount = max(ProcessInfo.processInfo.activeProcessorCount - 1, 1)
setFileLimit()
}

func clearCounters() {
Expand All @@ -47,6 +48,23 @@ class DDCoverageHelper {
$0.endCountersFuncPtr)
}
}

private func setFileLimit() {
var limit = rlimit()
let filesMax = 4096
guard getrlimit(RLIMIT_NOFILE, &limit) == 0 else {
Log.debug("Can't get open file limit")
return
}
guard limit.rlim_cur < filesMax else { return }
limit.rlim_cur = rlim_t(filesMax)
limit.rlim_max = rlim_t(filesMax * 8)
if setrlimit(RLIMIT_NOFILE, &limit) == 0 {
Log.debug("Updated open file limit to \(filesMax)")
} else {
Log.debug("Can't increase open file limit")
}
}

func setTest(name: String, testSessionId: UInt64, testSuiteId: UInt64, spanId: UInt64) {
if !self.initialCoverageSaved {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal class CoverageExporter {
do {
profData = try DDCoverageConversor.generateProfData(profrawFile: coverage)
} catch {
Log.print("Profiler Data genetation failed: \(error)")
Log.print("Profiler Data generation failed: \(error)")
return
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/EventsExporter/Utils/Spawn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public enum Spawn {

var childActions: posix_spawn_file_actions_t?
dd_posix_spawn_file_actions_init(&childActions)
defer { dd_posix_spawn_file_actions_destroy(&childActions) }

let outFile: URL?
let errFile: URL?
Expand Down Expand Up @@ -85,6 +84,8 @@ public enum Spawn {
dd_posix_spawn(&pid, command, &childActions, nil, argv, nil)
}

dd_posix_spawn_file_actions_destroy(&childActions)

do {
try _wait(spawn: ret, pid: pid)
} catch let e as RunErrorCode {
Expand Down

0 comments on commit 727835f

Please sign in to comment.