parent
e0537d5fd1
commit
9bce4090fa
@ -8,68 +8,7 @@ if [ ! -d $cache_dir ]; then
|
|||||||
mkdir -p $cache_dir
|
mkdir -p $cache_dir
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f $cache_dir/cpu-temp ]; then
|
[ -f $cache_dir/cpu-temp ] && rm $cache_dir/cpu-temp
|
||||||
clang -x objective-c -Wall -O2 -g -c -o $cache_dir/cpu-temp.o - << EOF
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import <IOKit/hidsystem/IOHIDEventSystemClient.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#define IOHIDEventFieldBase(type) (type << 16)
|
|
||||||
#define kIOHIDEventTypeTemperature 15
|
|
||||||
|
|
||||||
typedef struct __IOHIDEvent *IOHIDEventRef;
|
|
||||||
typedef struct __IOHIDServiceClient *IOHIDServiceClientRef;
|
|
||||||
typedef double IOHIDFloat;
|
|
||||||
|
|
||||||
IOHIDEventSystemClientRef
|
|
||||||
IOHIDEventSystemClientCreate(CFAllocatorRef allocator);
|
|
||||||
int IOHIDEventSystemClientSetMatching(IOHIDEventSystemClientRef client,
|
|
||||||
CFDictionaryRef match);
|
|
||||||
IOHIDEventRef IOHIDServiceClientCopyEvent(IOHIDServiceClientRef, int64_t,
|
|
||||||
int32_t, int64_t);
|
|
||||||
CFStringRef IOHIDServiceClientCopyProperty(IOHIDServiceClientRef service,
|
|
||||||
CFStringRef property);
|
|
||||||
IOHIDFloat IOHIDEventGetFloatValue(IOHIDEventRef event, int32_t field);
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
NSDictionary *thermalSensors = @{
|
|
||||||
@"PrimaryUsagePage" : [NSNumber numberWithInt:0xFF00],
|
|
||||||
@"PrimaryUsage" : [NSNumber numberWithInt:5],
|
|
||||||
};
|
|
||||||
IOHIDEventSystemClientRef system =
|
|
||||||
IOHIDEventSystemClientCreate(kCFAllocatorDefault);
|
|
||||||
IOHIDEventSystemClientSetMatching(system,
|
|
||||||
(__bridge CFDictionaryRef)thermalSensors);
|
|
||||||
NSArray *serviceClients =
|
|
||||||
(__bridge NSArray *)IOHIDEventSystemClientCopyServices(system);
|
|
||||||
|
|
||||||
long count = [serviceClients count];
|
|
||||||
for (NSUInteger i = 0; i < count; i++) {
|
|
||||||
IOHIDServiceClientRef serviceClient =
|
|
||||||
(IOHIDServiceClientRef)serviceClients[i];
|
|
||||||
NSString *name = (NSString *)IOHIDServiceClientCopyProperty(
|
|
||||||
serviceClient, (__bridge CFStringRef) @"Product");
|
|
||||||
if ([name isEqualToString:[NSString stringWithUTF8String:argv[1]]]) {
|
|
||||||
IOHIDEventRef event = IOHIDServiceClientCopyEvent(
|
|
||||||
serviceClient, kIOHIDEventTypeTemperature, 0, 0);
|
|
||||||
NSNumber *value;
|
|
||||||
double temp = 0.0;
|
|
||||||
if (event != 0) {
|
|
||||||
temp = IOHIDEventGetFloatValue(
|
|
||||||
event, IOHIDEventFieldBase(kIOHIDEventTypeTemperature));
|
|
||||||
}
|
|
||||||
value = [NSNumber numberWithDouble:temp];
|
|
||||||
printf("%.1lf°C\n", [value doubleValue]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
clang -o $cache_dir/cpu-temp $cache_dir/cpu-temp.o -framework Foundation -framework IOKit
|
|
||||||
rm $cache_dir/cpu-temp.o
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Cleanup cache file when interrupted.
|
# Cleanup cache file when interrupted.
|
||||||
trap '[ -f $cache_file ] && rm $cache_file; exit' INT
|
trap '[ -f $cache_file ] && rm $cache_file; exit' INT
|
||||||
@ -81,7 +20,9 @@ ioreg -w0 -l | grep BatteryInstalled &> /dev/null && \
|
|||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
# Get the current CPU temperature.
|
# Get the current CPU temperature.
|
||||||
cpu_temp="`$cache_dir/cpu-temp 'PMU tdie1'` "
|
cpu_temp=$(
|
||||||
|
~/.local/bin/iSMC -o json temp | jq '."PMU tdie1".quantity' | xargs printf "%.1f°C "
|
||||||
|
)
|
||||||
|
|
||||||
cpu_load=$(sudo powermetrics --format text \
|
cpu_load=$(sudo powermetrics --format text \
|
||||||
--sample-rate 1200 --sample-count 1 --samplers cpu_power |
|
--sample-rate 1200 --sample-count 1 --samplers cpu_power |
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user