Skip to content

Commit 33d95a3

Browse files
authored
Merge pull request #18984 from graydon/follow-my-simple-instruction
2 parents f110942 + e7903f9 commit 33d95a3

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ function (swift_benchmark_compile_archopts)
315315
if (is_darwin)
316316
list(APPEND common_options
317317
"-I" "${srcdir}/utils/ObjectiveCTests"
318+
"-I" "${srcdir}/utils/LibProc"
318319
"-F" "${sdk}/../../../Developer/Library/Frameworks"
319320
"-sdk" "${sdk}"
320321
"-no-link-objc-runtime")
@@ -344,6 +345,7 @@ function (swift_benchmark_compile_archopts)
344345
list(APPEND common_options_driver
345346
"-sdk" "${sdk}"
346347
"-F" "${sdk}/../../../Developer/Library/Frameworks"
348+
"-I" "${srcdir}/utils/LibProc"
347349
"-no-link-objc-runtime")
348350
endif()
349351
set(bench_library_objects)

benchmark/utils/DriverUtils.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import Glibc
1515
#else
1616
import Darwin
17+
import LibProc
1718
#endif
1819

1920
import TestsUtils
@@ -297,6 +298,27 @@ final class SampleRunner {
297298
(start, end, lastYield) = (now, now, now)
298299
}
299300

301+
#if os(Linux)
302+
private static func getExecutedInstructions() -> UInt64 {
303+
// FIXME: there is a Linux PMC API you can use to get this, but it's
304+
// not quite so straightforward.
305+
return 0
306+
}
307+
#else
308+
private static func getExecutedInstructions() -> UInt64 {
309+
if #available(OSX 10.9, iOS 7.0, *) {
310+
var u = rusage_info_v4()
311+
let p = UnsafeMutablePointer(&u)
312+
p.withMemoryRebound(to: Optional<rusage_info_t>.self, capacity: 1) { up in
313+
let _ = proc_pid_rusage(getpid(), RUSAGE_INFO_V4, up)
314+
}
315+
return u.ri_instructions
316+
} else {
317+
return 0
318+
}
319+
}
320+
#endif
321+
300322
private static func getResourceUtilization() -> rusage {
301323
var u = rusage(); getrusage(RUSAGE_SELF, &u); return u
302324
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===--- LibProcIncludeSystemHeader.h -------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// This file exists to include the not-yet-modularized libproc.h system header.
14+
15+
#if __has_include(<libproc.h>)
16+
#include <libproc.h>
17+
#else
18+
#include <Availability.h>
19+
#include <sys/resource.h>
20+
// Some SDKs are missing the libproc.h header, despite this symbol being present.
21+
int proc_pid_rusage(int pid, int flavor, rusage_info_t *buffer) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
22+
#endif
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===--- module.modulemap -------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
module LibProc {
14+
header "LibProcIncludeSystemHeader.h"
15+
export *
16+
}

0 commit comments

Comments
 (0)