-
-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add debug profile to feedback message
- Loading branch information
Showing
27 changed files
with
164 additions
and
42 deletions.
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
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import Cocoa | ||
import Foundation | ||
|
||
extension AXUIElement { | ||
func cgWindowId() -> CGWindowID { | ||
|
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import Cocoa | ||
import Foundation | ||
|
||
typealias CGWindow = [CFString: Any] | ||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import Cocoa | ||
import Foundation | ||
|
||
extension CGWindowID { | ||
func title() -> String? { | ||
|
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
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
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,47 @@ | ||
import Foundation | ||
|
||
public struct Sysctl { | ||
static func run(_ name: String) -> String { | ||
return run(name, { $0.baseAddress.flatMap { String(validatingUTF8: $0) } }) ?? "" | ||
} | ||
|
||
static func run<T>(_ name: String, _ type: T.Type) -> T? { | ||
return run(name, { $0.baseAddress?.withMemoryRebound(to: T.self, capacity: 1) { $0.pointee } }) | ||
} | ||
|
||
private static func run<R>(_ name: String, _ fn: (UnsafeBufferPointer<Int8>) -> R?) -> R? { | ||
return keys(name).flatMap { keys in data(keys)?.withUnsafeBufferPointer() { fn($0) } } | ||
} | ||
|
||
private static func data(_ keys: [Int32]) -> [Int8]? { | ||
return keys.withUnsafeBufferPointer() { keysPointer in | ||
var requiredSize = 0 | ||
let preFlightResult = Darwin.sysctl(UnsafeMutablePointer<Int32>(mutating: keysPointer.baseAddress), UInt32(keys.count), nil, &requiredSize, nil, 0) | ||
if preFlightResult != 0 { | ||
return nil | ||
} | ||
let data = Array<Int8>(repeating: 0, count: requiredSize) | ||
let result = data.withUnsafeBufferPointer() { dataBuffer -> Int32 in | ||
return Darwin.sysctl(UnsafeMutablePointer<Int32>(mutating: keysPointer.baseAddress), UInt32(keys.count), UnsafeMutableRawPointer(mutating: dataBuffer.baseAddress), &requiredSize, nil, 0) | ||
} | ||
if result != 0 { | ||
return nil | ||
} | ||
return data | ||
} | ||
} | ||
|
||
private static func keys(_ name: String) -> [Int32]? { | ||
var keysBufferSize = Int(CTL_MAXNAME) | ||
var keysBuffer = Array<Int32>(repeating: 0, count: keysBufferSize) | ||
_ = keysBuffer.withUnsafeMutableBufferPointer { (lbp: inout UnsafeMutableBufferPointer<Int32>) in | ||
name.withCString { (nbp: UnsafePointer<Int8>) in | ||
sysctlnametomib(nbp, lbp.baseAddress, &keysBufferSize) | ||
} | ||
} | ||
if keysBuffer.count > keysBufferSize { | ||
keysBuffer.removeSubrange(keysBufferSize..<keysBuffer.count) | ||
} | ||
return keysBuffer | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import Foundation | ||
import Cocoa | ||
|
||
class Application: NSObject { | ||
|
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import Foundation | ||
import Cocoa | ||
|
||
class Applications { | ||
|
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,70 @@ | ||
import Cocoa | ||
import Darwin | ||
|
||
class DebugProfile { | ||
static let intraSeparator = ": " | ||
static let interSeparator = ", " | ||
static let bulletPoint = "* " | ||
static let nestedSeparator = "\n " + bulletPoint | ||
|
||
static func make() -> String { | ||
([ | ||
// app | ||
("App version", App.version), | ||
("App preferences", appPreferences()), | ||
("Applications count", String(Applications.list.count)), | ||
("Windows", appWindows()), | ||
// os | ||
("OS version", ProcessInfo.processInfo.operatingSystemVersionString), | ||
("OS architecture", Sysctl.run("hw.machine")), | ||
("Locale", Locale.current.debugDescription), | ||
("Spaces count", String((CGSCopyManagedDisplaySpaces(cgsMainConnectionId) as! [NSDictionary]).map { $0["Spaces"] }.count)), | ||
// hardware | ||
("Hardware model", Sysctl.run("hw.model")), | ||
("Displays count", String(NSScreen.screens.count)), | ||
("CPU model", Sysctl.run("machdep.cpu.brand_string")), | ||
("Memory size", ByteCountFormatter.string(fromByteCount: Int64(ProcessInfo.processInfo.physicalMemory), countStyle: .file)), | ||
// TODO: add gpu model(s) | ||
// hardware utilization | ||
("Active CPU count", Sysctl.run("hw.activecpu", UInt.self).flatMap { String($0) } ?? ""), | ||
("Current CPU frequency", Sysctl.run("hw.cpufrequency", Int.self).map { String(format: "%.1f", Double($0) / Double(1_000_000_000)) + " Ghz" } ?? ""), | ||
// TODO: CPU utilization | ||
// TODO: Active GPU | ||
// TODO: GPU utilization | ||
// TODO: Memory utilization | ||
// TODO: disk space to detect disk pressure | ||
// TODO: thermals to check if overheating | ||
// TODO: battery to check if low-energy mode / throttling | ||
|
||
] as [(String, String)]) | ||
.map { bulletPoint + $0.0 + intraSeparator + $0.1 } | ||
.joined(separator: "\n") | ||
} | ||
|
||
private static func appPreferences() -> String { | ||
return nestedSeparator + Preferences.rawValues | ||
.sorted { $0.0 < $1.0 } | ||
.map { $0 + intraSeparator + $1 } | ||
.joined(separator: nestedSeparator) | ||
} | ||
|
||
private static func appWindows() -> String { | ||
return nestedSeparator + Windows.list | ||
.sorted { $0.cgWindowId < $1.cgWindowId } | ||
.map { appWindow($0) } | ||
.joined(separator: nestedSeparator) | ||
} | ||
|
||
private static func appWindow(_ window: Window) -> String { | ||
return "{" + ([ | ||
("isMinimized", String(window.isMinimized)), | ||
("isHidden", String(window.isHidden)), | ||
("isOnAllSpaces", String(window.isOnAllSpaces)), | ||
("spaceId", window.spaceId.flatMap { String($0) } ?? ""), | ||
("spaceIndex", window.spaceIndex.flatMap { String($0) } ?? ""), | ||
] as [(String, String)]) | ||
.map { $0.0 + intraSeparator + $0.1 } | ||
.joined(separator: interSeparator) | ||
+ "}" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import Foundation | ||
import Cocoa | ||
import Carbon.HIToolbox.Events | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import Foundation | ||
import Cocoa | ||
|
||
class Screen { | ||
|
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
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
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import Cocoa | ||
import Foundation | ||
|
||
class Window { | ||
var cgWindowId: CGWindowID | ||
|
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import Foundation | ||
import Cocoa | ||
import Darwin | ||
|
||
let cgsMainConnectionId = CGSMainConnectionID() | ||
|
||
|
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
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import Cocoa | ||
import Foundation | ||
|
||
class GridView { | ||
static let padding = CGFloat(20) | ||
|
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import Cocoa | ||
import Foundation | ||
|
||
class TextArea: NSTextView { | ||
static let paddingX = CGFloat(5) | ||
|
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import Cocoa | ||
import Foundation | ||
|
||
class LabelAndControl: NSObject { | ||
static var callbackTarget: PreferencesWindow! | ||
|
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import Cocoa | ||
import Foundation | ||
|
||
class PreferencesWindow: NSWindow { | ||
var windowCloseRequested = false | ||
|
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
Oops, something went wrong.