Commit b1a2bbea authored by Martin Marinov's avatar Martin Marinov

Maintain the number of done children in Progress::Node.

parent 9b6541f6
......@@ -6,6 +6,7 @@
#include "ProgressNode.hh"
#include "Base/Utils/BaseError.hh"
#include "Base/Utils/IOutputStream.hh"
#include "Base/Debug/DebOut.hh"
#include <exception>
#include <fstream>
......@@ -84,10 +85,12 @@ void Context::enter_node(Node* const _node)
// of the node graph from a tracking thread. It assumes the tracking thread
// does not use the node parent.
_node->tick_nmbr_ = 0;
_node->done_chld_nmbr_ = 0;
if (phony()) // no active node, ...
root_node_ = _node; // ... so the node to enter is the root
else // the current active node becomes the parent of the node to enter
_node->prnt_ = actv_node_;
_node->prnt_ = actv_node_; // make the parent the active node
if (logging()) // record the entry time
{
if (actv_node_ != nullptr) // add the elapsed time to the active node
......@@ -102,8 +105,12 @@ void Context::exit_node()
{ // NOTE: this function is written carefully to allow asynchronous inspection
// of the node graph from a tracking thread. It assumes the tracking thread
// does not use the node parent.
if (phony())
return; // TODO: this condition is a bug, so we need a DEB_error() here?
if (phony())
{// this is a bug, but guard against it anyway since it's difficult to test
DEB_error("Context exits from the phony() node!");
return;
}
if (logging())
{// log the node on exit
actv_node_->time_ns_ += log_data_->elapsed_nanoseconds();
......@@ -118,9 +125,30 @@ void Context::exit_node()
// record the re-entry time into the parent _node
log_data_->record_entry_time();
}
auto* const prnt = actv_node_->prnt_;
actv_node_->prnt_ = nullptr;
actv_node_ = prnt == nullptr ? &phny_root_ : prnt;
if (prnt == nullptr)
{
actv_node_ = &phny_root_;
return;
}
int done_chld_nmbr = 0;
DEB_only(bool chld_fnd = false);
for (auto chld = prnt->child(); chld != nullptr; chld = chld->next())
{// seek the "active" child in the parent's list of children
++done_chld_nmbr;
if (chld == actv_node_) // found the active child which is just exiting
{
DEB_only(chld_fnd = true);
break;
}
}
DEB_error_if(!chld_fnd, "Could not find the child node " << actv_node_->name
<< " in the children list of the parent node " << prnt->name);
prnt->done_chld_nmbr_ = done_chld_nmbr; // update the parent data
actv_node_ = prnt; // activate the parent
}
void Context::set_logging(const bool _lgng)
......
......@@ -51,7 +51,7 @@ public:
Node(const char* const _name,
Node* _next = nullptr, Node* _chld = nullptr)
: name(_name), next_(_next), chld_(_chld), prnt_(nullptr),
tick_nmbr_(0), time_ns_(0)
done_chld_nmbr_(0), tick_nmbr_(0), time_ns_(0)
{}
virtual ~Node();
......@@ -61,8 +61,12 @@ public:
void tick() { ++tick_nmbr_; }
//! Number of ticks recorded
TickNumber tick_number() const { return tick_nmbr_; }
//! Number of children that have been completed
int done_child_number() const { return done_chld_nmbr_; }
/*
Relative weight of this node in the overall computation process, default is 1.
*/
......@@ -87,6 +91,8 @@ protected:
Node* prnt_; //!< parent node, set temporarily
TickNumber tick_nmbr_; /*!< number of ticks in the node, exclusive of the
ticks in child nodes */
int done_chld_nmbr_; //!< Number of child nodes that made their exit
private:
TickNumber time_ns_; /*!< Time in nanoseconds spent in the node since it was
entered, exclusive of the time spent in child nodes. This is recorded only
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment