diff --git a/test/one/profiler/test/TestProcess.java b/test/one/profiler/test/TestProcess.java index 6b004ee93..c3cd2e4eb 100644 --- a/test/one/profiler/test/TestProcess.java +++ b/test/one/profiler/test/TestProcess.java @@ -212,6 +212,14 @@ private void moveLogs() { } } + private boolean isRoot() { + try (Stream lines = Files.lines(Paths.get("/proc/self/status"))) { + return lines.anyMatch(s -> s.startsWith("Uid:") && s.matches("Uid:\\s+0\\s+0.*")); + } catch (IOException e) { + return false; + } + } + @Override public void close() { p.destroy(); @@ -262,7 +270,7 @@ public Output profile(String args) throws IOException, TimeoutException, Interru public Output profile(String args, boolean sudo) throws IOException, TimeoutException, InterruptedException { List cmd = new ArrayList<>(); - if (sudo) { + if (sudo && (new File("/usr/bin/sudo").exists() || !isRoot())) { cmd.add("/usr/bin/sudo"); } cmd.add("build/bin/asprof");