Skip to content

Commit

Permalink
[perf] add adaptor perf show type. simplify dump code
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Sep 9, 2023
1 parent 56339c3 commit d8f6e1f
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/GraphCtrl/GraphDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static const char* CGRAPH_STR_DAEMON = "daemon";
static const char* CGRAPH_STR_ASPECT = "aspect";
static const char* CGRAPH_STR_EVENT = "event";
static const char* CGRAPH_STR_FENCE = "fence";
static const char* CGRAPH_STR_COORDINATOR = "coordinator";

CGRAPH_NAMESPACE_END

Expand Down
20 changes: 11 additions & 9 deletions src/GraphCtrl/GraphElement/GAdapter/GCoordinator/GCoordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ CGRAPH_NAMESPACE_BEGIN
template<CInt SIZE>
class GCoordinator : public GAdapter {
protected:
CStatus run() final {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_NOT_NULL(thread_pool_)
status = (SIZE >= 0)
? thread_pool_->createSecondaryThread(SIZE)
: thread_pool_->releaseSecondaryThread((-1) * SIZE);

CGRAPH_FUNCTION_END
}
explicit GCoordinator();

CStatus run() final;

CVoid dumpElement(std::ostream& oss) final;

CStatus checkSuitable() final;

friend class GPipeline;
};

template<CInt SIZE>
using GCoordinatorPtr = GCoordinator<SIZE> *;

CGRAPH_NAMESPACE_END

#include "GCoordinator.inl"

#endif //CGRAPH_GCOORDINATOR_H
54 changes: 54 additions & 0 deletions src/GraphCtrl/GraphElement/GAdapter/GCoordinator/GCoordinator.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/***************************
@Author: Chunel
@Contact: [email protected]
@File: GCoordinator.inl
@Time: 2023/9/8 21:12
@Desc:
***************************/

#ifndef CGRAPH_GCOORDINATOR_INL
#define CGRAPH_GCOORDINATOR_INL

#include "GCoordinator.h"

CGRAPH_NAMESPACE_BEGIN

template<CInt SIZE>
GCoordinator<SIZE>::GCoordinator() {
element_type_ = GElementType::COORDINATOR;
session_ = URandom<>::generateSession(CGRAPH_STR_COORDINATOR);
}


template<CInt SIZE>
CStatus GCoordinator<SIZE>::run() {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_NOT_NULL(thread_pool_)
status = (SIZE >= 0)
? thread_pool_->createSecondaryThread(SIZE)
: thread_pool_->releaseSecondaryThread((-1) * SIZE);

CGRAPH_FUNCTION_END
}


template<CInt SIZE>
CVoid GCoordinator<SIZE>::dumpElement(std::ostream& oss) {
dumpElementHeader(oss);
dumpPerfInfo(oss);
oss << "\", shape=diamond]\n";
}


template<CInt SIZE>
CStatus GCoordinator<SIZE>::checkSuitable() {
CGRAPH_FUNCTION_BEGIN
CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION(loop_ > 1, \
"cannot set GCoordinator loop > 1")

CGRAPH_FUNCTION_END
}

CGRAPH_NAMESPACE_END

#endif //CGRAPH_GCOORDINATOR_INL
7 changes: 7 additions & 0 deletions src/GraphCtrl/GraphElement/GAdapter/GFence/GFence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ CStatus GFence::checkSuitable() {
}


CVoid GFence::dumpElement(std::ostream& oss) {
dumpElementHeader(oss);
dumpPerfInfo(oss);
oss << "\", shape=box]\n";
}


CStatus GFence::run() {
CGRAPH_FUNCTION_BEGIN

Expand Down
4 changes: 3 additions & 1 deletion src/GraphCtrl/GraphElement/GAdapter/GFence/GFence.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class GFence : public GAdapter {
protected:
explicit GFence();

CStatus checkSuitable() override;
CStatus checkSuitable() final;

CVoid dumpElement(std::ostream& oss) final;

CGRAPH_DECLARE_GPARAM_MANAGER_WRAPPER

Expand Down
18 changes: 11 additions & 7 deletions src/GraphCtrl/GraphElement/GElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,7 @@ CVoid GElement::dumpEdge(std::ostream& oss, GElementPtr src, GElementPtr dst, co


CVoid GElement::dumpElement(std::ostream& oss) {
oss << 'p' << this << "[label=\"";
if (this->name_.empty()) {
oss << 'p' << this; // 如果没有名字,则通过当前指针位置来代替
} else {
oss << this->name_;
}

dumpElementHeader(oss);
dumpPerfInfo(oss);

oss << "\"];\n";
Expand All @@ -322,6 +316,16 @@ CVoid GElement::dumpElement(std::ostream& oss) {
}


CVoid GElement::dumpElementHeader(std::ostream& oss) {
oss << 'p' << this << "[label=\"";
if (this->name_.empty()) {
oss << 'p' << this; // 如果没有名字,则通过当前指针位置来代替
} else {
oss << this->name_;
}
}


CVoid GElement::dumpPerfInfo(std::ostream& oss) {
if (perf_info_ && perf_info_->loop_ > 0) {
// 包含 perf信息的情况
Expand Down
9 changes: 8 additions & 1 deletion src/GraphCtrl/GraphElement/GElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,14 @@ class GElement : public GElementObject,
* graphviz dump 点逻辑
* @param oss
*/
CVoid dumpElement(std::ostream& oss);
virtual CVoid dumpElement(std::ostream& oss);

/**
* dump 当前element的header。主要就是为了代码
* @param oss
* @return
*/
CVoid dumpElementHeader(std::ostream& oss);

/**
* graphviz dump perf逻辑
Expand Down
1 change: 1 addition & 0 deletions src/GraphCtrl/GraphElement/GElementDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum class GElementType {
FUNCTION = 0x00040001, // 函数
SINGLETON = 0x00040002, // 单例
FENCE = 0x00040004, // 栅栏
COORDINATOR = 0x00040008, // 协调
};


Expand Down
4 changes: 4 additions & 0 deletions src/GraphCtrl/GraphPipeline/GPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
@Desc:
***************************/

#include <iomanip>

#include "GPipeline.h"

CGRAPH_NAMESPACE_BEGIN
Expand Down Expand Up @@ -154,6 +156,8 @@ CStatus GPipeline::resume() {
CStatus GPipeline::dump(std::ostream& oss) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_NOT_NULL(element_manager_)
oss << std::fixed << std::setprecision(2); // 小数点最多展示2位数字

oss << "\ndigraph CGraph {\n";
oss << "compound=true;\n";

Expand Down

0 comments on commit d8f6e1f

Please sign in to comment.