8000 Linux metrics by prensing · Pull Request #641 · PhotonVision/photonvision · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Linux metrics #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum Platform {
"Linux Raspbian 32-bit", true, OSType.LINUX, true), // Raspberry Pi 3/4 with a 32-bit image
LINUX_RASPBIAN64(
"Linux Raspbian 64-bit", true, OSType.LINUX, true), // Raspberry Pi 3/4 with a 64-bit image
LINUX_AARCH64BIONIC("Linux AARCH64 Bionic", false, OSType.LINUX, true), // Jetson Nano, Jetson TX2
LINUX_AARCH64("Linux AARCH64", false, OSType.LINUX, true), // Jetson Nano, Jetson TX2

// PhotonVision Supported (Manual build/install)
LINUX_ARM32("Linux ARM32", false, OSType.LINUX, true), // ODROID XU4, C1+
Expand Down Expand Up @@ -155,7 +155,7 @@ private static Platform getCurrentPlatform() {
} else if (isJetsonSBC()) {
if (RuntimeDetector.isArm64()) {
// TODO - do we need to check OS version?
return LINUX_AARCH64BIONIC;
return LINUX_AARCH64;
} else {
// Unknown/exotic installation
return UNKNOWN;
Expand All @@ -166,7 +166,7 @@ private static Platform getCurrentPlatform() {
return LINUX_32;
} else if (RuntimeDetector.isArm64()) {
// TODO - os detection needed?
return LINUX_AARCH64BIONIC;
return LINUX_AARCH64;
} else {
// Unknown or otherwise unsupported platform
return Platform.UNKNOWN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ public String safeExecute(String str) {
}
}

private String cpuMemSplit = null;
private String cpuMemSave = null;

public String getMemory() {
if (cmds.cpuMemoryCommand.isEmpty()) return "";
if (cpuMemSplit == null) {
cpuMemSplit = execute(cmds.cpuMemoryCommand);
if (cpuMemSave == null) {
// save the value and only run it once
cpuMemSave = execute(cmds.cpuMemoryCommand);
}
return cpuMemSplit;
return cpuMemSave;
}

public String getTemp() {
Expand All @@ -88,14 +89,14 @@ public String getThrottleReason() {
return safeExecute(cmds.cpuThrottleReasonCmd);
}

private String gpuMemSplit = null;
private String gpuMemSave = null;

public String getGPUMemorySplit() {
if (gpuMemSplit == null) {
if (gpuMemSave == null) {
// only needs to run once
gpuMemSplit = safeExecute(cmds.gpuMemoryCommand);
gpuMemSave = safeExecute(cmds.gpuMemoryCommand);
}
return gpuMemSplit;
return gpuMemSave;
}

public String getMallocedMemory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,25 @@
*/

package org.photonvision.common.hardware.metrics.cmds;

import org.photonvision.common.configuration.HardwareConfig;

public class LinuxCmds extends CmdBase {
public void initCmds(HardwareConfig config) {}
public void initCmds(HardwareConfig config) {
// CPU
cpuMemoryCommand = "awk '/MemTotal:/ {print int($2 / 1000);}' /proc/meminfo";

// TODO: boards have lots of thermal devices. Hard to pick the CPU

cpuUtilizationCommand =
"top -bn1 | grep \"Cpu(s)\" | sed \"s/.*, *\\([0-9.]*\\)%* id.*/\\1/\" | awk '{print 100 - $1}'";

cpuUptimeCommand = "uptime -p | cut -c 4-";

// RAM
ramUsageCommand = "awk '/MemFree:/ {print int($2 / 1000);}' /proc/meminfo";

// Disk
diskUsageCommand = "df ./ --output=pcent | tail -n +2";
}
}
851C
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,23 @@

import org.photonvision.common.configuration.HardwareConfig;

public class PiCmds extends CmdBase {
public class PiCmds extends LinuxCmds {
/** Applies pi-specific commands, ignoring any input configuration */
public void initCmds(HardwareConfig config) {
super.initCmds(config);

// CPU
cpuMemoryCommand = "vcgencmd get_mem arm | grep -Eo '[0-9]+'";
cpuTemperatureCommand = "sed 's/.\\{3\\}$/.&/' <<< cat /sys/class/thermal/thermal_zone0/temp";
cpuUtilizationCommand =
"top -bn1 | grep \"Cpu(s)\" | sed \"s/.*, *\\([0-9.]*\\)%* id.*/\\1/\" | awk '{print 100 - $1}'";

cpuTemperatureCommand = "sed 's/.\\{3\\}$/.&/' /sys/class/thermal/thermal_zone0/temp";
cpuThrottleReasonCmd =
"if (( $(( $(vcgencmd get_throttled | grep -Eo 0x[0-9a-fA-F]*) & 0x01 )) != 0x00 )); then echo \"LOW VOLTAGE\"; "
+ " elif (( $(( $(vcgencmd get_throttled | grep -Eo 0x[0-9a-fA-F]*) & 0x08 )) != 0x00 )); then echo \"HIGH TEMP\"; "
+ " elif (( $(( $(vcgencmd get_throttled | grep -Eo 0x[0-9a-fA-F]*) & 0x10000 )) != 0x00 )); then echo \"Prev. Low Voltage\"; "
+ " elif (( $(( $(vcgencmd get_throttled | grep -Eo 0x[0-9a-fA-F]*) & 0x80000 )) != 0x00 )); then echo \"Prev. High Temp\"; "
+ " else echo \"None\"; fi";

cpuUptimeCommand = "uptime -p | cut -c 4-";

// GPU
gpuMemoryCommand = "vcgencmd get_mem gpu | grep -Eo '[0-9]+'";
gpuMemUsageCommand = "vcgencmd get_mem malloc | grep -Eo '[0-9]+'";

// RAM
ramUsageCommand = "free --mega | awk -v i=2 -v j=3 'FNR == i {print $j}'";

// Disk
diskUsageCommand = "df ./ --output=pcent | tail -n +2";
}
}
2 changes: 1 addition & 1 deletion photon-server/src/main/resources/web/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>UI has not been copied!</p>
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=/favicon.png><title>PhotonVision</title><link href=/js/chunk-2d216214.4302abb0.js rel=prefetch><link href=/js/chunk-2d216257.0de4b8cc.js rel=prefetch><link href=/js/chunk-6bdce92c.119701f5.js rel=prefetch><link href=/css/app.0314c96c.css rel=preload as=style><link href=/css/chunk-vendors.7e4af884.css rel=preload as=style><link href=/js/app.ae7ac408.js rel=preload as=script><link href=/js/chunk-vendors.8dba6e5e.js rel=preload as=script><link href=/css/chunk-vendors.7e4af884.css rel=stylesheet><link href=/css/app.0314c96c.css rel=stylesheet></head><body><noscript><strong>We're sorry but PhotonVision doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=/js/chunk-vendors.8dba6e5e.js></script><script src=/js/app.ae7ac408.js></script></body></html>
0