macos: add benchmark tests to our Xcode project

This commit is contained in:
Mitchell Hashimoto
2025-07-09 13:22:04 -07:00
parent 20bb71c627
commit c990d35d6d
5 changed files with 229 additions and 16 deletions

View File

@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 56;
objectVersion = 70;
objects = {
/* Begin PBXBuildFile section */
@ -152,6 +152,16 @@
FC9ABA9C2D0F53F80020D4C8 /* bash-completion in Resources */ = {isa = PBXBuildFile; fileRef = FC9ABA9B2D0F538D0020D4C8 /* bash-completion */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
A54F45F72E1F047A0046BD5C /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = A5B30529299BEAAA0047F10C /* Project object */;
proxyType = 1;
remoteGlobalIDString = A5B30530299BEAAA0047F10C;
remoteInfo = Ghostty;
};
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
29C15B1C2CDC3B2000520DD4 /* bat */ = {isa = PBXFileReference; lastKnownFileType = folder; name = bat; path = "../zig-out/share/bat"; sourceTree = "<group>"; };
3B39CAA42B33949B00DABEB8 /* GhosttyReleaseLocal.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GhosttyReleaseLocal.entitlements; sourceTree = "<group>"; };
@ -199,6 +209,7 @@
A54B0CEC2D0CFB7300CBEFF8 /* ColorizedGhosttyIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorizedGhosttyIcon.swift; sourceTree = "<group>"; };
A54B0CEE2D0D2E2400CBEFF8 /* ColorizedGhosttyIconImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorizedGhosttyIconImage.swift; sourceTree = "<group>"; };
A54D786B2CA79788001B19B1 /* BaseTerminalController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTerminalController.swift; sourceTree = "<group>"; };
A54F45F32E1F047A0046BD5C /* GhosttyTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GhosttyTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
A553F4122E06EB1600257779 /* Ghostty.icon */ = {isa = PBXFileReference; lastKnownFileType = folder.iconcomposer.icon; name = Ghostty.icon; path = ../images/Ghostty.icon; sourceTree = SOURCE_ROOT; };
A5593FDE2DF8D57100B47B10 /* TerminalWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalWindow.swift; sourceTree = "<group>"; };
A5593FE02DF8D73400B47B10 /* HiddenTitlebarTerminalWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HiddenTitlebarTerminalWindow.swift; sourceTree = "<group>"; };
@ -291,7 +302,18 @@
FC9ABA9B2D0F538D0020D4C8 /* bash-completion */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "bash-completion"; path = "../zig-out/share/bash-completion"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFileSystemSynchronizedRootGroup section */
A54F45F42E1F047A0046BD5C /* GhosttyTests */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = GhosttyTests; sourceTree = "<group>"; };
/* End PBXFileSystemSynchronizedRootGroup section */
/* Begin PBXFrameworksBuildPhase section */
A54F45F02E1F047A0046BD5C /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
A5B3052E299BEAAA0047F10C /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
@ -590,6 +612,7 @@
A51BFC282B30F26D00E92F16 /* GhosttyDebug.entitlements */,
3B39CAA42B33949B00DABEB8 /* GhosttyReleaseLocal.entitlements */,
A54CD6ED299BEB14008C95BB /* Sources */,
A54F45F42E1F047A0046BD5C /* GhosttyTests */,
A5D495A3299BECBA00DD1313 /* Frameworks */,
A5A1F8862A489D7400D1E8BC /* Resources */,
A5B30532299BEAAA0047F10C /* Products */,
@ -601,6 +624,7 @@
children = (
A5B30531299BEAAA0047F10C /* Ghostty.app */,
A5D4499D2B53AE7B000F5B83 /* Ghostty-iOS.app */,
A54F45F32E1F047A0046BD5C /* GhosttyTests.xctest */,
);
name = Products;
sourceTree = "<group>";
@ -674,6 +698,29 @@
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
A54F45F22E1F047A0046BD5C /* GhosttyTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = A54F45FC2E1F047A0046BD5C /* Build configuration list for PBXNativeTarget "GhosttyTests" */;
buildPhases = (
A54F45EF2E1F047A0046BD5C /* Sources */,
A54F45F02E1F047A0046BD5C /* Frameworks */,
A54F45F12E1F047A0046BD5C /* Resources */,
);
buildRules = (
);
dependencies = (
A54F45F82E1F047A0046BD5C /* PBXTargetDependency */,
);
fileSystemSynchronizedGroups = (
A54F45F42E1F047A0046BD5C /* GhosttyTests */,
);
name = GhosttyTests;
packageProductDependencies = (
);
productName = GhosttyTests;
productReference = A54F45F32E1F047A0046BD5C /* GhosttyTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
A5B30530299BEAAA0047F10C /* Ghostty */ = {
isa = PBXNativeTarget;
buildConfigurationList = A5B30540299BEAAB0047F10C /* Build configuration list for PBXNativeTarget "Ghostty" */;
@ -718,9 +765,13 @@
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1520;
LastSwiftUpdateCheck = 2600;
LastUpgradeCheck = 1610;
TargetAttributes = {
A54F45F22E1F047A0046BD5C = {
CreatedOnToolsVersion = 26.0;
TestTargetID = A5B30530299BEAAA0047F10C;
};
A5B30530299BEAAA0047F10C = {
CreatedOnToolsVersion = 14.2;
LastSwiftMigration = 1510;
@ -748,11 +799,19 @@
targets = (
A5B30530299BEAAA0047F10C /* Ghostty */,
A5D4499C2B53AE7B000F5B83 /* Ghostty-iOS */,
A54F45F22E1F047A0046BD5C /* GhosttyTests */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
A54F45F12E1F047A0046BD5C /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
A5B3052F299BEAAA0047F10C /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
@ -794,6 +853,13 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
A54F45EF2E1F047A0046BD5C /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
A5B3052D299BEAAA0047F10C /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
@ -925,6 +991,14 @@
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
A54F45F82E1F047A0046BD5C /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = A5B30530299BEAAA0047F10C /* Ghostty */;
targetProxy = A54F45F72E1F047A0046BD5C /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
3B39CAA22B33946300DABEB8 /* ReleaseLocal */ = {
isa = XCBuildConfiguration;
@ -1034,6 +1108,76 @@
};
name = ReleaseLocal;
};
A54F45F92E1F047A0046BD5C /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GENERATE_INFOPLIST_FILE = YES;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 15.5;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.mitchellh.GhosttyTests;
PRODUCT_NAME = "$(TARGET_NAME)";
STRING_CATALOG_GENERATE_SYMBOLS = NO;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_APPROACHABLE_CONCURRENCY = YES;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Ghostty.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/ghostty";
};
name = Debug;
};
A54F45FA2E1F047A0046BD5C /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GENERATE_INFOPLIST_FILE = YES;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 15.5;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.mitchellh.GhosttyTests;
PRODUCT_NAME = "$(TARGET_NAME)";
STRING_CATALOG_GENERATE_SYMBOLS = NO;
SWIFT_APPROACHABLE_CONCURRENCY = YES;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Ghostty.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/ghostty";
};
name = Release;
};
A54F45FB2E1F047A0046BD5C /* ReleaseLocal */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GENERATE_INFOPLIST_FILE = YES;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 15.5;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.mitchellh.GhosttyTests;
PRODUCT_NAME = "$(TARGET_NAME)";
STRING_CATALOG_GENERATE_SYMBOLS = NO;
SWIFT_APPROACHABLE_CONCURRENCY = YES;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Ghostty.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/ghostty";
};
name = ReleaseLocal;
};
A5B3053E299BEAAB0047F10C /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
@ -1378,6 +1522,16 @@
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
A54F45FC2E1F047A0046BD5C /* Build configuration list for PBXNativeTarget "GhosttyTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
A54F45F92E1F047A0046BD5C /* Debug */,
A54F45FA2E1F047A0046BD5C /* Release */,
A54F45FB2E1F047A0046BD5C /* ReleaseLocal */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = ReleaseLocal;
};
A5B3052C299BEAAA0047F10C /* Build configuration list for PBXProject "Ghostty" */ = {
isa = XCConfigurationList;
buildConfigurations = (

View File

@ -28,6 +28,19 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A54F45F22E1F047A0046BD5C"
BuildableName = "GhosttyTests.xctest"
BlueprintName = "GhosttyTests"
ReferencedContainer = "container:Ghostty.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"

View File

@ -0,0 +1,32 @@
//
// GhosttyTests.swift
// GhosttyTests
//
// Created by Mitchell Hashimoto on 7/9/25.
//
import Testing
import GhosttyKit
extension Tag {
@Tag static var benchmark: Self
}
/// The whole idea behind these benchmarks is that they're run by right-clicking
/// in Xcode and using "Profile" to open them in instruments. They aren't meant to
/// be run in general.
///
/// When running them, set the `if:` to `true`. There's probably a better
/// programmatic way to do this but I don't know it yet!
@Suite(
"Benchmarks",
.enabled(if: false),
.tags(.benchmark)
)
struct BenchmarkTests {
@Test func example() async throws {
ghostty_benchmark_cli(
"terminal-stream",
"--data=/Users/mitchellh/Documents/ghostty/bug.osc.txt")
}
}

View File

@ -13,18 +13,23 @@ const Log = logpkg.Log;
pub fn init() void {
if (__dso_handle != null) return;
const root = @import("root");
const sym = if (@hasDecl(root, "main"))
root.main
else
comptime first: {
for (@typeInfo(root).@"struct".decls) |decl_info| {
const decl = @field(root, decl_info.name);
if (@typeInfo(@TypeOf(decl)) == .@"fn") break :first decl;
}
const sym = comptime sym: {
const root = @import("root");
@compileError("No functions found in root module");
};
// If we have a main function, use that as the symbol.
if (@hasDecl(root, "main")) break :sym root.main;
// Otherwise, we're in a library, so we just use the first
// function in our root module. I actually don't know if this is
// all required or if we can just use the real `__dso_handle` symbol,
// but this seems to work for now.
for (@typeInfo(root).@"struct".decls) |decl_info| {
const decl = @field(root, decl_info.name);
if (@typeInfo(@TypeOf(decl)) == .@"fn") break :sym decl;
}
@compileError("no functions found in root module");
};
// Since __dso_handle is not automatically populated by the linker,
// we populate it by looking up the main function's module address

View File

@ -21,6 +21,8 @@ const Benchmark = @import("Benchmark.zig");
const Terminal = terminalpkg.Terminal;
const Stream = terminalpkg.Stream(*Handler);
const log = std.log.scoped(.@"terminal-stream-bench");
opts: Options,
terminal: Terminal,
handler: Handler,
@ -88,8 +90,10 @@ fn setup(ptr: *anyopaque) Benchmark.Error!void {
// validation here eventually.
assert(self.data_f == null);
if (self.opts.data) |path| {
self.data_f = std.fs.cwd().openFile(path, .{}) catch
self.data_f = std.fs.cwd().openFile(path, .{}) catch |err| {
log.warn("error opening data file err={}", .{err});
return error.BenchmarkFailed;
};
}
}
@ -114,11 +118,16 @@ fn step(ptr: *anyopaque) Benchmark.Error!void {
var buf: [4096]u8 = undefined;
while (true) {
const n = r.read(&buf) catch return error.BenchmarkFailed;
const n = r.read(&buf) catch |err| {
log.warn("error reading data file err={}", .{err});
return error.BenchmarkFailed;
};
if (n == 0) break; // EOF reached
const chunk = buf[0..n];
self.stream.nextSlice(chunk) catch
self.stream.nextSlice(chunk) catch |err| {
log.warn("error processing data file chunk err={}", .{err});
return error.BenchmarkFailed;
};
}
}