Skip to content

Commit 8b52dc8

Browse files
committed
chore: add testbed file if i ever need to investigate again
1 parent db5644e commit 8b52dc8

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

alt-tab-macos.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
BF0C8C7F5F9EE501B240D2E3 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8532DEDE7C1218B90444 /* Localizable.strings */; };
155155
BF0C8C8E35FF49CAA4BF5FC4 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8A970BD1CAD555F31EDA /* Localizable.strings */; };
156156
BF0C8C9CA44285E493918A74 /* menubar-2@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8E54658B4DAEA0528200 /* menubar-2@2x.png */; };
157+
BF0C8CBED8D88DFBADE7EC03 /* ConcurrentScreenshots.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8C6810FF50908E637A48 /* ConcurrentScreenshots.swift */; };
157158
BF0C8CBF5B4EE15FDB53C94B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C861EE84489EF56879CBF /* InfoPlist.strings */; };
158159
BF0C8CC5057406014FD612CC /* ATShortcut.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8BA452332236D972C60E /* ATShortcut.swift */; };
159160
BF0C8D1C57D74106018D073C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C87F5D4AD51D6950C98B0 /* InfoPlist.strings */; };
@@ -452,6 +453,7 @@
452453
BF0C8C5210ACA9FBFAE9C631 /* preferences-general.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "preferences-general.jpg"; sourceTree = "<group>"; };
453454
BF0C8C5B74E5DA2CC31E52F4 /* extract_l10n_strings.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = extract_l10n_strings.sh; sourceTree = "<group>"; };
454455
BF0C8C5C0FF5D567BF190DE5 /* ApplicationServices.HIServices.framework.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplicationServices.HIServices.framework.swift; sourceTree = "<group>"; };
456+
BF0C8C6810FF50908E637A48 /* ConcurrentScreenshots.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConcurrentScreenshots.swift; sourceTree = "<group>"; };
455457
BF0C8C69316EAAF6DC9AE391 /* CliEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CliEvents.swift; sourceTree = "<group>"; };
456458
BF0C8C6995992F837A9A83A6 /* ca */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = ca; path = InfoPlist.strings; sourceTree = "<group>"; };
457459
BF0C8C77273E00B019725640 /* add_missing_terms_on_poeditor.ts */ = {isa = PBXFileReference; lastKnownFileType = file.ts; path = add_missing_terms_on_poeditor.ts; sourceTree = "<group>"; };
@@ -969,6 +971,7 @@
969971
BF0C84933936C6FE676CD33C /* AppearanceTests.swift */,
970972
BF0C899905524253DC170B56 /* KeyboardEventsTests.swift */,
971973
BF0C829EAA93A4C4ADB42CF8 /* Mocks.swift */,
974+
BF0C8C6810FF50908E637A48 /* ConcurrentScreenshots.swift */,
972975
);
973976
path = "unit-tests";
974977
sourceTree = "<group>";
@@ -2238,6 +2241,7 @@
22382241
BF0C8C5FA4B401A8C0F75B7A /* KeyboardEventsTestable.swift in Sources */,
22392242
BF0C875A28B98904F8F4A66A /* ATShortcut.swift in Sources */,
22402243
BF0C84E5AC1D423625ABF3E6 /* Mocks.swift in Sources */,
2244+
BF0C8CBED8D88DFBADE7EC03 /* ConcurrentScreenshots.swift in Sources */,
22412245
);
22422246
runOnlyForDeploymentPostprocessing = 0;
22432247
};
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
//import XCTest
2+
//
3+
//import Cocoa
4+
//
5+
//@_silgen_name("CGSMainConnectionID")
6+
//func CGSMainConnectionID() -> CGSConnectionID
7+
//
8+
//let CGS_CONNECTION = CGSMainConnectionID()
9+
//typealias CGSConnectionID = UInt32
10+
//typealias CGSSpaceID = UInt64
11+
//
12+
//struct CGSWindowCaptureOptions: OptionSet {
13+
// let rawValue: UInt32
14+
// static let ignoreGlobalClipShape = CGSWindowCaptureOptions(rawValue: 1 << 11)
15+
// // on a retina display, 1px is spread on 4px, so nominalResolution is 1/4 of bestResolution
16+
// static let nominalResolution = CGSWindowCaptureOptions(rawValue: 1 << 9)
17+
// static let bestResolution = CGSWindowCaptureOptions(rawValue: 1 << 8)
18+
//}
19+
//
20+
//@_silgen_name("CGSHWCaptureWindowList")
21+
//func CGSHWCaptureWindowList(_ cid: CGSConnectionID, _ windowList: inout CGWindowID, _ windowCount: UInt32, _ options: CGSWindowCaptureOptions) -> Unmanaged<CFArray>
22+
//
23+
//typealias CGWindow = [CFString: Any]
24+
//
25+
//class Playground {
26+
// static var batchId = 0
27+
// static var startTime: UInt64!
28+
// static var wid: CGWindowID!
29+
// static let dispatchGroup = DispatchGroup()
30+
// static let dispatchSemaphore = DispatchSemaphore(value: 8)
31+
// // DispatchQueue.global()
32+
// // 1: 21.4
33+
// // 2: 11.2
34+
// // 3: 8.1
35+
// // 5: 6.5 // 3.2
36+
// // 8: 5.9 // 3.1
37+
// // 10: 5.5 // 3.0
38+
// // 15: 5.2 // 3.3
39+
// // 20: 5.2
40+
// // 30: 5.2
41+
// // 40: 5.2
42+
// // 50: 5.6
43+
// // 60: 10.7
44+
// // no-cap: 93 // 93.3
45+
// // custom-concurrent-queue no-cap: 91.3
46+
// // custom DispatchQueue (serial)
47+
// // no-cap: 5.1 // 3.2
48+
// // no-cap qos:.userInteractive: 6.0
49+
// // no-cap qos:.userInteractive autoreleaseFrequency:.inherit: 6.0
50+
// // no-cap qos:.userInteractive autoreleaseFrequency:.workItem: 5.9
51+
// // no-cap qos:.userInteractive autoreleaseFrequency:.never: 6.3
52+
// // no second queue. Only 1 global() queue in dispatchTasksThenCleanup: 11 // 3.3
53+
// // no second queue. Only 1 DispatchQueue (serial) in dispatchTasksThenCleanup: 12.2
54+
//
55+
// static func dispatchTasksThenCleanup(_ batchId: Int, _ expectation: XCTestExpectation) {
56+
// DispatchQueue.init(label: "test").async {
57+
// print("orchestrator start \(batchId)")
58+
// for taskId in 0..<100 {
59+
//// dispatchSemaphore.wait()
60+
//// DispatchQueue.global().async {
61+
// defer {
62+
//// dispatchSemaphore.signal()
63+
// dispatchGroup.leave()
64+
// }
65+
// dispatchGroup.enter()
66+
// print("task start \(batchId) \(taskId)")
67+
// task(batchId, taskId)
68+
// print("task stop \(batchId) \(taskId)")
69+
//// }
70+
// }
71+
// dispatchGroup.notify(queue: .main) {
72+
// cleanup(expectation)
73+
// }
74+
// print("orchestrator stop \(batchId)")
75+
// }
76+
// }
77+
//
78+
// static func start(_ expectation1: XCTestExpectation, _ expectation2: XCTestExpectation) {
79+
// let windows = CGWindowListCopyWindowInfo([.excludeDesktopElements, .optionOnScreenOnly], kCGNullWindowID) as! [CGWindow]
80+
// let window = windows.first { ($0[kCGWindowName] as? String) == "~" }
81+
// wid = window?[kCGWindowNumber] as? CGWindowID
82+
// startTime = DispatchTime.now().uptimeNanoseconds
83+
// dispatchTasksThenCleanup(batchId, expectation1)
84+
// batchId += 1
85+
// dispatchTasksThenCleanup(batchId, expectation2)
86+
// batchId += 1
87+
// }
88+
//
89+
// static func task(_ batchId: Int, _ taskId: Int) {
90+
// //Thread.sleep(forTimeInterval: 10)//Double(Int.random(in: 1...5)))
91+
// let _ = screenshot()
92+
// }
93+
//
94+
// static func cleanup(_ expectation: XCTestExpectation) {
95+
// let timePassedInSeconds = Double(DispatchTime.now().uptimeNanoseconds - startTime) / 1_000_000_000
96+
// print("cleanup", timePassedInSeconds)
97+
// expectation.fulfill()
98+
// }
99+
//
100+
// static func screenshot() -> CGImage? {
101+
// print("CGSHWCaptureWindowList start")
102+
// var windowId_ = wid!
103+
// let list = CGSHWCaptureWindowList(CGS_CONNECTION, &windowId_, 1, [.ignoreGlobalClipShape, .bestResolution]).takeRetainedValue() as! [CGImage]
104+
// print(list.first != nil)
105+
// return list.first
106+
//// let windowId_ = wid!
107+
//// let image = CGWindowListCreateImage(.null, .optionIncludingWindow, windowId_, [.boundsIgnoreFraming, .bestResolution])
108+
//// print(image != nil)
109+
//// return image
110+
// }
111+
//}
112+
//
113+
//final class ConcurrentScreenshots: XCTestCase {
114+
// func testBench() throws {
115+
//// let options = XCTMeasureOptions()
116+
//// options.iterationCount = 1
117+
//// self.measure(options: options) {
118+
// let expectation1 = XCTestExpectation()
119+
// let expectation2 = XCTestExpectation()
120+
// Playground.start(expectation1, expectation2)
121+
// wait(for: [expectation1, expectation2], timeout: 100)
122+
//// }
123+
// }
124+
//}

0 commit comments

Comments
 (0)