-
Notifications
You must be signed in to change notification settings - Fork 83
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
feat: Add PerformanceTests #1910
Merged
Merged
Changes from 10 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 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: ".."), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "PerformanceTestRunner", | ||
dependencies: [ | ||
.product(name: "AWSSTS", package: "aws-sdk-swift"), | ||
] | ||
), | ||
] | ||
) |
11 changes: 11 additions & 0 deletions
11
PerformanceTests/Sources/PerformanceTestRunner/Core/Model/Dimension.swift
This file contains 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,11 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
struct Dimension: Codable { | ||
let name: String // The name of the dimension. MUST comply with CloudWatch constraints on dimension name. | ||
let value: String // The value of the dimension. MUST comply with CloudWatch constraints on dimension value. | ||
} |
14 changes: 14 additions & 0 deletions
14
PerformanceTests/Sources/PerformanceTestRunner/Core/Model/PerformanceTest.swift
This file contains 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: Unit { get } | ||
var dimensions: [Dimension] { get } | ||
var test: () async throws -> Double { get } | ||
} |
29 changes: 29 additions & 0 deletions
29
PerformanceTests/Sources/PerformanceTestRunner/Core/Model/PerformanceTestReport.swift
This file contains 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,29 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
struct PerformanceTestReport: Codable { | ||
var productId: String = "AWS SDK for Swift" | ||
let sdkVersion: String? | ||
let commitId: String | ||
let results: [PerformanceTestResult] | ||
} | ||
|
||
extension PerformanceTestReport { | ||
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") | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
PerformanceTests/Sources/PerformanceTestRunner/Core/Model/PerformanceTestResult.swift
This file contains 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,15 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
struct PerformanceTestResult: Codable { | ||
let name: String | ||
let description: String | ||
let unit: String | ||
let date: Int | ||
let measurements: [Double] | ||
let dimensions: [Dimension]? | ||
} |
21 changes: 21 additions & 0 deletions
21
PerformanceTests/Sources/PerformanceTestRunner/Core/Model/Unit.swift
This file contains 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,21 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
enum Unit: String { | ||
jbelkins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case operationsPerSecond = "Operations/Second" | ||
case bitsPerSecond = "Bits/Second" | ||
case megabitsPerSecond = "Megabits/Second" | ||
case gigabitsPerSecond = "Gigabits/Second" | ||
case seconds = "Seconds" | ||
case milliseconds = "Milliseconds" | ||
case microseconds = "Microseconds" | ||
case nanoseconds = "Nanoseconds" | ||
case bytes = "Bytes" | ||
case megabytes = "Megabytes" | ||
case gigabytes = "Gigabytes" | ||
case percentage = "Percentage" | ||
} |
34 changes: 34 additions & 0 deletions
34
PerformanceTests/Sources/PerformanceTestRunner/Core/Runners/PerformanceTestRunner.swift
This file contains 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,34 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
struct PerformanceTestRunner { | ||
|
||
var iterations: Int | ||
|
||
/// Executes the given test multiple times | ||
func runTest( | ||
_ perfTest: PerformanceTest | ||
) async throws -> PerformanceTestResult { | ||
var measurements: [Double] = [] | ||
|
||
for _ in 0..<iterations { | ||
measurements.append(try await perfTest.test()) | ||
} | ||
jbelkins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let timestamp = Int(Date().timeIntervalSince1970) | ||
return PerformanceTestResult( | ||
name: perfTest.name, | ||
description: perfTest.description, | ||
unit: perfTest.unit.rawValue, | ||
date: timestamp, | ||
measurements: measurements, | ||
dimensions: perfTest.dimensions | ||
) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
PerformanceTests/Sources/PerformanceTestRunner/Core/Runners/ProcessRunner.swift
This file contains 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,44 @@ | ||
// | ||
// 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 { | ||
let version = ProcessRunner.runProcess(arguments: ["cat", "../../aws-sdk-swift/Package.version"]) | ||
return version.trimmingCharacters(in: .whitespacesAndNewlines) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
PerformanceTests/Sources/PerformanceTestRunner/Core/Util/OperatingSystem.swift
This file contains 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 unknownOS = "Unknown" | ||
|
||
static var current: OperatingSystem { | ||
#if os(macOS) | ||
return .macOS | ||
#elseif os(Linux) | ||
return .linux | ||
#else | ||
return .unknownOS | ||
#endif | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
PerformanceTests/Sources/PerformanceTestRunner/PerformanceMain.swift
This file contains 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,37 @@ | ||
// | ||
// 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 PerformanceMain { | ||
static func main() async throws { | ||
let runner = PerformanceTestRunner(iterations: 5) | ||
let commitId = ProcessRunner.getGitCommitId() | ||
let sdkVersion = ProcessRunner.getSdkVersion() | ||
|
||
// Add more tests here | ||
let performanceTests = [ | ||
AWSSTSGetCallerIdentity() | ||
] | ||
|
||
var results: [PerformanceTestResult] = [] | ||
for test in performanceTests { | ||
let result = try await runner.runTest(test) | ||
results.append(result) | ||
} | ||
jbelkins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let report = PerformanceTestReport( | ||
sdkVersion: sdkVersion, | ||
commitId: commitId, | ||
results: results | ||
) | ||
report.printFormatted() | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
PerformanceTests/Sources/PerformanceTestRunner/Tests/AWSSTSTests.swift
This file contains 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 = Unit.milliseconds | ||
|
||
let dimensions = [ | ||
Dimension(name: "OS", value: OperatingSystem.current.rawValue), | ||
] | ||
|
||
let test = getCallerIdentity | ||
jbelkins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These may as well be doc comments (three slashes on line before property) so that they show in tooltip help
Also, the same sort of comments are appropriate on
PerformanceTestReport
andPerformanceTestResult
which also form the test report structure.