-
Notifications
You must be signed in to change notification settings - Fork 85
feat: Add PerformanceTests #1910
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
597be9d
initial testing script
dayaffe 9a94a6b
refactor code
dayaffe c0fed01
remove region from client definition
dayaffe 23f311f
remove test.sh as its generated later
dayaffe 93f94ca
Merge branch 'main' into day/roader-runner-onboard
dayaffe d2dfeed
move files around and rename
dayaffe 08c6b29
move more around
dayaffe 5900dd9
some minor changes
dayaffe 70d8d33
Merge branch 'main' into day/roader-runner-onboard
dayaffe 853b5d0
Merge branch 'main' into day/roader-runner-onboard
dayaffe b7e9ad4
docstrings
dayaffe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// swift-tools-version: 5.9 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "SDKWorkbench", | ||
platforms: [.macOS(.v12), .iOS(.v15)], | ||
dependencies: [ | ||
.package(name: "aws-sdk-swift", path: "../../aws-sdk-swift"), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "PerformanceTestScript", | ||
sichanyoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dependencies: [ | ||
.product(name: "AWSSTS", package: "aws-sdk-swift"), | ||
] | ||
), | ||
] | ||
) |
38 changes: 38 additions & 0 deletions
38
PerformanceTests/Sources/PerformanceTestScript/PerformanceTestRun.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
import ClientRuntime | ||
|
||
// MARK: - Main Entry Point | ||
@main | ||
struct PerformanceTestRun { | ||
sichanyoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
static func main() async throws { | ||
let runner = BenchmarkRunner(iterations: 5) | ||
let commitId = ProcessRunner.getGitCommitId() | ||
let sdkVersion = ProcessRunner.getSdkVersion() | ||
|
||
// Add more tests here | ||
let performanceTests = [ | ||
AWSSTSGetCallerIdentity() | ||
] | ||
|
||
var benchmarks: [BenchmarkResult] = [] | ||
for test in performanceTests { | ||
let result = try await runner.runBenchmark(test) | ||
benchmarks.append(result) | ||
} | ||
|
||
let report = BenchmarkReport( | ||
productId: "AWS SDK for Swift", | ||
sdkVersion: sdkVersion, | ||
commitId: commitId, | ||
results: benchmarks | ||
) | ||
report.printFormatted() | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
PerformanceTests/Sources/PerformanceTestScript/Tests/AWSSTSTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import AWSSTS | ||
import Foundation | ||
|
||
struct AWSSTSGetCallerIdentity: PerformanceTest { | ||
let name = "sts.getcalleridentity.latency" | ||
|
||
let description = "The total time between initiating a GetCallerIdentity and reading the last byte of the object." | ||
|
||
let unit = "Milliseconds" | ||
|
||
let dimensions = [ | ||
Dimension(name: "OS", value: OperatingSystem.current.rawValue), | ||
] | ||
|
||
let test = getCallerIdentity | ||
|
||
static func getCallerIdentity() async throws -> Double { | ||
let start = Date() | ||
let client = try await STSClient() | ||
_ = try await client.getCallerIdentity(input: .init()) | ||
return Date().timeIntervalSince(start) * 1000 // Convert seconds to milliseconds | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
PerformanceTests/Sources/PerformanceTestScript/Util/Benchmark.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
sichanyoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
struct BenchmarkResult: Codable { | ||
sichanyoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let name: String | ||
let description: String | ||
let unit: String | ||
sichanyoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let date: Int | ||
let measurements: [Double] | ||
let dimensions: [Dimension]? | ||
} | ||
|
||
struct Dimension: Codable { | ||
let name: String | ||
let value: String | ||
} | ||
|
||
struct BenchmarkReport: Codable { | ||
let productId: String | ||
sichanyoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let sdkVersion: String? | ||
let commitId: String | ||
let results: [BenchmarkResult] | ||
} | ||
|
||
struct BenchmarkRunner { | ||
sichanyoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var iterations: Int | ||
|
||
/// Executes the given test multiple times | ||
func runBenchmark( | ||
_ perfTest: PerformanceTest | ||
) async throws -> BenchmarkResult { | ||
var measurements: [Double] = [] | ||
|
||
for _ in 0..<iterations { | ||
measurements.append(try await perfTest.test()) | ||
} | ||
|
||
let timestamp = Int(Date().timeIntervalSince1970) | ||
return BenchmarkResult( | ||
name: perfTest.name, | ||
description: perfTest.description, | ||
unit: perfTest.unit, | ||
date: timestamp, | ||
measurements: measurements, | ||
dimensions: perfTest.dimensions | ||
) | ||
} | ||
} | ||
|
||
extension BenchmarkReport { | ||
func printFormatted() { | ||
let jsonEncoder = JSONEncoder() | ||
jsonEncoder.outputFormatting = .prettyPrinted | ||
|
||
if let jsonData = try? jsonEncoder.encode(self), | ||
let jsonString = String(data: jsonData, encoding: .utf8) { | ||
print(jsonString) | ||
} else { | ||
print("Error encoding JSON") | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
PerformanceTests/Sources/PerformanceTestScript/Util/OperatingSystem.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
enum OperatingSystem: String { | ||
case macOS = "macOS" | ||
case Linux = "Linux" | ||
case Unknown = "Unknown" | ||
|
||
static var current: OperatingSystem { | ||
#if os(macOS) | ||
return .macOS | ||
#elseif os(Linux) | ||
return .Linux | ||
#else | ||
return .Unknown | ||
#endif | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
PerformanceTests/Sources/PerformanceTestScript/Util/PerformanceTest.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
protocol PerformanceTest { | ||
var name: String { get } | ||
var description: String { get } | ||
var unit: String { get } | ||
var dimensions: [Dimension] { get } | ||
var test: () async throws -> Double { get } | ||
} |
43 changes: 43 additions & 0 deletions
43
PerformanceTests/Sources/PerformanceTestScript/Util/ProcessRunner.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
struct ProcessRunner { | ||
static func runProcess( | ||
executable: String = "/usr/bin/env", | ||
arguments: [String] | ||
) -> String { | ||
let process = Process() | ||
process.executableURL = URL(fileURLWithPath: executable) | ||
process.arguments = arguments | ||
|
||
let outputPipe = Pipe() | ||
process.standardOutput = outputPipe | ||
process.standardError = Pipe() | ||
|
||
do { | ||
try process.run() | ||
process.waitUntilExit() | ||
let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile() | ||
return String(data: outputData, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" | ||
} catch { | ||
print("ProcessRunner Error: \(error.localizedDescription)") | ||
return "" | ||
} | ||
} | ||
|
||
/// Retrieves the current Git commit ID. | ||
static func getGitCommitId() -> String { | ||
return ProcessRunner.runProcess(arguments: ["git", "rev-parse", "HEAD"]) | ||
} | ||
|
||
/// Retrieves the SDK version from a file. | ||
static func getSdkVersion() -> String { | ||
return ProcessRunner.runProcess(arguments: ["cat", "../../aws-sdk-swift/Package.version"]) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.