Cleanup CPU plugin
Summary: Addressing code review feedback from previous 3 diffs. * Don't return draft when using immer * Move functions out of component to module level * Make executeShell async and simplify callsites * Add onStopMonitor to cleanup function * Add uniform spacing by adding Layout.Container around titles * Disable searchbar on both tables * Use Toolbar Reviewed By: mweststrate Differential Revision: D28091565 fbshipit-source-id: 533d2491e6f48a9eaaa64b1a6cf76eea2e7189a5
This commit is contained in:
committed by
Facebook GitHub Bot
parent
303e42535c
commit
679ef665e2
@@ -18,6 +18,7 @@ import {
|
|||||||
DetailSidebar,
|
DetailSidebar,
|
||||||
DataTable,
|
DataTable,
|
||||||
DataTableColumn,
|
DataTableColumn,
|
||||||
|
Toolbar,
|
||||||
} from 'flipper-plugin';
|
} from 'flipper-plugin';
|
||||||
import adb from 'adbkit';
|
import adb from 'adbkit';
|
||||||
import TemperatureTable from './TemperatureTable';
|
import TemperatureTable from './TemperatureTable';
|
||||||
@@ -51,8 +52,6 @@ type CPUState = {
|
|||||||
displayCPUDetail: boolean;
|
displayCPUDetail: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ShellCallBack = (output: string) => any;
|
|
||||||
|
|
||||||
// check if str is a number
|
// check if str is a number
|
||||||
function isNormalInteger(str: string) {
|
function isNormalInteger(str: string) {
|
||||||
const n = Math.floor(Number(str));
|
const n = Math.floor(Number(str));
|
||||||
@@ -75,13 +74,16 @@ function formatFrequency(freq: number) {
|
|||||||
export function devicePlugin(client: PluginClient<{}, {}>) {
|
export function devicePlugin(client: PluginClient<{}, {}>) {
|
||||||
const device = client.device;
|
const device = client.device;
|
||||||
|
|
||||||
const executeShell = (callback: ShellCallBack, command: string) => {
|
const executeShell = async (command: string) => {
|
||||||
return (device.realDevice as any).adb
|
return new Promise<string>((resolve, reject) => {
|
||||||
.shell(device.serial, command)
|
(device.realDevice as any).adb
|
||||||
.then(adb.util.readAll)
|
.shell(device.serial, command)
|
||||||
.then(function (output: {toString: () => {trim: () => string}}) {
|
.then(adb.util.readAll)
|
||||||
return callback(output.toString().trim());
|
.then(function (output: {toString: () => {trim: () => string}}) {
|
||||||
});
|
resolve(output.toString().trim());
|
||||||
|
})
|
||||||
|
.catch((e: unknown) => reject(e));
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let intervalID: NodeJS.Timer | null = null;
|
let intervalID: NodeJS.Timer | null = null;
|
||||||
@@ -96,77 +98,70 @@ export function devicePlugin(client: PluginClient<{}, {}>) {
|
|||||||
displayCPUDetail: true,
|
displayCPUDetail: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateCoreFrequency: (core: number, type: string) => Promise<void> = (
|
const updateCoreFrequency: (
|
||||||
core: number,
|
core: number,
|
||||||
type: string,
|
type: string,
|
||||||
) => {
|
) => Promise<void> = async (core: number, type: string) => {
|
||||||
return new Promise((resolve, _reject) => {
|
const output = await executeShell(
|
||||||
executeShell((output: string) => {
|
'cat /sys/devices/system/cpu/cpu' + core + '/cpufreq/' + type,
|
||||||
cpuState.update((draft) => {
|
);
|
||||||
const newFreq = isNormalInteger(output) ? parseInt(output, 10) : -1;
|
cpuState.update((draft) => {
|
||||||
// update table only if frequency changed
|
const newFreq = isNormalInteger(output) ? parseInt(output, 10) : -1;
|
||||||
if (draft.cpuFreq[core][type] != newFreq) {
|
// update table only if frequency changed
|
||||||
draft.cpuFreq[core][type] = newFreq;
|
if (draft.cpuFreq[core][type] != newFreq) {
|
||||||
if (type == 'scaling_cur_freq' && draft.cpuFreq[core][type] < 0) {
|
draft.cpuFreq[core][type] = newFreq;
|
||||||
// cannot find current freq means offline
|
if (type == 'scaling_cur_freq' && draft.cpuFreq[core][type] < 0) {
|
||||||
draft.cpuFreq[core][type] = -2;
|
// cannot find current freq means offline
|
||||||
}
|
draft.cpuFreq[core][type] = -2;
|
||||||
}
|
}
|
||||||
return draft;
|
}
|
||||||
});
|
|
||||||
resolve();
|
|
||||||
}, 'cat /sys/devices/system/cpu/cpu' + core + '/cpufreq/' + type);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateAvailableFrequencies: (core: number) => Promise<void> = (
|
const updateAvailableFrequencies: (core: number) => Promise<void> = async (
|
||||||
core: number,
|
core: number,
|
||||||
) => {
|
) => {
|
||||||
return new Promise((resolve, _reject) => {
|
const output = await executeShell(
|
||||||
executeShell((output: string) => {
|
'cat /sys/devices/system/cpu/cpu' +
|
||||||
cpuState.update((draft) => {
|
core +
|
||||||
const freqs = output.split(' ').map((num: string) => {
|
'/cpufreq/scaling_available_frequencies',
|
||||||
return parseInt(num, 10);
|
);
|
||||||
});
|
cpuState.update((draft) => {
|
||||||
draft.cpuFreq[core].scaling_available_freqs = freqs;
|
const freqs = output.split(' ').map((num: string) => {
|
||||||
const maxFreq = draft.cpuFreq[core].scaling_max_freq;
|
return parseInt(num, 10);
|
||||||
if (maxFreq > 0 && freqs.indexOf(maxFreq) == -1) {
|
});
|
||||||
freqs.push(maxFreq); // always add scaling max to available frequencies
|
draft.cpuFreq[core].scaling_available_freqs = freqs;
|
||||||
}
|
const maxFreq = draft.cpuFreq[core].scaling_max_freq;
|
||||||
return draft;
|
if (maxFreq > 0 && freqs.indexOf(maxFreq) == -1) {
|
||||||
});
|
freqs.push(maxFreq); // always add scaling max to available frequencies
|
||||||
resolve();
|
}
|
||||||
}, 'cat /sys/devices/system/cpu/cpu' + core + '/cpufreq/scaling_available_frequencies');
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateCoreGovernor: (core: number) => Promise<void> = (
|
const updateCoreGovernor: (core: number) => Promise<void> = async (
|
||||||
core: number,
|
core: number,
|
||||||
) => {
|
) => {
|
||||||
return new Promise((resolve, _reject) => {
|
const output = await executeShell(
|
||||||
executeShell((output: string) => {
|
'cat /sys/devices/system/cpu/cpu' + core + '/cpufreq/scaling_governor',
|
||||||
cpuState.update((draft) => {
|
);
|
||||||
if (output.toLowerCase().includes('no such file')) {
|
cpuState.update((draft) => {
|
||||||
draft.cpuFreq[core].scaling_governor = 'N/A';
|
if (output.toLowerCase().includes('no such file')) {
|
||||||
} else {
|
draft.cpuFreq[core].scaling_governor = 'N/A';
|
||||||
draft.cpuFreq[core].scaling_governor = output;
|
} else {
|
||||||
}
|
draft.cpuFreq[core].scaling_governor = output;
|
||||||
return draft;
|
}
|
||||||
});
|
|
||||||
resolve();
|
|
||||||
}, 'cat /sys/devices/system/cpu/cpu' + core + '/cpufreq/scaling_governor');
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const readAvailableGovernors: (core: number) => Promise<string[]> = (
|
const readAvailableGovernors: (core: number) => Promise<string[]> = async (
|
||||||
core: number,
|
core: number,
|
||||||
) => {
|
) => {
|
||||||
return new Promise((resolve, _reject) => {
|
const output = await executeShell(
|
||||||
executeShell((output: string) => {
|
'cat /sys/devices/system/cpu/cpu' +
|
||||||
// draft.cpuFreq[core].scaling_available_governors = output.split(' ');
|
core +
|
||||||
resolve(output.split(' '));
|
'/cpufreq/scaling_available_governors',
|
||||||
}, 'cat /sys/devices/system/cpu/cpu' + core + '/cpufreq/scaling_available_governors');
|
);
|
||||||
});
|
return output.split(' ');
|
||||||
};
|
};
|
||||||
|
|
||||||
const readCoreFrequency = async (core: number) => {
|
const readCoreFrequency = async (core: number) => {
|
||||||
@@ -184,90 +179,82 @@ export function devicePlugin(client: PluginClient<{}, {}>) {
|
|||||||
return Promise.all(promises).then(() => {});
|
return Promise.all(promises).then(() => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateHardwareInfo = () => {
|
const updateHardwareInfo = async () => {
|
||||||
executeShell((output: string) => {
|
const output = await executeShell('getprop ro.board.platform');
|
||||||
let hwInfo = '';
|
let hwInfo = '';
|
||||||
if (
|
if (
|
||||||
output.startsWith('msm') ||
|
output.startsWith('msm') ||
|
||||||
output.startsWith('apq') ||
|
output.startsWith('apq') ||
|
||||||
output.startsWith('sdm')
|
output.startsWith('sdm')
|
||||||
) {
|
) {
|
||||||
hwInfo = 'QUALCOMM ' + output.toUpperCase();
|
hwInfo = 'QUALCOMM ' + output.toUpperCase();
|
||||||
} else if (output.startsWith('exynos')) {
|
} else if (output.startsWith('exynos')) {
|
||||||
executeShell((output: string) => {
|
const chipname = await executeShell('getprop ro.chipname');
|
||||||
if (output != null) {
|
if (chipname != null) {
|
||||||
cpuState.update((draft) => {
|
cpuState.update((draft) => {
|
||||||
draft.hardwareInfo = 'SAMSUMG ' + output.toUpperCase();
|
draft.hardwareInfo = 'SAMSUMG ' + chipname.toUpperCase();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}, 'getprop ro.chipname');
|
|
||||||
return;
|
|
||||||
} else if (output.startsWith('mt')) {
|
|
||||||
hwInfo = 'MEDIATEK ' + output.toUpperCase();
|
|
||||||
} else if (output.startsWith('sc')) {
|
|
||||||
hwInfo = 'SPREADTRUM ' + output.toUpperCase();
|
|
||||||
} else if (output.startsWith('hi') || output.startsWith('kirin')) {
|
|
||||||
hwInfo = 'HISILICON ' + output.toUpperCase();
|
|
||||||
} else if (output.startsWith('rk')) {
|
|
||||||
hwInfo = 'ROCKCHIP ' + output.toUpperCase();
|
|
||||||
} else if (output.startsWith('bcm')) {
|
|
||||||
hwInfo = 'BROADCOM ' + output.toUpperCase();
|
|
||||||
}
|
}
|
||||||
cpuState.update((draft) => {
|
return;
|
||||||
draft.hardwareInfo = hwInfo;
|
} else if (output.startsWith('mt')) {
|
||||||
return draft;
|
hwInfo = 'MEDIATEK ' + output.toUpperCase();
|
||||||
});
|
} else if (output.startsWith('sc')) {
|
||||||
}, 'getprop ro.board.platform');
|
hwInfo = 'SPREADTRUM ' + output.toUpperCase();
|
||||||
|
} else if (output.startsWith('hi') || output.startsWith('kirin')) {
|
||||||
|
hwInfo = 'HISILICON ' + output.toUpperCase();
|
||||||
|
} else if (output.startsWith('rk')) {
|
||||||
|
hwInfo = 'ROCKCHIP ' + output.toUpperCase();
|
||||||
|
} else if (output.startsWith('bcm')) {
|
||||||
|
hwInfo = 'BROADCOM ' + output.toUpperCase();
|
||||||
|
}
|
||||||
|
cpuState.update((draft) => {
|
||||||
|
draft.hardwareInfo = hwInfo;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const readThermalZones = () => {
|
const readThermalZones = async () => {
|
||||||
const thermal_dir = '/sys/class/thermal/';
|
const thermal_dir = '/sys/class/thermal/';
|
||||||
const map = {};
|
const map = {};
|
||||||
executeShell(async (output: string) => {
|
const output = await executeShell('ls ' + thermal_dir);
|
||||||
if (output.toLowerCase().includes('permission denied')) {
|
if (output.toLowerCase().includes('permission denied')) {
|
||||||
cpuState.update((draft) => {
|
|
||||||
draft.thermalAccessible = false;
|
|
||||||
return draft;
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const dirs = output.split(/\s/);
|
|
||||||
const promises = [];
|
|
||||||
for (let d of dirs) {
|
|
||||||
d = d.trim();
|
|
||||||
if (d.length == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const path = thermal_dir + d;
|
|
||||||
promises.push(readThermalZone(path, d, map));
|
|
||||||
}
|
|
||||||
await Promise.all(promises);
|
|
||||||
cpuState.update((draft) => {
|
cpuState.update((draft) => {
|
||||||
draft.temperatureMap = map;
|
draft.thermalAccessible = false;
|
||||||
draft.thermalAccessible = true;
|
|
||||||
return draft;
|
|
||||||
});
|
});
|
||||||
if (cpuState.get().displayThermalInfo) {
|
return;
|
||||||
setTimeout(readThermalZones, 1000);
|
}
|
||||||
|
const dirs = output.split(/\s/);
|
||||||
|
const promises = [];
|
||||||
|
for (let d of dirs) {
|
||||||
|
d = d.trim();
|
||||||
|
if (d.length == 0) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}, 'ls ' + thermal_dir);
|
const path = thermal_dir + d;
|
||||||
|
promises.push(readThermalZone(path, d, map));
|
||||||
|
}
|
||||||
|
await Promise.all(promises);
|
||||||
|
cpuState.update((draft) => {
|
||||||
|
draft.temperatureMap = map;
|
||||||
|
draft.thermalAccessible = true;
|
||||||
|
});
|
||||||
|
if (cpuState.get().displayThermalInfo) {
|
||||||
|
setTimeout(readThermalZones, 1000);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const readThermalZone = (path: string, dir: string, map: any) => {
|
const readThermalZone = async (path: string, dir: string, map: any) => {
|
||||||
return executeShell((type: string) => {
|
const type = await executeShell('cat ' + path + '/type');
|
||||||
if (type.length == 0) {
|
if (type.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return executeShell((temp: string) => {
|
const temp = await executeShell('cat ' + path + '/temp');
|
||||||
if (Number.isNaN(Number(temp))) {
|
if (Number.isNaN(Number(temp))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
map[type] = {
|
map[type] = {
|
||||||
path: dir,
|
path: dir,
|
||||||
temp: parseInt(temp, 10),
|
temp: parseInt(temp, 10),
|
||||||
};
|
};
|
||||||
}, 'cat ' + path + '/temp');
|
|
||||||
}, 'cat ' + path + '/type');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onStartMonitor = () => {
|
const onStartMonitor = () => {
|
||||||
@@ -309,11 +296,11 @@ export function devicePlugin(client: PluginClient<{}, {}>) {
|
|||||||
intervalID = null;
|
intervalID = null;
|
||||||
cpuState.update((draft) => {
|
cpuState.update((draft) => {
|
||||||
draft.monitoring = false;
|
draft.monitoring = false;
|
||||||
return draft;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const cleanup = () => {
|
const cleanup = () => {
|
||||||
|
onStopMonitor();
|
||||||
cpuState.update((draft) => {
|
cpuState.update((draft) => {
|
||||||
for (let i = 0; i < draft.cpuCount; ++i) {
|
for (let i = 0; i < draft.cpuCount; ++i) {
|
||||||
draft.cpuFreq[i].scaling_cur_freq = -1;
|
draft.cpuFreq[i].scaling_cur_freq = -1;
|
||||||
@@ -334,7 +321,6 @@ export function devicePlugin(client: PluginClient<{}, {}>) {
|
|||||||
cpuState.update((draft) => {
|
cpuState.update((draft) => {
|
||||||
draft.displayThermalInfo = !draft.displayThermalInfo;
|
draft.displayThermalInfo = !draft.displayThermalInfo;
|
||||||
draft.displayCPUDetail = false;
|
draft.displayCPUDetail = false;
|
||||||
return draft;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -342,12 +328,11 @@ export function devicePlugin(client: PluginClient<{}, {}>) {
|
|||||||
cpuState.update((draft) => {
|
cpuState.update((draft) => {
|
||||||
draft.displayCPUDetail = !draft.displayCPUDetail;
|
draft.displayCPUDetail = !draft.displayCPUDetail;
|
||||||
draft.displayThermalInfo = false;
|
draft.displayThermalInfo = false;
|
||||||
return draft;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// check how many cores we have on this device
|
// check how many cores we have on this device
|
||||||
executeShell((output: string) => {
|
executeShell('cat /sys/devices/system/cpu/possible').then((output) => {
|
||||||
const idx = output.indexOf('-');
|
const idx = output.indexOf('-');
|
||||||
const cpuFreq = [];
|
const cpuFreq = [];
|
||||||
const count = parseInt(output.substring(idx + 1), 10) + 1;
|
const count = parseInt(output.substring(idx + 1), 10) + 1;
|
||||||
@@ -374,7 +359,7 @@ export function devicePlugin(client: PluginClient<{}, {}>) {
|
|||||||
displayThermalInfo: false,
|
displayThermalInfo: false,
|
||||||
displayCPUDetail: true,
|
displayCPUDetail: true,
|
||||||
});
|
});
|
||||||
}, 'cat /sys/devices/system/cpu/possible');
|
});
|
||||||
|
|
||||||
client.onDeactivate(() => cleanup());
|
client.onDeactivate(() => cleanup());
|
||||||
client.onActivate(() => {
|
client.onActivate(() => {
|
||||||
@@ -415,36 +400,6 @@ const cpuSidebarColumns: DataTableColumn[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const getRowStyle = (freq: CPUFrequency) => {
|
|
||||||
if (freq.scaling_cur_freq == -2) {
|
|
||||||
return {
|
|
||||||
backgroundColor: theme.backgroundWash,
|
|
||||||
color: theme.textColorPrimary,
|
|
||||||
fontWeight: 700,
|
|
||||||
};
|
|
||||||
} else if (
|
|
||||||
freq.scaling_min_freq != freq.cpuinfo_min_freq &&
|
|
||||||
freq.scaling_min_freq > 0 &&
|
|
||||||
freq.cpuinfo_min_freq > 0
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
backgroundColor: theme.warningColor,
|
|
||||||
color: theme.textColorPrimary,
|
|
||||||
fontWeight: 700,
|
|
||||||
};
|
|
||||||
} else if (
|
|
||||||
freq.scaling_max_freq != freq.cpuinfo_max_freq &&
|
|
||||||
freq.scaling_max_freq > 0 &&
|
|
||||||
freq.cpuinfo_max_freq > 0
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
backgroundColor: theme.backgroundWash,
|
|
||||||
color: theme.textColorSecondary,
|
|
||||||
fontWeight: 700,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export function Component() {
|
export function Component() {
|
||||||
const instance = usePlugin(devicePlugin);
|
const instance = usePlugin(devicePlugin);
|
||||||
const {
|
const {
|
||||||
@@ -458,72 +413,6 @@ export function Component() {
|
|||||||
|
|
||||||
const [selectedIds, setSelectedIds] = useState<number[]>([]);
|
const [selectedIds, setSelectedIds] = useState<number[]>([]);
|
||||||
|
|
||||||
const buildRow = (freq: CPUFrequency) => {
|
|
||||||
return {
|
|
||||||
core: freq.cpu_id,
|
|
||||||
cpu_id: `CPU_${freq.cpu_id}`,
|
|
||||||
scaling_cur_freq: formatFrequency(freq.scaling_cur_freq),
|
|
||||||
scaling_min_freq: formatFrequency(freq.scaling_min_freq),
|
|
||||||
scaling_max_freq: formatFrequency(freq.scaling_max_freq),
|
|
||||||
cpuinfo_min_freq: formatFrequency(freq.cpuinfo_min_freq),
|
|
||||||
cpuinfo_max_freq: formatFrequency(freq.cpuinfo_max_freq),
|
|
||||||
scaling_governor: freq.scaling_governor,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const frequencyRows = (cpuFreqs: Array<CPUFrequency>) => {
|
|
||||||
return cpuFreqs.map(buildRow);
|
|
||||||
};
|
|
||||||
|
|
||||||
const buildAvailableFreqList = (freq: CPUFrequency) => {
|
|
||||||
if (freq.scaling_available_freqs.length == 0) {
|
|
||||||
return <Typography.Text>N/A</Typography.Text>;
|
|
||||||
}
|
|
||||||
const info = freq;
|
|
||||||
return (
|
|
||||||
<Typography.Text>
|
|
||||||
{freq.scaling_available_freqs.map((freq, idx) => {
|
|
||||||
const bold =
|
|
||||||
freq == info.scaling_cur_freq ||
|
|
||||||
freq == info.scaling_min_freq ||
|
|
||||||
freq == info.scaling_max_freq;
|
|
||||||
return (
|
|
||||||
<Typography.Text key={idx} strong={bold}>
|
|
||||||
{formatFrequency(freq)}
|
|
||||||
{freq == info.scaling_cur_freq && (
|
|
||||||
<Typography.Text strong={bold}>
|
|
||||||
{' '}
|
|
||||||
(scaling current)
|
|
||||||
</Typography.Text>
|
|
||||||
)}
|
|
||||||
{freq == info.scaling_min_freq && (
|
|
||||||
<Typography.Text strong={bold}> (scaling min)</Typography.Text>
|
|
||||||
)}
|
|
||||||
{freq == info.scaling_max_freq && (
|
|
||||||
<Typography.Text strong={bold}> (scaling max)</Typography.Text>
|
|
||||||
)}
|
|
||||||
<br />
|
|
||||||
</Typography.Text>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</Typography.Text>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const buildAvailableGovList = (freq: CPUFrequency): string => {
|
|
||||||
if (freq.scaling_available_governors.length == 0) {
|
|
||||||
return 'N/A';
|
|
||||||
}
|
|
||||||
return freq.scaling_available_governors.join(', ');
|
|
||||||
};
|
|
||||||
|
|
||||||
const buildSidebarRow = (key: string, val: any) => {
|
|
||||||
return {
|
|
||||||
key: key,
|
|
||||||
value: val,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const sidebarRows = (id: number) => {
|
const sidebarRows = (id: number) => {
|
||||||
let availableFreqTitle = 'Scaling Available Frequencies';
|
let availableFreqTitle = 'Scaling Available Frequencies';
|
||||||
const selected = cpuState.cpuFreq[id];
|
const selected = cpuState.cpuFreq[id];
|
||||||
@@ -550,12 +439,15 @@ export function Component() {
|
|||||||
const id = selectedIds[0];
|
const id = selectedIds[0];
|
||||||
return (
|
return (
|
||||||
<DetailSidebar width={500}>
|
<DetailSidebar width={500}>
|
||||||
<Typography.Title>CPU Details: CPU_{id}</Typography.Title>
|
<Layout.Container pad>
|
||||||
<DataTable
|
<Typography.Title>CPU Details: CPU_{id}</Typography.Title>
|
||||||
records={sidebarRows(id)}
|
<DataTable
|
||||||
columns={cpuSidebarColumns}
|
records={sidebarRows(id)}
|
||||||
scrollable={false}
|
columns={cpuSidebarColumns}
|
||||||
/>
|
scrollable={false}
|
||||||
|
searchbar={false}
|
||||||
|
/>
|
||||||
|
</Layout.Container>
|
||||||
</DetailSidebar>
|
</DetailSidebar>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -585,9 +477,9 @@ export function Component() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout.Container pad={theme.space.medium}>
|
<Layout.Container pad>
|
||||||
<Typography.Title>CPU Info</Typography.Title>
|
<Typography.Title>CPU Info</Typography.Title>
|
||||||
<Layout.Horizontal gap={theme.space.small} center>
|
<Toolbar>
|
||||||
{cpuState.monitoring ? (
|
{cpuState.monitoring ? (
|
||||||
<Button onClick={onStopMonitor} icon={<PauseCircleOutlined />}>
|
<Button onClick={onStopMonitor} icon={<PauseCircleOutlined />}>
|
||||||
Pause
|
Pause
|
||||||
@@ -611,7 +503,7 @@ export function Component() {
|
|||||||
{cpuState.displayCPUDetail &&
|
{cpuState.displayCPUDetail &&
|
||||||
selectedIds.length == 0 &&
|
selectedIds.length == 0 &&
|
||||||
' (Please select a core in the table below)'}
|
' (Please select a core in the table below)'}
|
||||||
</Layout.Horizontal>
|
</Toolbar>
|
||||||
|
|
||||||
<DataTable
|
<DataTable
|
||||||
records={frequencyRows(cpuState.cpuFreq)}
|
records={frequencyRows(cpuState.cpuFreq)}
|
||||||
@@ -619,9 +511,106 @@ export function Component() {
|
|||||||
scrollable={false}
|
scrollable={false}
|
||||||
onSelect={setSelected}
|
onSelect={setSelected}
|
||||||
onRowStyle={getRowStyle}
|
onRowStyle={getRowStyle}
|
||||||
|
searchbar={false}
|
||||||
/>
|
/>
|
||||||
{renderCPUSidebar()}
|
{renderCPUSidebar()}
|
||||||
{renderThermalSidebar()}
|
{renderThermalSidebar()}
|
||||||
</Layout.Container>
|
</Layout.Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildAvailableGovList(freq: CPUFrequency): string {
|
||||||
|
if (freq.scaling_available_governors.length == 0) {
|
||||||
|
return 'N/A';
|
||||||
|
}
|
||||||
|
return freq.scaling_available_governors.join(', ');
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildSidebarRow(key: string, val: any) {
|
||||||
|
return {
|
||||||
|
key: key,
|
||||||
|
value: val,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildRow(freq: CPUFrequency) {
|
||||||
|
return {
|
||||||
|
core: freq.cpu_id,
|
||||||
|
cpu_id: `CPU_${freq.cpu_id}`,
|
||||||
|
scaling_cur_freq: formatFrequency(freq.scaling_cur_freq),
|
||||||
|
scaling_min_freq: formatFrequency(freq.scaling_min_freq),
|
||||||
|
scaling_max_freq: formatFrequency(freq.scaling_max_freq),
|
||||||
|
cpuinfo_min_freq: formatFrequency(freq.cpuinfo_min_freq),
|
||||||
|
cpuinfo_max_freq: formatFrequency(freq.cpuinfo_max_freq),
|
||||||
|
scaling_governor: freq.scaling_governor,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function frequencyRows(cpuFreqs: Array<CPUFrequency>) {
|
||||||
|
return cpuFreqs.map(buildRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRowStyle(freq: CPUFrequency) {
|
||||||
|
if (freq.scaling_cur_freq == -2) {
|
||||||
|
return {
|
||||||
|
backgroundColor: theme.backgroundWash,
|
||||||
|
color: theme.textColorPrimary,
|
||||||
|
fontWeight: 700,
|
||||||
|
};
|
||||||
|
} else if (
|
||||||
|
freq.scaling_min_freq != freq.cpuinfo_min_freq &&
|
||||||
|
freq.scaling_min_freq > 0 &&
|
||||||
|
freq.cpuinfo_min_freq > 0
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
backgroundColor: theme.warningColor,
|
||||||
|
color: theme.textColorPrimary,
|
||||||
|
fontWeight: 700,
|
||||||
|
};
|
||||||
|
} else if (
|
||||||
|
freq.scaling_max_freq != freq.cpuinfo_max_freq &&
|
||||||
|
freq.scaling_max_freq > 0 &&
|
||||||
|
freq.cpuinfo_max_freq > 0
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
backgroundColor: theme.backgroundWash,
|
||||||
|
color: theme.textColorSecondary,
|
||||||
|
fontWeight: 700,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildAvailableFreqList(freq: CPUFrequency) {
|
||||||
|
if (freq.scaling_available_freqs.length == 0) {
|
||||||
|
return <Typography.Text>N/A</Typography.Text>;
|
||||||
|
}
|
||||||
|
const info = freq;
|
||||||
|
return (
|
||||||
|
<Typography.Text>
|
||||||
|
{freq.scaling_available_freqs.map((freq, idx) => {
|
||||||
|
const bold =
|
||||||
|
freq == info.scaling_cur_freq ||
|
||||||
|
freq == info.scaling_min_freq ||
|
||||||
|
freq == info.scaling_max_freq;
|
||||||
|
return (
|
||||||
|
<Typography.Text key={idx} strong={bold}>
|
||||||
|
{formatFrequency(freq)}
|
||||||
|
{freq == info.scaling_cur_freq && (
|
||||||
|
<Typography.Text strong={bold}>
|
||||||
|
{' '}
|
||||||
|
(scaling current)
|
||||||
|
</Typography.Text>
|
||||||
|
)}
|
||||||
|
{freq == info.scaling_min_freq && (
|
||||||
|
<Typography.Text strong={bold}> (scaling min)</Typography.Text>
|
||||||
|
)}
|
||||||
|
{freq == info.scaling_max_freq && (
|
||||||
|
<Typography.Text strong={bold}> (scaling max)</Typography.Text>
|
||||||
|
)}
|
||||||
|
<br />
|
||||||
|
</Typography.Text>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Typography.Text>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user