• MacThrottle एक SwiftUI-आधारित ऐप है जो Mac के ओवरहीटिंग के कारण performance limit होने पर इसे menu bar में विज़ुअली दिखाता है - ओपन सोर्स
  • macOS के ProcessInfo.thermalState API और powermetrics कमांड की तुलना करते हुए, सिस्टम की वास्तविक thermal state को सटीक रूप से detect करने के तरीकों की खोज की गई
  • अंत में thermald द्वारा Darwin के notifyd सिस्टम में प्रकाशित notifications का उपयोग करके root permission के बिना thermal state पढ़ने का तरीका लागू किया गया
  • ऐप में temperature·fan speed graphs, state-wise color icons, macOS notification feature शामिल हैं, और login पर auto-start भी support करता है
  • Apple Silicon Mac की thermal management state को real time में समझने के लिए यह एक उपयोगी टूल है, जो developers और power users को diagnostic साधन देता है

Mac में thermal throttling समस्या को पहचानना

  • M2 MacBook Air पर external 4K 120Hz display इस्तेमाल करते समय performance drop और response lag देखा गया
    • इसमें fan नहीं है, इसलिए noise से पता नहीं चलता, लेकिन CPU usage 100% होने पर भी power usage कम हो रहा था
  • iStat Menus और MX Power Gadget के जरिए CPU frequency और power drop की पुष्टि करते हुए thermal throttling diagnose किया गया
  • M4 Max MacBook Pro में भी यही समस्या दिखी, और इसे 14-inch model की thermal design limit से जुड़ी बात बताया गया
  • Apple Silicon की power efficiency अब भी बहुत अच्छी है, लेकिन thermal state को सीधे detect करने का तरीका ढूँढना उद्देश्य था

macOS में thermal state को programmatically जाँचना

  • macOS thermal state को कई तरीकों से expose करता है, लेकिन consistency की कमी है
  • Apple द्वारा recommended तरीका Foundation के ProcessInfo.thermalState का उपयोग है
    • output उदाहरण: nominal, fair, serious, critical
  • root permission की ज़रूरत वाली powermetrics -s thermal कमांड भी यही जानकारी देती है, लेकिन
    दोनों तरीकों की state classification units अलग हैं
    • उदाहरण: fair, powermetrics के moderate और heavy दोनों states को शामिल करता है
  • वास्तविक throttling का समय powermetrics में heavy के रूप में दिखता है, लेकिन ProcessInfo में उसे अलग से पहचानना संभव नहीं

thermald और Darwin notification system का उपयोग

  • powermetrics का डेटा thermald daemon से आता है, और
    thermald मौजूदा thermal pressure state को notifyd system events के रूप में publish करता है
  • notifyutil -g com.apple.system.thermalpressurelevel कमांड से state जाँची जा सकती है
  • OSThermalNotification.h header में defined thermal pressure levels:
    • nominal, moderate, heavy, trapping, sleeping
  • Swift code में notify_register_check और notify_get_state को call करके
    root permission के बिना real-time thermal state पढ़ने की सुविधा लागू की गई

MacThrottle ऐप डेवलपमेंट

  • SwiftUI और MenuBarExtra का उपयोग करके menu bar-only ऐप बनाया गया
    • thermometer icon के रंग से state दिखती है (हरा→लाल)
    • Info.plist में LSUIElement को true सेट करके Dock icon disable किया गया

शुरुआती तरीका: powermetrics root helper

  • शुरुआत में root permission की ज़रूरत वाले powermetrics का उपयोग करने के लिए
    LaunchDaemon और bash script से helper process तैयार किया गया
    • /usr/local/bin/mac-throttle-thermal-monitor हर 10 सेकंड में state को /tmp फ़ाइल में लिखता था
    • ऐप उस फ़ाइल को समय-समय पर पढ़कर display करता था

सुधार: thermald IPC notifications का उपयोग

  • सीधे notifyd events subscribe करने वाले तरीके पर स्विच किया गया
    • root permission की ज़रूरत नहीं, code भी सरल हो गया

temperature और fan speed display

  • CPU/GPU temperature और fan speed को graph में दिखाया गया
  • शुरुआत में IOKit private API उपयोग करने पर temperature वास्तविक से कम दिख रहा था (~80°C)
  • ओपन सोर्स Stats प्रोजेक्ट को देखकर SMC interface पर स्विच किया गया
    • SoC generation के अनुसार अलग keys (Tp0D, Tf0E आदि) इस्तेमाल करनी पड़ती हैं
  • SMC काम न करे तो IOKit पर fallback किया जाता है

menu bar graph implementation

  • graph एक साथ 3 तरह की जानकारी दिखाता है
    • background color: thermal state (हरा~लाल)
    • solid line: CPU temperature
    • dotted line: fan speed ratio
  • हर 2 सेकंड में data collect होता है, और 10 मिनट की history रखी जाती है
  • onContinuousHover से tooltip दिया गया,
    .drawingGroup जोड़कर GPU rendering के जरिए 120Hz display पर भी smooth display सुनिश्चित किया गया

macOS notifications और auto-start

  • thermal state बदलने पर notification भेजने की सुविधा जोड़ी गई
    • किसी specific state transition या recovery पर notification भेजी जा सकती है
  • SMAppService API से login पर auto-start setting support की गई
    • register() / unregister() / status methods से control

distribution और उपयोग

  • Apple Developer account न होने से official notarization संभव नहीं था
    • GitHub release से install करने पर Privacy and Security में manual approval देना पड़ता है
    • कुछ Mac पर Xcode से सीधे build करना पड़ सकता है
  • install और build के तरीके GitHub README में दिए गए हैं

निष्कर्ष

  • MacThrottle Apple Silicon Mac के thermal throttling state को real time में monitor करने वाला lightweight टूल है
  • यह root permission के बिना काम करता है, और visual feedback, notifications, और graph features के जरिए
    developers और high-performance work users को system thermal state की स्पष्ट जानकारी देता है

अभी कोई टिप्पणी नहीं है.

अभी कोई टिप्पणी नहीं है.