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

increase amount of open files for code coverage #129

Merged
merged 1 commit into from
Aug 22, 2024
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
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