Skip to content

Commit

Permalink
board info and pstate profile
Browse files Browse the repository at this point in the history
  • Loading branch information
trulyspinach committed Mar 15, 2020
1 parent bc99174 commit 3cc76ab
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 68 deletions.
10 changes: 2 additions & 8 deletions AMD Power Gadget/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

@IBAction func gadget(_ sender: Any) {
let mainStoryboard = NSStoryboard.init(name: NSStoryboard.Name("Main"), bundle: nil)
let controller = mainStoryboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("AMDPowerGadget")) as! NSWindowController
controller.showWindow(self)
ViewController.launch()
}

@IBAction func tool(_ sender: Any) {
let mainStoryboard = NSStoryboard.init(name: NSStoryboard.Name("Main"), bundle: nil)
let controller = mainStoryboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("AMDPowerTool")) as! NSWindowController
controller.showWindow(self)

controller.window?.isMovableByWindowBackground = true
PowerToolViewController.launch()
}

func applicationDidFinishLaunching(_ aNotification: Notification) {
Expand Down
56 changes: 35 additions & 21 deletions AMD Power Gadget/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,28 @@
<action selector="revert:" target="arI-oH-4xY" id="Pno-Uv-T2l"/>
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="pNv-Gc-cHo">
<rect key="frame" x="92" y="13" width="80" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Import" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="zct-1P-oFp">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="import:" target="arI-oH-4xY" id="BIR-4A-yry"/>
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="R8Z-Yp-tyN">
<rect key="frame" x="173" y="13" width="80" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Export" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="bsR-em-SBO">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="export:" target="arI-oH-4xY" id="3hX-63-diF"/>
</connections>
</button>
</subviews>
</view>
<connections>
Expand Down Expand Up @@ -912,27 +934,8 @@
<rect key="frame" x="0.0" y="0.0" width="568" height="274"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Jah-fU-9WT">
<rect key="frame" x="25" y="9" width="365" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" selectable="YES" id="HmI-x3-4Ci">
<font key="font" metaFont="systemMedium" size="8"/>
<string key="title">FPU, VME, DE, PSE, TSC, MSR, PAE, MCE, CX8, APIC, SEP, MTRR, PGE, MCA, CMOV, PAT, PSE36, CLFSH, MMX, FXSR, SSE, SSE2, HTT, SSE3, PCLMULQDQ, MON, SSSE3, FMA, CX16, SSE4.1, SSE4.2, MOVBE, POPCNT, AES, XSAVE, OSXSAVE, AVX1.0, RDRAND, F16C, RDWRFSGS, BMI1, AVX2, SMEP, BMI2, PQM, PQE, RDSEED, ADX, SMAP, CLFSOPT, CLWB, SHA, UMIP, RDPID</string>
<color key="textColor" red="1" green="1" blue="1" alpha="0.59641835389999998" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5ze-2r-CBU">
<rect key="frame" x="18" y="62" width="140" height="17"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Supported Features:" id="fOd-f9-OKT">
<font key="font" metaFont="systemMedium" size="14"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IvS-BL-onx">
<rect key="frame" x="18" y="79" width="307" height="175"/>
<rect key="frame" x="18" y="20" width="372" height="242"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" selectable="YES" alignment="left" id="g3v-Pl-VUX">
<font key="font" metaFont="systemMedium" size="13"/>
Expand Down Expand Up @@ -980,6 +983,17 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="k7R-ib-Cnn">
<rect key="frame" x="12" y="7" width="283" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Fix motherboard displays as 'Unknown'?" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="xeA-Lk-bKK">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="boardHelp:" target="rDh-aT-nig" id="s63-7f-Ob1"/>
</connections>
</button>
</subviews>
</view>
</tabViewItem>
Expand Down Expand Up @@ -1116,12 +1130,12 @@ A better solution is still in development.</string>
<connections>
<outlet property="asaBox" destination="0lB-ss-dpq" id="pLi-pS-Hgp"/>
<outlet property="basicLabel" destination="IvS-BL-onx" id="YHX-hZ-cyr"/>
<outlet property="boardHelpButton" destination="k7R-ib-Cnn" id="89p-zX-fWV"/>
<outlet property="configControl" destination="mWw-zl-STF" id="lK7-f9-mmi"/>
<outlet property="configTabView" destination="pJK-Iy-0Pe" id="5w4-9P-5N2"/>
<outlet property="cpbEnabledBox" destination="hck-n7-ZB8" id="9Wm-qW-Otj"/>
<outlet property="cpbSupportedBox" destination="XVJ-1V-MPd" id="GbR-et-p38"/>
<outlet property="cpuFreqGraph" destination="5PL-lX-mWT" id="va5-5g-BLH"/>
<outlet property="featuresLabel" destination="Jah-fU-9WT" id="QDm-P6-EI7"/>
<outlet property="overviewSpeedShift" destination="LRK-w5-6Kx" id="sBA-SR-DsA"/>
<outlet property="topLabel1" destination="VGI-us-87W" id="OQ9-dq-3xk"/>
<outlet property="topLabel2" destination="f05-q5-Exd" id="QDN-jE-Rag"/>
Expand Down
15 changes: 15 additions & 0 deletions AMD Power Gadget/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2020 trulyspinach. All rights reserved.</string>
<key>NSMainStoryboardFile</key>
Expand Down
21 changes: 21 additions & 0 deletions AMD Power Gadget/Power Tool/PStateEditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,25 @@ class PStateEditorViewController: NSViewController, NSTableViewDelegate, NSTable

presentingViewController?.dismiss(self)
}

