diff --git a/fe/fe-core/src/main/java/com/starrocks/memory/ProcProfileCollector.java b/fe/fe-core/src/main/java/com/starrocks/memory/ProcProfileCollector.java index a31c97b604f8b..5b9abd97cbd48 100644 --- a/fe/fe-core/src/main/java/com/starrocks/memory/ProcProfileCollector.java +++ b/fe/fe-core/src/main/java/com/starrocks/memory/ProcProfileCollector.java @@ -42,11 +42,13 @@ public class ProcProfileCollector extends FrontendDaemon { private static final Logger LOG = LogManager.getLogger(ProcProfileCollector.class); private static final String CPU_FILE_NAME_PREFIX = "cpu-profile-"; private static final String MEM_FILE_NAME_PREFIX = "mem-profile-"; + private static final long LOG_INTERVAL = 3600 * 1000L; private final SimpleDateFormat profileTimeFormat = new SimpleDateFormat("yyyyMMdd-HHmmss"); private final String profileLogDir; private long lastCollectTime = -1; + private long lastLogTime = -1; public ProcProfileCollector() { super("ProcProfileCollector"); @@ -87,7 +89,7 @@ private void collectMemProfile() { try { compressFile(fileName); } catch (IOException e) { - LOG.warn("compress file {} failed", fileName, e); + checkAndLog(() -> LOG.warn("compress file {} failed, reason: {}", fileName, e.getMessage())); } } @@ -102,7 +104,7 @@ private void collectCPUProfile() { try { compressFile(fileName); } catch (IOException e) { - LOG.warn("compress file {} failed", fileName, e); + checkAndLog(() -> LOG.warn("compress file {} failed, reason: {}", fileName, e.getMessage())); } } @@ -112,13 +114,13 @@ private void collectProfile(String... command) { Process process = processBuilder.start(); process.waitFor(); if (process.exitValue() != 0) { - LOG.info("collect profile failed, stdout: {}, stderr: {}", + checkAndLog(() -> LOG.warn("collect profile failed, stdout: {}, stderr: {}", getMsgFromInputStream(process.getInputStream()), - getMsgFromInputStream(process.getErrorStream())); + getMsgFromInputStream(process.getErrorStream()))); stopProfile(); } } catch (IOException | InterruptedException e) { - LOG.warn("collect profile failed", e); + checkAndLog(() -> LOG.warn("collect profile failed, reason: {}", e.getMessage())); } } @@ -133,11 +135,11 @@ private void stopProfile() { process.destroyForcibly(); } } catch (IOException | InterruptedException e) { - LOG.warn("stop profile failed", e); + checkAndLog(() -> LOG.warn("stop profile failed, reason: {}", e.getMessage())); } } - private String getMsgFromInputStream(InputStream inputStream) throws IOException { + private String getMsgFromInputStream(InputStream inputStream) { if (inputStream == null) { return ""; } @@ -148,6 +150,9 @@ private String getMsgFromInputStream(InputStream inputStream) throws IOException sb.append(line).append("\n"); } return sb.toString(); + } catch (IOException e) { + checkAndLog(() -> LOG.warn("get message from input stream failed, reason: {}", e.getMessage())); + return ""; } } @@ -227,4 +232,11 @@ private String getPid() { .getName() .split("@")[0]; } + + private void checkAndLog(Runnable runnable) { + if (System.currentTimeMillis() - lastLogTime > LOG_INTERVAL) { + runnable.run(); + lastLogTime = System.currentTimeMillis(); + } + } }