HappenLee commented on code in PR #23377:
URL: https://github.com/apache/doris/pull/23377#discussion_r1319787850


##########
fe/fe-core/src/main/java/org/apache/doris/common/util/RuntimeProfile.java:
##########
@@ -299,12 +304,220 @@ public void prettyPrint(StringBuilder builder, String 
prefix) {
         }
     }
 
+    public void simpleProfile(int depth) {
+        if (depth == FRAGMENT_DEPTH) {
+            mergeMutiInstance(childList);
+            return;
+        }
+        for (int i = 0; i < childList.size(); i++) {
+            Pair<RuntimeProfile, Boolean> pair = childList.get(i);
+            RuntimeProfile profile = pair.first;
+            profile.simpleProfile(depth + 1);
+        }
+    }
+
+    private static void mergeMutiInstance(
+            LinkedList<Pair<RuntimeProfile, Boolean>> childList) {
+        /*
+         * Fragment 1: Fragment 1:
+         * Instance 0 Instance (total)
+         * Instance 1
+         * Instance 2
+         */
+        int numInstance = childList.size();
+        Pair<RuntimeProfile, Boolean> pair = childList.get(0);
+        RuntimeProfile mergedProfile = pair.first;
+        LinkedList<RuntimeProfile> other = new LinkedList<RuntimeProfile>();
+        for (int i = 1; i < childList.size(); i++) {
+            other.add(childList.get(i).first);
+        }
+        mergeInstanceProfile(mergedProfile, other);
+        childList.clear();
+        mergedProfile.name = "Instance " + "(" + numInstance + ")";
+        childList.add(Pair.of(mergedProfile, pair.second));
+    }
+
+    private static LinkedList<RuntimeProfile> getChildListFromLists(int idx, 
LinkedList<RuntimeProfile> rhs) {
+        LinkedList<RuntimeProfile> ret = new LinkedList<RuntimeProfile>();
+        for (RuntimeProfile profile : rhs) {
+            ret.add(profile.childList.get(idx).first);
+        }
+        return ret;
+    }
+
+    private static LinkedList<Counter> getCounterListFromLists(String 
counterName, LinkedList<RuntimeProfile> rhs) {
+        LinkedList<Counter> ret = new LinkedList<Counter>();
+        for (RuntimeProfile profile : rhs) {
+            ret.add(profile.counterMap.get(counterName));
+        }
+        return ret;
+    }
+
+    private static void mergeInstanceProfile(RuntimeProfile src, 
LinkedList<RuntimeProfile> rhs) {
+        mergeProfileCounter(src, ROOT_COUNTER, rhs);
+        mergeTotalTime(src, rhs);
+        mergeProfileInfoStr(src, rhs);
+        removePipelineContext(src);
+        for (int i = 0; i < src.childList.size(); i++) {
+            RuntimeProfile srcChild = src.childList.get(i).first;
+            LinkedList<RuntimeProfile> rhsChild = getChildListFromLists(i, 
rhs);
+            mergeInstanceProfile(srcChild, rhsChild);
+        }
+    }
+
+    private static void mergeTotalTime(RuntimeProfile src, 
LinkedList<RuntimeProfile> rhs) {
+        Counter counter = src.counterMap.get("TotalTime");
+        for (RuntimeProfile profile : rhs) {
+            Counter othCounter = profile.counterMap.get("TotalTime");
+            if (othCounter != null && counter != null) {
+                counter.addValue(othCounter);
+            }
+        }
+        counter.setValue(0); // Because the time is not accurate, it has been 
set to 0.
+    }
+
+    private static void removePipelineContext(RuntimeProfile src) {
+        LinkedList<Pair<RuntimeProfile, Boolean>> newChildList = new 
LinkedList<Pair<RuntimeProfile, Boolean>>();
+        for (Pair<RuntimeProfile, Boolean> pair : src.childList) {
+            RuntimeProfile profile = pair.first;
+            if (!profile.name.equals("PipelineContext")) {
+                newChildList.add(pair);
+            }
+        }
+        src.childList = newChildList;
+    }
+
+    // Will be used in the future.
+    // private static void removeNameExtra(RuntimeProfile src) {
+    // String[] parts = src.name.split("\\s+");
+    // src.name = parts[0];
+    // }
+
+    private static void mergeProfileCounter(RuntimeProfile src, String 
counterName, LinkedList<RuntimeProfile> rhs) {
+        Set<String> childCounterSet = src.childCounterMap.get(counterName);
+        if (childCounterSet == null) {
+            return;
+        }
+        List<String> childCounterList = new LinkedList<>(childCounterSet);
+        for (String childCounterName : childCounterList) {
+            Counter counter = src.counterMap.get(childCounterName);
+            LinkedList<Counter> rhsCounter = 
getCounterListFromLists(childCounterName, rhs);
+
+            mergeProfileCounter(src, childCounterName, rhs);
+            mergeCounter(src, childCounterName, counter, rhsCounter);
+            removeZeroeCounter(childCounterSet, childCounterName, counter);
+
+        }
+    }
+
+
+    // Will be used in the future.
+    // private static void removeInfoStr(RuntimeProfile src) {
+    //     src.infoStringsDisplayOrder.clear();
+    //     src.infoStrings.clear();
+    // }
+
+    // Will be used in the future.
+    // private static void removeMaxMinCounter(RuntimeProfile src, String 
counterName) {
+    //     String maxCounterName = MAX_TIME_PRE + counterName;
+    //     String minCounterName = MIN_TIME_PRE + counterName;
+    //     TreeSet<String> childCounterSet = 
src.childCounterMap.get(counterName);
+    //     if (childCounterSet != null) {
+    //         childCounterSet.remove(maxCounterName);
+    //         childCounterSet.remove(minCounterName);
+    //     }
+    // }
+
+    private static void mergeProfileInfoStr(RuntimeProfile src, 
LinkedList<RuntimeProfile> rhs) {
+        for (String key : src.infoStringsDisplayOrder) {
+            Set<String> strList = new TreeSet<String>();
+            strList.add(src.infoStrings.get(key));
+            for (RuntimeProfile profile : rhs) {
+                strList.add(profile.infoStrings.get(key));
+            }
+            try {
+                String joinedString = String.join("  |  ", strList);
+                src.infoStrings.put(key, joinedString);
+            } catch (Exception e) {
+                return;
+            }
+        }
+    }
+
+    private static void removeZeroeCounter(Set<String> childCounterSet, String 
childCounterName, Counter counter) {
+        if (counter.getValue() == 0) {
+            childCounterSet.remove(childCounterName);
+        }
+    }
+
+    // Will be used in the future.

Review Comment:
   remove the code of this 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to