Skip to content

Commit

Permalink
fix benchmark result on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
alvindimas05 committed Aug 9, 2024
1 parent 2c9acf0 commit b7c6d29
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 43 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules/lagassist.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 30 additions & 43 deletions src/main/java/org/alvindimas05/lagassist/minebench/SpecsGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,51 +35,38 @@ public class SpecsGetter {

private static OperatingSystemMXBean osmx = ManagementFactory.getOperatingSystemMXBean();

// private static String getLinuxCPU() {
//
// final String regex = "model name : (.*\\n)";
//
// File fl = new File("/proc/cpuinfo");
// if (!fl.exists()) {
// return "unknown";
// }
// if (!fl.canRead()) {
// return "unknown";
// }
// try {
// String stg = Others.readInputStreamAsString(new FileInputStream(fl));
//
// final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
// final Matcher matcher = pattern.matcher(stg);
// matcher.find();
//
// return matcher.group(1).replaceAll("\n", "");
//
// } catch (IOException e) {
// e.printStackTrace();
// return "unknown";
// }
//
// }
private static String getLinuxCPU() {

private static String formatCPU(String cpuname){
return String.join(" ",
Arrays.stream(cpuname
.replaceAll("\\(R\\)", "")
.replaceAll(" CPU", "")
.split(" ")).toList().subList(0, 4));
}
final String regex = "model name : (.*\\n)";

private static String getLinuxCPU(){
Runtime rt = Runtime.getRuntime();
try {
Process proc = rt.exec("lscpu | grep 'Model name' | cut -f 2 -d ':' | awk '{$1=$1}1'");
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
File fl = new File("/proc/cpuinfo");
if (!fl.exists()) {
return "unknown";
}
if (!fl.canRead()) {
return "unknown";
}
try {
String stg = Others.readInputStreamAsString(new FileInputStream(fl));

return formatCPU(reader.readLine());
} catch(IOException e){
return "unknown";
}
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(stg);
matcher.find();

return formatCPU(matcher.group(1).replaceAll("\n", ""));
} catch (IOException e) {
e.printStackTrace();
}
return "unknown";
}

private static String formatCPU(String cpuname){
return String.join(" ",
Arrays.copyOfRange(
cpuname.replaceAll("\\(R\\)| CPU", "").split(" "),
0, 4
)
);
}

private static String getWindowsCPU() {
Expand Down Expand Up @@ -184,7 +171,7 @@ public static BenchResponse getBenchmark() {
} catch (Exception e) {
e.printStackTrace();
}
return null;
return new BenchResponse(-1, -1, -1, false);

}

Expand Down

0 comments on commit b7c6d29

Please sign in to comment.