@IBAction func `import`(_ sender: Any) {
let op = NSOpenPanel()
op.runModal()

let arr = NSArray.init(contentsOf: op.url!) as! [UInt64]

data = arr.map({value2Dict(v: $0)})
tableView.reloadData()
}

@IBAction func export(_ sender: Any) {
let op = NSSavePanel()
op.isExtensionHidden = false
op.allowedFileTypes = ["pstate"]

op.runModal()

let arr = data.map{ dict2Value(d: $0) }
(arr as NSArray).write(to: op.url!, atomically: true)
}
}
65 changes: 56 additions & 9 deletions AMD Power Gadget/Power Tool/PowerToolViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Cocoa

class PowerToolViewController: NSViewController {
class PowerToolViewController: NSViewController, NSWindowDelegate {

@IBOutlet weak var cpuFreqGraph: CPUPowerStepView!

Expand All @@ -17,7 +17,6 @@ class PowerToolViewController: NSViewController {
var vaildStatesClock : [Float] = []

@IBOutlet weak var basicLabel: NSTextField!
@IBOutlet weak var featuresLabel: NSTextField!
@IBOutlet weak var overviewSpeedShift: CPUSpeedShiftView!

@IBOutlet weak var configTabView: NSTabView!
Expand All @@ -31,6 +30,23 @@ class PowerToolViewController: NSViewController {

}



@IBOutlet weak var boardHelpButton: NSButton!
@IBAction func boardHelp(_ sender: Any) {
let alert = NSAlert()
alert.messageText = "To enable motherboard display:"
alert.informativeText = """
Open your OpenCore config file,
Go to Misc -> Security -> ExposeSensitiveData,
Set the value to 0x08 to expose board information.
"""
alert.alertStyle = .informational
alert.addButton(withTitle: "Done")
alert.beginSheetModal(for: view.window!, completionHandler: nil)
}
@IBOutlet weak var cpbSupportedBox: NSButton!
@IBOutlet weak var cpbEnabledBox: NSButton!
@IBAction func cpbEnabledBox(_ sender: Any) {
Expand All @@ -53,6 +69,19 @@ class PowerToolViewController: NSViewController {
var instDelta : UInt64 = 0
var sumCount = 0

static var activeSelf : PowerToolViewController?
static func launch() {
if let vc = PowerToolViewController.activeSelf {
vc.view.window?.orderFrontRegardless()
} else {
let mainStoryboard = NSStoryboard.init(name: NSStoryboard.Name("Main"), bundle: nil)
let controller = mainStoryboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("AMDPowerTool")) as! NSWindowController
controller.showWindow(self)

controller.window?.isMovableByWindowBackground = true
}
}

override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -73,12 +102,22 @@ class PowerToolViewController: NSViewController {

topLabel1.font = NSFont(name: "SF Pro Rounded", size: 32)
topLabel2.font = NSFont(name: "SF Pro Rounded", size: 32)

PowerToolViewController.activeSelf = self
}

override func viewWillAppear() {
view.window?.delegate = self
}

override func viewWillDisappear() {
timer?.invalidate()
}

func windowWillClose(_ notification: Notification) {
PowerToolViewController.activeSelf = nil
}

func sampleCPUGraph() {
let metric = ProcessorModel.shared.getMetric(forced: true)
let load = ProcessorModel.shared.getLoadIndex()
Expand Down Expand Up @@ -112,23 +151,31 @@ class PowerToolViewController: NSViewController {
let id = ProcessorModel.shared.cpuidBasic
let supported = id[7] == 1 ? "Yes" : "Not yet :)"

let memGB = Int(ProcessorModel.shared.systemConfig["mem"]!)! / 1024
var storageGB = "?"
if let rs = ProcessorModel.shared.systemConfig["rs"] {
storageGB = "\(Int(rs)! / 1024)"
}

basicLabel.stringValue = """
\(ProcessorModel.sysctlString(key: "machdep.cpu.brand_string"))
\(ProcessorModel.shared.systemConfig["cpu"]!)
Family: \(String(format:"%02X", id[0]))h, Model: \(String(format:"%02X", id[1]))h
Physical: \(id[2]), Logical: \(id[3])
L1(Total): \(id[4] * id[2]) KB, L2(Total): \(id[5] * id[2] / 1024) MB
L3(Shared): \(id[6] / 1024) MB
macOS Version: \(ProcessorModel.sysctlString(key: "kern.osproductversion"))
Motherboard: \(ProcessorModel.shared.boardName)
\(ProcessorModel.shared.boardVender)
Memory: \(memGB)GB, Storage: \(storageGB)GB
macOS Version: \(ProcessorModel.shared.systemConfig["os"]!)
SMCAMDProcessor:
Version: \(ProcessorModel.shared.SMCAMDProcessorVersion), CPU Supported: \(supported)
"""

let features = ProcessorModel.sysctlString(key: "machdep.cpu.features") + " " +
ProcessorModel.sysctlString(key: "machdep.cpu.leaf7_features")
featuresLabel.stringValue = features.replacingOccurrences(of: " ", with: ", ")
if ProcessorModel.shared.boardValid {
boardHelpButton.removeFromSuperview()
}
}

func updatePStateDef() {
Expand Down
Loading

0 comments on commit 3cc76ab

Please sign in to comment.