This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch dev-1.1.2
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/dev-1.1.2 by this push:
     new d7e2166eee [dev-1.1.2](bugfix) pick some code manually for #11657 
(#11690)
d7e2166eee is described below

commit d7e2166eee1aed8c005d9a016ad14eab64651ebb
Author: yiguolei <[email protected]>
AuthorDate: Thu Aug 11 17:12:20 2022 +0800

    [dev-1.1.2](bugfix) pick some code manually for #11657 (#11690)
---
 .../apache/doris/common/profile/CounterNode.java   |  4 +++
 .../doris/common/profile/ProfileTreeNode.java      | 37 ++++++++++++++++++++++
 .../doris/common/profile/ProfileTreePrinter.java   | 37 ++++++++++++++++++++++
 .../httpv2/rest/manager/QueryProfileAction.java    |  4 +--
 4 files changed, 80 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/common/profile/CounterNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/common/profile/CounterNode.java
index 86f2d1a010..5934f05f05 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/profile/CounterNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/profile/CounterNode.java
@@ -27,6 +27,10 @@ public class CounterNode extends TreeNode<CounterNode> {
         counter = Pair.create(key, value);
     }
 
+    public Pair<String, String> getCounter() {
+        return counter;
+    }
+
     public String toTree(int indent) {
         StringBuilder sb = new StringBuilder();
         sb.append(debugString(indent));
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/common/profile/ProfileTreeNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/common/profile/ProfileTreeNode.java
index e68e9e71f0..10d71a58bc 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/common/profile/ProfileTreeNode.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/common/profile/ProfileTreeNode.java
@@ -20,6 +20,8 @@ package org.apache.doris.common.profile;
 import org.apache.doris.common.TreeNode;
 
 import com.google.common.base.Strings;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
 
 public class ProfileTreeNode extends TreeNode<ProfileTreeNode> {
 
@@ -135,6 +137,41 @@ public class ProfileTreeNode extends 
TreeNode<ProfileTreeNode> {
         return sb.toString();
     }
 
+
+    public JSONObject debugStringInJson(ProfileTreePrinter.PrintLevel level, 
String nodeLevel) {
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("id", nodeLevel);
+        JSONObject title = new JSONObject();
+        if (!id.equals(ProfileTreeBuilder.UNKNOWN_ID)) {
+            title.put("id", id);
+        }
+        title.put("name", name);
+        jsonObject.put("title", title);
+        if (level == ProfileTreePrinter.PrintLevel.FRAGMENT) {
+            jsonObject.put("fragment", fragmentId);
+            JSONArray labels = new JSONArray();
+            if (!Strings.isNullOrEmpty(maxInstanceActiveTime)) {
+                JSONObject label = new JSONObject();
+                label.put("name", "MaxActiveTime");
+                label.put("value", maxInstanceActiveTime);
+                labels.add(label);
+            }
+            jsonObject.put("labels", labels);
+        }
+        if (level == ProfileTreePrinter.PrintLevel.INSTANCE) {
+            jsonObject.put("active", activeTime);
+            jsonObject.put("non-child", nonChild);
+            JSONArray counters = new JSONArray();
+            for (CounterNode node : counterNode.getChildren()) {
+                JSONObject counter = new JSONObject();
+                counter.put(node.getCounter().first, node.getCounter().second);
+                counters.add(counter);
+            }
+            jsonObject.put("counters", counters);
+        }
+        return jsonObject;
+    }
+
     private String printIndent(int indent) {
         String res = "";
         for (int i = 0; i < indent; i++) {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/common/profile/ProfileTreePrinter.java
 
b/fe/fe-core/src/main/java/org/apache/doris/common/profile/ProfileTreePrinter.java
index 19d2f6a62f..0028d080ed 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/common/profile/ProfileTreePrinter.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/common/profile/ProfileTreePrinter.java
@@ -21,6 +21,10 @@ import hu.webarticum.treeprinter.BorderTreeNodeDecorator;
 import hu.webarticum.treeprinter.SimpleTreeNode;
 import hu.webarticum.treeprinter.TraditionalTreePrinter;
 
+import org.apache.commons.lang3.StringUtils;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+
 public class ProfileTreePrinter {
 
     public static enum PrintLevel {
@@ -52,4 +56,37 @@ public class ProfileTreePrinter {
         }
         return node;
     }
+
+
+    public static JSONObject printFragmentTreeInJson(ProfileTreeNode root, 
ProfileTreePrinter.PrintLevel level) {
+        JSONObject object = new JSONObject();
+        JSONArray jsonNodes = new JSONArray();
+        JSONArray edges = new JSONArray();
+        object.put("nodes", jsonNodes);
+        object.put("edges", edges);
+        buildNodeInJson(root, level, "", "", jsonNodes, edges);
+        return object;
+    }
+
+    private static void buildNodeInJson(ProfileTreeNode profileNode, 
PrintLevel level, String sourceNodeId,
+            String targetNodeId, JSONArray jsonNodes, JSONArray edges) {
+        boolean isFrist = false;
+        if (StringUtils.isBlank(sourceNodeId)) {
+            isFrist = true;
+            targetNodeId = "1";
+        }
+        jsonNodes.add(profileNode.debugStringInJson(level, targetNodeId));
+        int i = 0;
+        for (ProfileTreeNode child : profileNode.getChildren()) {
+            buildNodeInJson(child, level, targetNodeId, targetNodeId + i++, 
jsonNodes, edges);
+        }
+        if (!isFrist) {
+            JSONObject edge = new JSONObject();
+            edge.put("id", "e" + targetNodeId);
+            edge.put("source", sourceNodeId);
+            edge.put("target", targetNodeId);
+            edges.add(edge);
+        }
+    }
+    
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
 
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
index 7cbaa8273b..f0b02e00d6 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
@@ -44,6 +44,8 @@ import com.google.gson.reflect.TypeToken;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+import org.json.simple.JSONObject;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -350,7 +352,6 @@ public class QueryProfileAction extends RestBaseController {
         return ResponseEntityBuilder.ok(graph);
     }
 
-    @NotNull
     private ResponseEntity getJsonProfile(HttpServletRequest request, String 
queryId, String fragmentId,
             String instanceId, boolean isAllNode) {
         Map<String, String> graph = Maps.newHashMap();
@@ -376,7 +377,6 @@ public class QueryProfileAction extends RestBaseController {
         return ResponseEntityBuilder.ok(graph);
     }
 
-    @NotNull
     private ResponseEntity getProfileFromAllFrontends(HttpServletRequest 
request, String format, String queryId,
             String fragmentId, String instanceId) {
         String httpPath = "/rest/v2/manager/query/profile/" + format + "/" + 
queryId;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to