Skip to content

Commit

Permalink
[feat] change perf timestamp as us.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Aug 21, 2023
1 parent 6cde041 commit 33f970a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
12 changes: 7 additions & 5 deletions src/CBasic/CValType.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@

using CChar = CGraph::CCHAR;
using CUint = CGraph::CUINT;
using CSec = CGraph::CLONG; // 表示秒信息, for second
using CMSec = CGraph::CLONG; // 表示毫秒信息, for millisecond
using CSize = CGraph::CSIZE;
using CVoid = CGraph::CVOID;
using CVoidPtr = CGraph::CVOID *;
using CInt = CGraph::CINT;
using CLevel = CGraph::CINT;
using CLong = CGraph::CLONG;
using CULong = CGraph::CULONG;
using CBool = CGraph::CBOOL;
using CIndex = CGraph::CINT; // 表示标识信息,可以为负数
using CIndex = CGraph::CINT; // 表示标识信息,可以为负数
using CFloat = CGraph::CFLOAT;
using CDouble = CGraph::CDOUBLE;
using CConStr = CGraph::CCONSTR; // 表示 const char*
using CConStr = CGraph::CCONSTR; // 表示 const char*
using CBigBool = CGraph::CBIGBOOL;

using CLevel = CGraph::CINT;
using CSec = CGraph::CLONG; // 表示秒信息, for second
using CMSec = CGraph::CLONG; // 表示毫秒信息, for millisecond
using CFMSec = CGraph::CDOUBLE; // 表示毫秒信息,包含小数点信息

using CStatus = CGraph::CSTATUS;
using CException = CGraph::CEXCEPTION;

Expand Down
8 changes: 5 additions & 3 deletions src/GraphCtrl/GraphElement/GGroup/GSome/GSome.inl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ template<CSize TriggerNum>
CStatus GSome<TriggerNum>::run() {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_NOT_NULL(thread_pool_)
if (group_elements_arr_.size() < TriggerNum) {
CGRAPH_RETURN_ERROR_STATUS("this GSome need at least [" + std::to_string(TriggerNum) + "] element")
}

left_num_.store(TriggerNum); // 还剩n个,就完成当前GSome的执行逻辑
cur_status_ = CStatus();

Expand All @@ -51,9 +55,7 @@ CStatus GSome<TriggerNum>::run() {
return left_num_ <= 0 || cur_status_.isErr();
});

if (!cur_status_.isOK()) {
status = cur_status_; // 出错的话,赋值到外部去,让上游知道。
}
status = cur_status_; // 出错的话,赋值到外部去,让上游知道。
CGRAPH_FUNCTION_END
}

Expand Down
4 changes: 2 additions & 2 deletions src/GraphCtrl/GraphPipeline/_GPerf/GPerf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ CStatus GPerf::inject(GPipelinePtr pipeline) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_NOT_NULL(pipeline)

const CMSec now = CGRAPH_GET_CURRENT_MS();
const CFMSec now = CGRAPH_GET_CURRENT_ACCURATE_MS();
for (auto* cur : pipeline->repository_.elements_) {
/**
* 给其中的每个element,都添加这个切面信息
* 这里是不需要考虑 delete perf_info_的,因为在 element结束的时候,会自动释放
*/
cur->perf_info_ = UAllocator::safeMallocCStruct<GPerfInfo>();
cur->addGAspect<GPerfAspect<CMSec, GPerfInfoPtr>>(now, cur->perf_info_);
cur->addGAspect<GPerfAspect<CFMSec, GPerfInfoPtr>>(now, cur->perf_info_);
}
CGRAPH_FUNCTION_END
}
Expand Down
12 changes: 6 additions & 6 deletions src/GraphCtrl/GraphPipeline/_GPerf/GPerfAspect.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CGRAPH_NAMESPACE_BEGIN
template <typename ...Args>
class GPerfAspect : public GTemplateAspect<Args ...> {
protected:
explicit GPerfAspect(CMSec startTs, GPerfInfoPtr perfInfo) {
explicit GPerfAspect(CFMSec startTs, GPerfInfoPtr perfInfo) {
CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(perfInfo)
pipeline_start_ts_ = startTs;
perf_info_ = perfInfo;
Expand All @@ -26,7 +26,7 @@ class GPerfAspect : public GTemplateAspect<Args ...> {
CStatus beginRun() final {
CGRAPH_FUNCTION_BEGIN

cur_start_ts_ = CGRAPH_GET_CURRENT_MS();
cur_start_ts_ = CGRAPH_GET_CURRENT_ACCURATE_MS();
if (0 == perf_info_->first_start_ts_) {
// 记录开始的时间信息,仅记录第一次运行到这个node的时间信息
perf_info_->first_start_ts_ = (cur_start_ts_ - pipeline_start_ts_);
Expand All @@ -35,16 +35,16 @@ class GPerfAspect : public GTemplateAspect<Args ...> {
}

CVoid finishRun(const CStatus& curStatus) final {
auto cur = CGRAPH_GET_CURRENT_MS();
auto cur = CGRAPH_GET_CURRENT_ACCURATE_MS();
perf_info_->last_finish_ts_ = cur - pipeline_start_ts_;
perf_info_->loop_++;
perf_info_->accu_cost_ts_ += (cur - cur_start_ts_);
}

private:
CMSec pipeline_start_ts_ = 0; // 流水线开启的时间
CMSec cur_start_ts_ = 0; // 当前element开始运行的时间
GPerfInfoPtr perf_info_ = nullptr; // 具体赋值的对象
CFMSec pipeline_start_ts_ = 0.0; // 流水线开启的时间
CFMSec cur_start_ts_ = 0.0; // 当前element开始运行的时间
GPerfInfoPtr perf_info_ = nullptr; // 具体赋值的对象

friend class UAllocator;
};
Expand Down
8 changes: 4 additions & 4 deletions src/GraphCtrl/GraphPipeline/_GPerf/GPerfDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
CGRAPH_NAMESPACE_BEGIN

struct GPerfInfo : public CStruct {
CUint loop_ = 0; // 循环数
CUint first_start_ts_ = 0; // 开始的时间戳
CUint last_finish_ts_ = 0; // 最后一次结束的时间(需要考虑多次执行,或者多次被循环执行的情况)
CUint accu_cost_ts_ = 0; // 总体的耗时信息(累计值)
CUint loop_ = 0; // 循环数
CFMSec first_start_ts_ = 0.0; // 开始的时间戳
CFMSec last_finish_ts_ = 0.0; // 最后一次结束的时间(需要考虑多次执行,或者多次被循环执行的情况)
CFMSec accu_cost_ts_ = 0.0; // 总体的耗时信息(累计值)
};

using GPerfInfoPtr = GPerfInfo *;
Expand Down
7 changes: 4 additions & 3 deletions src/UtilsCtrl/UtilsFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ inline CVoid CGRAPH_ECHO(const char *cmd, ...) {
std::cout << "\n";
}


/**
* 获取当前的ms信息
* @return
*/
inline CMSec CGRAPH_GET_CURRENT_MS() {
inline CFMSec CGRAPH_GET_CURRENT_ACCURATE_MS() {
// 获取当前的时间戳信息
return (CMSec)std::chrono::time_point_cast<std::chrono::milliseconds> \
(std::chrono::system_clock::now()).time_since_epoch().count();
return (CFMSec)std::chrono::time_point_cast<std::chrono::microseconds> \
(std::chrono::steady_clock::now()).time_since_epoch().count() / (CFMSec)1000.0;
}


Expand Down

0 comments on commit 33f970a

Please sign in to comment.