Skip to content

Commit 4df1586

Browse files
author
Joe Shajrawi
authored
Merge pull request #12073 from shajrawi/bench_tags
Benchmark categorization support
2 parents aee81d2 + ca6ccb4 commit 4df1586

File tree

3 files changed

+591
-487
lines changed

3 files changed

+591
-487
lines changed

benchmark/utils/DriverUtils.swift

Lines changed: 92 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ struct Test {
5656
let index: Int
5757
let f: (Int) -> ()
5858
let run: Bool
59+
let tags: [BenchmarkCategories]
5960
}
6061

6162
// Legacy test dictionaries.
62-
public var precommitTests: [String : (Int) -> ()] = [:]
63-
public var otherTests: [String : (Int) -> ()] = [:]
64-
public var stringTests: [String : (Int) -> ()] = [:]
63+
public var precommitTests: [String : ((Int) -> (), [BenchmarkCategories])] = [:]
64+
public var otherTests: [String : ((Int) -> (), [BenchmarkCategories])] = [:]
65+
public var stringTests: [String : ((Int) -> (), [BenchmarkCategories])] = [:]
6566

6667
// We should migrate to a collection of BenchmarkInfo.
6768
public var registeredBenchmarks = [TestsUtils.BenchmarkInfo]()
@@ -79,6 +80,9 @@ struct TestConfig {
7980
/// The filters applied to our test names.
8081
var filters = [String]()
8182

83+
/// The tag that we want to run
84+
var tags = Set<BenchmarkCategories>()
85+
8286
/// The scalar multiple of the amount of times a test should be run. This
8387
/// enables one to cause tests to run for N iterations longer than they
8488
/// normally would. This is useful when one wishes for a test to run for a
@@ -115,7 +119,7 @@ struct TestConfig {
115119
let validOptions = [
116120
"--iter-scale", "--num-samples", "--num-iters",
117121
"--verbose", "--delim", "--run-all", "--list", "--sleep",
118-
"--registered"
122+
"--registered", "--tags"
119123
]
120124
let maybeBenchArgs: Arguments? = parseArgs(validOptions)
121125
if maybeBenchArgs == nil {
@@ -150,6 +154,73 @@ struct TestConfig {
150154
delim = x
151155
}
152156

157+
if let x = benchArgs.optionalArgsMap["--tags"] {
158+
if x.isEmpty { return .Fail("--tags requires a value") }
159+
if x.contains("cpubench") {
160+
tags.insert(BenchmarkCategories.cpubench)
161+
}
162+
if x.contains("unstable") {
163+
tags.insert(BenchmarkCategories.unstable)
164+
}
165+
if x.contains("validation") {
166+
tags.insert(BenchmarkCategories.validation)
167+
}
168+
if x.contains("api") {
169+
tags.insert(BenchmarkCategories.api)
170+
}
171+
if x.contains("Array") {
172+
tags.insert(BenchmarkCategories.Array)
173+
}
174+
if x.contains("String") {
175+
tags.insert(BenchmarkCategories.String)
176+
}
177+
if x.contains("Dictionary") {
178+
tags.insert(BenchmarkCategories.Dictionary)
179+
}
180+
if x.contains("Codable") {
181+
tags.insert(BenchmarkCategories.Codable)
182+
}
183+
if x.contains("Set") {
184+
tags.insert(BenchmarkCategories.Set)
185+
}
186+
if x.contains("sdk") {
187+
tags.insert(BenchmarkCategories.sdk)
188+
}
189+
if x.contains("runtime") {
190+
tags.insert(BenchmarkCategories.runtime)
191+
}
192+
if x.contains("refcount") {
193+
tags.insert(BenchmarkCategories.refcount)
194+
}
195+
if x.contains("metadata") {
196+
tags.insert(BenchmarkCategories.metadata)
197+
}
198+
if x.contains("abstraction") {
199+
tags.insert(BenchmarkCategories.abstraction)
200+
}
201+
if x.contains("safetychecks") {
202+
tags.insert(BenchmarkCategories.safetychecks)
203+
}
204+
if x.contains("exceptions") {
205+
tags.insert(BenchmarkCategories.exceptions)
206+
}
207+
if x.contains("bridging") {
208+
tags.insert(BenchmarkCategories.bridging)
209+
}
210+
if x.contains("concurrency") {
211+
tags.insert(BenchmarkCategories.concurrency)
212+
}
213+
if x.contains("algorithm") {
214+
tags.insert(BenchmarkCategories.algorithm)
215+
}
216+
if x.contains("miniapplication") {
217+
tags.insert(BenchmarkCategories.miniapplication)
218+
}
219+
if x.contains("regression") {
220+
tags.insert(BenchmarkCategories.regression)
221+
}
222+
}
223+
153224
if let _ = benchArgs.optionalArgsMap["--run-all"] {
154225
onlyPrecommit = false
155226
}
@@ -177,35 +248,41 @@ struct TestConfig {
177248
}
178249

179250
mutating func findTestsToRun() {
180-
var allTests: [(key: String, value: (Int)-> ())]
251+
var allTests: [(key: String, value: ((Int) -> (), [BenchmarkCategories]))]
181252

182253
if onlyRegistered {
183254
allTests = registeredBenchmarks.map {
184-
bench -> (key: String, value: (Int)-> ()) in
185-
return (bench.name, bench.runFunction)
255+
bench -> (key: String, value: ((Int) -> (), [BenchmarkCategories])) in
256+
(bench.name, (bench.runFunction, bench.tags))
186257
}
187258
// FIXME: for now unstable/extra benchmarks are not registered at all, but
188259
// soon they will be handled with a default exclude list.
189260
onlyPrecommit = false
190261
}
191262
else {
192263
allTests = [precommitTests, otherTests, stringTests]
193-
.map { dictionary -> [(key: String, value: (Int)-> ())] in
264+
.map { dictionary -> [(key: String, value: ((Int) -> (), [BenchmarkCategories]))] in
194265
Array(dictionary).sorted { $0.key < $1.key } } // by name
195266
.flatMap { $0 }
196267
}
197268

269+
let filteredTests = allTests.filter { pair in tags.isSubset(of: pair.value.1)}
270+
if (filteredTests.isEmpty) {
271+
return;
272+
}
273+
198274
let included =
199275
!filters.isEmpty ? Set(filters)
200276
: onlyPrecommit ? Set(precommitTests.keys)
201-
: Set(allTests.map { $0.key })
277+
: Set(filteredTests.map { $0.key })
202278

203-
tests = zip(1...allTests.count, allTests).map {
279+
tests = zip(1...filteredTests.count, filteredTests).map {
204280
t -> Test in
205-
let (ordinal, (key: name, value: function)) = t
206-
return Test(name: name, index: ordinal, f: function,
281+
let (ordinal, (key: name, value: funcAndTags)) = t
282+
return Test(name: name, index: ordinal, f: funcAndTags.0,
207283
run: included.contains(name)
208-
|| included.contains(String(ordinal)))
284+
|| included.contains(String(ordinal)),
285+
tags: funcAndTags.1)
209286
}
210287
}
211288
}
@@ -426,9 +503,9 @@ public func main() {
426503
fatalError("\(msg)")
427504
case .ListTests:
428505
config.findTestsToRun()
429-
print("Enabled Tests:")
506+
print("Enabled Tests\(config.delim)Tags")
430507
for t in config.tests where t.run == true {
431-
print(" \(t.name)")
508+
print("\(t.name)\(config.delim)\(t.tags)")
432509
}
433510
case .Run:
434511
config.findTestsToRun()

benchmark/utils/TestsUtils.swift

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import Glibc
1616
import Darwin
1717
#endif
1818

19-
public enum BenchmarkCategories {
19+
public enum BenchmarkCategories : CustomStringConvertible {
2020
// Validation "micro" benchmarks test a specific operation or critical path that
2121
// we know is important to measure.
2222
case validation
2323
// subsystems to validate and their subcategories.
24-
case api, Array, String, Dictionary, Codable
24+
case api, Array, String, Dictionary, Codable, Set
2525
case sdk
2626
case runtime, refcount, metadata
2727
// Other general areas of compiled code validation.
@@ -65,6 +65,32 @@ case unstable
6565
// reimplementing or call into code paths that have known opportunities for
6666
// significant optimization.
6767
case cpubench
68+
69+
public var description : String {
70+
switch self {
71+
case .cpubench: return "cpubench"
72+
case .unstable: return "unstable"
73+
case .validation: return "validation"
74+
case .api: return "api"
75+
case .Array: return "Array"
76+
case .String: return "String"
77+
case .Dictionary: return "Dictionary"
78+
case .Codable: return "Codable"
79+
case .Set: return "Set"
80+
case .sdk: return "sdk"
81+
case .runtime: return "runtime"
82+
case .refcount: return "refcount"
83+
case .metadata: return "metadata"
84+
case .abstraction: return "abstraction"
85+
case .safetychecks: return "safetychecks"
86+
case .exceptions: return "exceptions"
87+
case .bridging: return "bridging"
88+
case .concurrency: return "concurrency"
89+
case .algorithm: return "algorithm"
90+
case .miniapplication: return "miniapplication"
91+
case .regression: return "regression"
92+
}
93+
}
6894
}
6995

7096
public struct BenchmarkInfo {

0 commit comments

Comments
 (0)