Skip to content

Commit

Permalink
chore: add testbed file if i ever need to investigate again
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Jan 7, 2025
1 parent db5644e commit 8b52dc8
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
4 changes: 4 additions & 0 deletions alt-tab-macos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
BF0C8C7F5F9EE501B240D2E3 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8532DEDE7C1218B90444 /* Localizable.strings */; };
BF0C8C8E35FF49CAA4BF5FC4 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8A970BD1CAD555F31EDA /* Localizable.strings */; };
BF0C8C9CA44285E493918A74 /* menubar-2@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8E54658B4DAEA0528200 /* menubar-2@2x.png */; };
BF0C8CBED8D88DFBADE7EC03 /* ConcurrentScreenshots.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8C6810FF50908E637A48 /* ConcurrentScreenshots.swift */; };
BF0C8CBF5B4EE15FDB53C94B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C861EE84489EF56879CBF /* InfoPlist.strings */; };
BF0C8CC5057406014FD612CC /* ATShortcut.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8BA452332236D972C60E /* ATShortcut.swift */; };
BF0C8D1C57D74106018D073C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C87F5D4AD51D6950C98B0 /* InfoPlist.strings */; };
Expand Down Expand Up @@ -452,6 +453,7 @@
BF0C8C5210ACA9FBFAE9C631 /* preferences-general.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "preferences-general.jpg"; sourceTree = "<group>"; };
BF0C8C5B74E5DA2CC31E52F4 /* extract_l10n_strings.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = extract_l10n_strings.sh; sourceTree = "<group>"; };
BF0C8C5C0FF5D567BF190DE5 /* ApplicationServices.HIServices.framework.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplicationServices.HIServices.framework.swift; sourceTree = "<group>"; };
BF0C8C6810FF50908E637A48 /* ConcurrentScreenshots.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConcurrentScreenshots.swift; sourceTree = "<group>"; };
BF0C8C69316EAAF6DC9AE391 /* CliEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CliEvents.swift; sourceTree = "<group>"; };
BF0C8C6995992F837A9A83A6 /* ca */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = ca; path = InfoPlist.strings; sourceTree = "<group>"; };
BF0C8C77273E00B019725640 /* add_missing_terms_on_poeditor.ts */ = {isa = PBXFileReference; lastKnownFileType = file.ts; path = add_missing_terms_on_poeditor.ts; sourceTree = "<group>"; };
Expand Down Expand Up @@ -969,6 +971,7 @@
BF0C84933936C6FE676CD33C /* AppearanceTests.swift */,
BF0C899905524253DC170B56 /* KeyboardEventsTests.swift */,
BF0C829EAA93A4C4ADB42CF8 /* Mocks.swift */,
BF0C8C6810FF50908E637A48 /* ConcurrentScreenshots.swift */,
);
path = "unit-tests";
sourceTree = "<group>";
Expand Down Expand Up @@ -2238,6 +2241,7 @@
BF0C8C5FA4B401A8C0F75B7A /* KeyboardEventsTestable.swift in Sources */,
BF0C875A28B98904F8F4A66A /* ATShortcut.swift in Sources */,
BF0C84E5AC1D423625ABF3E6 /* Mocks.swift in Sources */,
BF0C8CBED8D88DFBADE7EC03 /* ConcurrentScreenshots.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
124 changes: 124 additions & 0 deletions unit-tests/ConcurrentScreenshots.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//import XCTest
//
//import Cocoa
//
//@_silgen_name("CGSMainConnectionID")
//func CGSMainConnectionID() -> CGSConnectionID
//
//let CGS_CONNECTION = CGSMainConnectionID()
//typealias CGSConnectionID = UInt32
//typealias CGSSpaceID = UInt64
//
//struct CGSWindowCaptureOptions: OptionSet {
// let rawValue: UInt32
// static let ignoreGlobalClipShape = CGSWindowCaptureOptions(rawValue: 1 << 11)
// // on a retina display, 1px is spread on 4px, so nominalResolution is 1/4 of bestResolution
// static let nominalResolution = CGSWindowCaptureOptions(rawValue: 1 << 9)
// static let bestResolution = CGSWindowCaptureOptions(rawValue: 1 << 8)
//}
//
//@_silgen_name("CGSHWCaptureWindowList")
//func CGSHWCaptureWindowList(_ cid: CGSConnectionID, _ windowList: inout CGWindowID, _ windowCount: UInt32, _ options: CGSWindowCaptureOptions) -> Unmanaged<CFArray>
//
//typealias CGWindow = [CFString: Any]
//
//class Playground {
// static var batchId = 0
// static var startTime: UInt64!
// static var wid: CGWindowID!
// static let dispatchGroup = DispatchGroup()
// static let dispatchSemaphore = DispatchSemaphore(value: 8)
// // DispatchQueue.global()
// // 1: 21.4
// // 2: 11.2
// // 3: 8.1
// // 5: 6.5 // 3.2
// // 8: 5.9 // 3.1
// // 10: 5.5 // 3.0
// // 15: 5.2 // 3.3
// // 20: 5.2
// // 30: 5.2
// // 40: 5.2
// // 50: 5.6
// // 60: 10.7
// // no-cap: 93 // 93.3
// // custom-concurrent-queue no-cap: 91.3
// // custom DispatchQueue (serial)
// // no-cap: 5.1 // 3.2
// // no-cap qos:.userInteractive: 6.0
// // no-cap qos:.userInteractive autoreleaseFrequency:.inherit: 6.0
// // no-cap qos:.userInteractive autoreleaseFrequency:.workItem: 5.9
// // no-cap qos:.userInteractive autoreleaseFrequency:.never: 6.3
// // no second queue. Only 1 global() queue in dispatchTasksThenCleanup: 11 // 3.3
// // no second queue. Only 1 DispatchQueue (serial) in dispatchTasksThenCleanup: 12.2
//
// static func dispatchTasksThenCleanup(_ batchId: Int, _ expectation: XCTestExpectation) {
// DispatchQueue.init(label: "test").async {
// print("orchestrator start \(batchId)")
// for taskId in 0..<100 {
//// dispatchSemaphore.wait()
//// DispatchQueue.global().async {
// defer {
//// dispatchSemaphore.signal()
// dispatchGroup.leave()
// }
// dispatchGroup.enter()
// print("task start \(batchId) \(taskId)")
// task(batchId, taskId)
// print("task stop \(batchId) \(taskId)")
//// }
// }
// dispatchGroup.notify(queue: .main) {
// cleanup(expectation)
// }
// print("orchestrator stop \(batchId)")
// }
// }
//
// static func start(_ expectation1: XCTestExpectation, _ expectation2: XCTestExpectation) {
// let windows = CGWindowListCopyWindowInfo([.excludeDesktopElements, .optionOnScreenOnly], kCGNullWindowID) as! [CGWindow]
// let window = windows.first { ($0[kCGWindowName] as? String) == "~" }
// wid = window?[kCGWindowNumber] as? CGWindowID
// startTime = DispatchTime.now().uptimeNanoseconds
// dispatchTasksThenCleanup(batchId, expectation1)
// batchId += 1
// dispatchTasksThenCleanup(batchId, expectation2)
// batchId += 1
// }
//
// static func task(_ batchId: Int, _ taskId: Int) {
// //Thread.sleep(forTimeInterval: 10)//Double(Int.random(in: 1...5)))
// let _ = screenshot()
// }
//
// static func cleanup(_ expectation: XCTestExpectation) {
// let timePassedInSeconds = Double(DispatchTime.now().uptimeNanoseconds - startTime) / 1_000_000_000
// print("cleanup", timePassedInSeconds)
// expectation.fulfill()
// }
//
// static func screenshot() -> CGImage? {
// print("CGSHWCaptureWindowList start")
// var windowId_ = wid!
// let list = CGSHWCaptureWindowList(CGS_CONNECTION, &windowId_, 1, [.ignoreGlobalClipShape, .bestResolution]).takeRetainedValue() as! [CGImage]
// print(list.first != nil)
// return list.first
//// let windowId_ = wid!
//// let image = CGWindowListCreateImage(.null, .optionIncludingWindow, windowId_, [.boundsIgnoreFraming, .bestResolution])
//// print(image != nil)
//// return image
// }
//}
//
//final class ConcurrentScreenshots: XCTestCase {
// func testBench() throws {
//// let options = XCTMeasureOptions()
//// options.iterationCount = 1
//// self.measure(options: options) {
// let expectation1 = XCTestExpectation()
// let expectation2 = XCTestExpectation()
// Playground.start(expectation1, expectation2)
// wait(for: [expectation1, expectation2], timeout: 100)
//// }
// }
//}

0 comments on commit 8b52dc8

Please sign in to comment.