Skip to content

Commit

Permalink
[feat] draw red in max ts path when perf
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Jun 2, 2024
1 parent 7e802bf commit ca4e1af
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/GraphCtrl/GraphElement/GElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,20 @@ CVoid GElement::dump(std::ostream& oss) {
CVoid GElement::dumpEdge(std::ostream& oss, GElementPtr src, GElementPtr dst, const std::string& label) {
if (src->isGroup() && dst->isGroup()) {
// 在group的逻辑中,添加 cluster_ 的信息
oss << 'p' << src << " -> p" << dst << label << "[ltail=cluster_p" << src << " lhead=cluster_p" << dst << "];\n";
oss << 'p' << src << " -> p" << dst << label << "[ltail=cluster_p" << src << " lhead=cluster_p" << dst << "]";
} else if (src->isGroup() && !dst->isGroup()) {
oss << 'p' << src << " -> p" << dst << label << "[ltail=cluster_p" << src << "];\n";
oss << 'p' << src << " -> p" << dst << label << "[ltail=cluster_p" << src << "]";
} else if (!src->isGroup() && dst->isGroup()) {
oss << 'p' << src << " -> p" << dst << label << "[lhead=cluster_p" << dst << "];\n";
oss << 'p' << src << " -> p" << dst << label << "[lhead=cluster_p" << dst << "]";
} else {
oss << 'p' << src << " -> p" << dst << label << ";\n";
oss << 'p' << src << " -> p" << dst << label;
}

if (src->perf_info_ && src->perf_info_->in_longest_path_
&& dst->perf_info_ && dst->perf_info_->in_longest_path_) {
oss << "[color=red]";
}
oss << ";\n";
}


Expand Down
1 change: 1 addition & 0 deletions src/GraphCtrl/GraphElement/GElementManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class GElementManager : public GElementObject,
friend class GPipeline;
friend class GRegion;
friend class GMutable;
friend class GPerf;
friend class UAllocator;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ CVoid GDynamicEngine::parallelRunAll() {
}
#endif


CVoid GDynamicEngine::serialRunAll() {
/**
* 如果分析出来 dag是一个链式的,则直接依次执行element
Expand Down
2 changes: 2 additions & 0 deletions src/GraphCtrl/GraphElement/_GOptimizer/GOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class GOptimizer : public GElementObject {

return paths;
}

friend class GPerf;
};

CGRAPH_NAMESPACE_END
Expand Down
30 changes: 30 additions & 0 deletions src/GraphCtrl/GraphPipeline/_GPerf/GPerf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "GPerf.h"
#include "GPerfDefine.h"
#include "../GPipeline.h"
#include "../../GraphElement/_GOptimizer/GOptimizerInclude.h"

CGRAPH_NAMESPACE_BEGIN

Expand All @@ -22,6 +23,9 @@ CStatus GPerf::perf(GPipelinePtr pipeline, std::ostream& oss) {
status = pipeline->process();
CGRAPH_FUNCTION_CHECK_STATUS

status = markLongestPath(pipeline);
CGRAPH_FUNCTION_CHECK_STATUS

status = pipeline->dump(oss);
CGRAPH_FUNCTION_CHECK_STATUS

Expand Down Expand Up @@ -49,6 +53,32 @@ CStatus GPerf::inject(GPipelinePtr pipeline) {
}


CStatus GPerf::markLongestPath(GPipelinePtr pipeline) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_NOT_NULL(pipeline, pipeline->element_manager_)
GElementPtrArr longestPath;
CFMSec maxTs = 0.0;
auto paths = GOptimizer::collectPaths(pipeline->element_manager_->manager_elements_);
for (const auto& path : paths) {
CFMSec curTs = 0.0;
for (auto* element : path) {
CGRAPH_ASSERT_NOT_NULL(element)
curTs += element->perf_info_->accu_cost_ts_;
}
if (curTs >= maxTs) {
maxTs = curTs;
longestPath = path;
}
}

for (auto* element : longestPath) {
CGRAPH_ASSERT_NOT_NULL(element->perf_info_)
element->perf_info_->in_longest_path_ = true;
}
CGRAPH_FUNCTION_END
}


CStatus GPerf::recover(GPipelinePtr pipeline) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_NOT_NULL(pipeline)
Expand Down
7 changes: 7 additions & 0 deletions src/GraphCtrl/GraphPipeline/_GPerf/GPerf.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ class GPerf : public GraphObject {
*/
static CStatus inject(GPipeline* pipeline);

/**
* 查询最长链路信息
* @param pipeline
* @return
*/
static CStatus markLongestPath(GPipeline* pipeline);

/**
* 恢复原来的pipeline信息
* @param pipeline
Expand Down
1 change: 1 addition & 0 deletions src/GraphCtrl/GraphPipeline/_GPerf/GPerfDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct GPerfInfo : public CStruct {
CFMSec first_start_ts_ = 0.0; // 开始的时间戳
CFMSec last_finish_ts_ = 0.0; // 最后一次结束的时间(需要考虑多次执行,或者多次被循环执行的情况)
CFMSec accu_cost_ts_ = 0.0; // 总体的耗时信息(累计值)
CBool in_longest_path_ = false; // 是否在最长耗时链路上
};

using GPerfInfoPtr = GPerfInfo *;
Expand Down

0 comments on commit ca4e1af

Please sign in to comment.