sys-sage
|
#include <Component.hpp>
Public Member Functions | |
Component (int _id=0, string _name="unknown", int _componentType=SYS_SAGE_COMPONENT_NONE) | |
Component (Component *parent, int _id=0, string _name="unknown", int _componentType=SYS_SAGE_COMPONENT_NONE) | |
void | InsertChild (Component *child) |
int | InsertBetweenParentAndChild (Component *parent, Component *child, bool alreadyParentsChild) |
int | InsertBetweenParentAndChildren (Component *parent, vector< Component * > children, bool alreadyParentsChild) |
int | RemoveChild (Component *child) |
void | SetParent (Component *parent) |
void | PrintSubtree () |
void | PrintAllDataPathsInSubtree () |
string | GetName () |
void | SetName (string _name) |
int | GetId () |
int | GetComponentType () |
string | GetComponentTypeStr () |
vector< Component * > * | GetChildren () |
Component * | GetParent () |
Component * | GetChild (int _id) |
Component * | GetChildById (int _id) |
Component * | GetChildByType (int _componentType) |
vector< Component * > | GetAllChildrenByType (int _componentType) |
void | GetAllChildrenByType (vector< Component * > *_outArray, int _componentType) |
Component * | FindSubcomponentById (int _id, int _componentType) |
Component * | GetSubcomponentById (int _id, int _componentType) |
void | GetAllSubcomponentsByType (vector< Component * > *outArray, int _componentType) |
vector< Component * > | GetAllSubcomponentsByType (int _componentType) |
int | CountAllSubcomponents () |
int | CountAllSubcomponentsByType (int _componentType) |
int | CountAllChildrenByType (int _componentType) |
Component * | GetAncestorByType (int _componentType) |
int | GetNumThreads () |
int | GetSubtreeDepth () |
Component * | GetNthAncestor (int n) |
void | GetNthDescendents (vector< Component * > *outArray, int depth) |
vector< Component * > | GetNthDescendents (int depth) |
void | GetSubcomponentsByType (vector< Component * > *outArray, int componentType) |
vector< Component * > | GetSubcomponentsByType (int _componentType) |
void | GetComponentsInSubtree (vector< Component * > *outArray) |
vector< Component * > | GetComponentsInSubtree () |
vector< DataPath * > * | GetDataPaths (int orientation) |
DataPath * | GetDataPathByType (int dp_type, int orientation) |
void | GetAllDataPathsByType (vector< DataPath * > *outDpArr, int dp_type, int orientation) |
vector< DataPath * > | GetAllDataPathsByType (int dp_type, int orientation) |
int | CheckComponentTreeConsistency () |
Checks the consistency of the component tree starting from this component. | |
int | GetTopologySize (unsigned *out_component_size, unsigned *out_dataPathSize) |
int | GetDepth (bool refresh) |
void | DeleteDataPath (DataPath *dp) |
void | DeleteAllDataPaths () |
void | DeleteSubtree () |
void | Delete (bool withSubtree=true) |
Public Attributes | |
std::map< std::string, void * > | attrib |
Protected Attributes | |
int | id |
int | depth |
string | name |
int | count {-1} |
const int | componentType |
vector< Component * > | children |
Component * | parent { nullptr } |
vector< DataPath * > | dp_incoming |
vector< DataPath * > | dp_outgoing |
Generic class Component - all components inherit from this class, i.e. this class defines attributes and methods common to all components.
Therefore, these can be used universally among all components. Usually, a Component instance would be an instance of one of the child classes, but a generic component (instance of class Component) is also possible.
Component::Component | ( | int | _id = 0, |
string | _name = "unknown", | ||
int | _componentType = SYS_SAGE_COMPONENT_NONE ) |
Component::Component | ( | Component * | parent, |
int | _id = 0, | ||
string | _name = "unknown", | ||
int | _componentType = SYS_SAGE_COMPONENT_NONE ) |
Generic Component constructor with insertion into the Component Tree as the parent 's child (as long as parent is an existing Component). Usually one of the derived subclasses for different Component Types will be created. Sets:
parent | = the parent |
_id | = id, default 0 |
_name | = name, default "unknown" |
_componentType | = componentType, default SYS_SAGE_COMPONENT_NONE |
int Component::CheckComponentTreeConsistency | ( | ) |
Checks the consistency of the component tree starting from this component.
This function verifies that each child component has this component set as its parent. It logs an error message for each child that has an incorrect parent and increments the error count. The function then recursively checks the consistency of the entire subtree rooted at each child component.
The function returns the total number of errors found in the component tree, including errors in the direct children and any nested descendants.
int Component::CountAllChildrenByType | ( | int | _componentType | ) |
Counts number of children matching the requested component type.
_componentType | - Component type to look for. |
int Component::CountAllSubcomponents | ( | ) |
Counts number of subcomponents (children, their children and so on).
int Component::CountAllSubcomponentsByType | ( | int | _componentType | ) |
Counts number of subcomponents (children, their children and so on) matching the requested component type.
_componentType | - Component type to look for. |
void Component::Delete | ( | bool | withSubtree = true | ) |
Deletes a component, its children (if withSubtree = true) and all the associated data paths. If only the component itself is deleted, its children are inserted into its parent's children list.
withSubtree | - if true, the whole subtree is deleted, otherwise only the component itself. |
void Component::DeleteAllDataPaths | ( | ) |
Deletes all DataPaths of this component.
void Component::DeleteDataPath | ( | DataPath * | dp | ) |
void Component::DeleteSubtree | ( | ) |
Deletes the whole subtree (all the children) of the component.
Component * Component::FindSubcomponentById | ( | int | _id, |
int | _componentType ) |
OBSOLETE. Use GetSubcomponentById instead. This function will be removed in the future.
vector< Component * > Component::GetAllChildrenByType | ( | int | _componentType | ) |
Searches for all the children matching the given component type.
_componentType | - Required type of components |
void Component::GetAllChildrenByType | ( | vector< Component * > * | _outArray, |
int | _componentType ) |
Searches for all the children matching the given component type.
_componentType | - Required type of components |
outArray | - output parameter (vector with results) An input is pointer to a std::vector<Component *>, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). The method pushes back the found elements – i.e. the elements(pointers) can be found in this array after the method returns. (If no found, nothing will be pushed into the vector.) |
vector< DataPath * > Component::GetAllDataPathsByType | ( | int | dp_type, |
int | orientation ) |
Retrieves all DataPath * from the list of this component's data paths with matching type and orientation. Results are returned in a vector<DataPath*>*, where first the matching data paths in dp_outgoing are pushed back, then the ones in dp_incoming.
dp_type | - DataPath type (dp_type) to search for. |
orientation | - orientation of the DataPath (SYS_SAGE_DATAPATH_OUTGOING or SYS_SAGE_DATAPATH_INCOMING or a logical or of these) |
void Component::GetAllDataPathsByType | ( | vector< DataPath * > * | outDpArr, |
int | dp_type, | ||
int | orientation ) |
Retrieves all DataPath * from the list of this component's data paths with matching type and orientation. Results are returned in vector<DataPath*>* outDpArr, where first the matching data paths in dp_outgoing are pushed back, then the ones in dp_incoming.
dp_type | - DataPath type (dp_type) to search for. |
orientation | - orientation of the DataPath (SYS_SAGE_DATAPATH_OUTGOING or SYS_SAGE_DATAPATH_INCOMING or a logical or of these) |
outDpArr | - output parameter (vector with results) An input is pointer to a std::vector<DataPath *>, in which the data paths will be pushed. It must be allocated before the call (but does not have to be empty). The method pushes back the found data paths – i.e. the data paths(pointers) can be found in this array after the method returns. (If no found, the vector is not changed.) |
vector< Component * > Component::GetAllSubcomponentsByType | ( | int | _componentType | ) |
Searches for all the subcomponents (children, their children and so on) matching the given component type.
_componentType | - Required type of components. |
void Component::GetAllSubcomponentsByType | ( | vector< Component * > * | outArray, |
int | _componentType ) |
Searches for all the subcomponents (children, their children and so on) matching the given component type.
_componentType | - Required type of components |
outArray | - output parameter (vector with results) An input is pointer to a std::vector<Component *>, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). The method pushes back the found elements – i.e. the elements(pointers) can be found in this array after the method returns. (If no found, nothing will be pushed into the vector.) |
Component * Component::GetAncestorByType | ( | int | _componentType | ) |
Moves up the tree until a parent of given type.
_componentType | - the desired component type |
Component * Component::GetChild | ( | int | _id | ) |
Identical to GetChildById Retrieve a Component* to a child with child.id=_id.
Should there be more children with the same id, the first match will be retrieved (i.e. the one with lower index in the children array.)
Component * Component::GetChildById | ( | int | _id | ) |
Retrieve a Component* to a child with child.id=_id.
Should there be more children with the same id, the first match will be retrieved (i.e. the one with lower index in the children array.)
Component * Component::GetChildByType | ( | int | _componentType | ) |
Retrieve a Component* to a child matching the given component type.
Should there be more children with the same type, the first match will be retrieved (i.e. the one with lower index in the children array.)
vector< Component * > * Component::GetChildren | ( | ) |
Returns a pointer to std::vector containing all children of the component (empty vector if no children) .
vector< Component * > Component::GetComponentsInSubtree | ( | ) |
Retrieves a std::vector of Component pointers, which form the subtree (current node and all the subcomponents) of this.
void Component::GetComponentsInSubtree | ( | vector< Component * > * | outArray | ) |
Retrieves a std::vector of Component pointers, which form the subtree (current node and all the subcomponents) of this.
outArray | - output parameter (vector with results) An input is pointer to a std::vector<Component *>, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). The method pushes back the found elements – i.e. the elements(pointers) can be found in this array after the method returns. (If no found, the vector is not changed.) |
int Component::GetComponentType | ( | ) |
Returns component type of the component. The component type denotes of which class the instance is (Often the components are stored as Component*, even though they are a member of one of the child classes)
SYS_SAGE_COMPONENT_NONE -> class Component
SYS_SAGE_COMPONENT_THREAD -> class Thread
SYS_SAGE_COMPONENT_CORE -> class Core
SYS_SAGE_COMPONENT_CACHE -> class Cache
SYS_SAGE_COMPONENT_SUBDIVISION -> class Subdivision
SYS_SAGE_COMPONENT_NUMA -> class Numa
SYS_SAGE_COMPONENT_CHIP -> class Chip
SYS_SAGE_COMPONENT_MEMORY -> class Memory
SYS_SAGE_COMPONENT_STORAGE -> class Storage
SYS_SAGE_COMPONENT_NODE -> class Node
SYS_SAGE_COMPONENT_TOPOLOGY -> class Topology
string Component::GetComponentTypeStr | ( | ) |
Returns component type in human-readable string.
SYS_SAGE_COMPONENT_NONE -> "None"
SYS_SAGE_COMPONENT_THREAD -> "HW_thread"
SYS_SAGE_COMPONENT_CORE -> "Core"
SYS_SAGE_COMPONENT_CACHE -> "Cache"
SYS_SAGE_COMPONENT_SUBDIVISION -> "Subdivision"
SYS_SAGE_COMPONENT_NUMA -> "NUMA"
SYS_SAGE_COMPONENT_CHIP -> "Chip"
SYS_SAGE_COMPONENT_MEMORY -> "Memory"
SYS_SAGE_COMPONENT_STORAGE -> "Storage"
SYS_SAGE_COMPONENT_NODE -> "Node"
SYS_SAGE_COMPONENT_TOPOLOGY -> "Topology"
DataPath * Component::GetDataPathByType | ( | int | dp_type, |
int | orientation ) |
Retrieves a DataPath * from the list of this component's data paths with matching type and orientation.
The first match is returned – first SYS_SAGE_DATAPATH_OUTGOING are searched, then SYS_SAGE_DATAPATH_INCOMING.
dp_type | - DataPath type (dp_type) to search for |
orientation | - orientation of the DataPath (SYS_SAGE_DATAPATH_OUTGOING or SYS_SAGE_DATAPATH_INCOMING or a logical or of these) |
vector< DataPath * > * Component::GetDataPaths | ( | int | orientation | ) |
Returns the DataPaths of this component according to their orientation.
orientation | - either SYS_SAGE_DATAPATH_OUTGOING or SYS_SAGE_DATAPATH_INCOMING |
int Component::GetDepth | ( | bool | refresh | ) |
Retrieves the depth (level) of a component in the topology.
refresh | - Boolean value, if true: recalculate the position (depth) of the component in the tree, if false, return the already stored value |
int Component::GetId | ( | ) |
string Component::GetName | ( | ) |
Component * Component::GetNthAncestor | ( | int | n | ) |
Retrieves Nth ancestor, which resides N levels above.
E.g. if n=1, the parent is retrieved; if n=2, the grandparent is retrieved and so on.
n | - how many levels above the tree should be looked. |
vector< Component * > Component::GetNthDescendents | ( | int | depth | ) |
Retrieves a std::vector of Component pointers, which reside 'depth' levels deeper. The tree is traversed in order as the children are stored in the std::vector.
E.g. if depth=1, only children of the current are retrieved; if depth=2, only children of the children are retrieved..
depth | - how many levels down the tree should be looked |
void Component::GetNthDescendents | ( | vector< Component * > * | outArray, |
int | depth ) |
Retrieves a std::vector of Component pointers, which reside 'depth' levels deeper. The tree is traversed in order as the children are stored in std::vector children.
E.g. if depth=1, only children of the current are retrieved; if depth=2, only children of the children are retrieved..
depth | - how many levels down the tree should be looked |
outArray | - output parameter (vector with results) An input is pointer to a std::vector<Component *>, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). The method pushes back the found elements – i.e. the elements(pointers) can be found in this array after the method returns. (If no found, nothing will be pushed into the vector.) |
int Component::GetNumThreads | ( | ) |
OBSOLETE. Use int CountAllSubcomponentsByType(SYS_SAGE_COMPONENT_THREAD) instead. Returns the number of Components of type SYS_SAGE_COMPONENT_THREAD in the subtree.
Component * Component::GetParent | ( | ) |
Returns Component pointer to parent (or NULL if this component is the root)
Component * Component::GetSubcomponentById | ( | int | _id, |
int | _componentType ) |
Searches the subtree to find a component with a matching id and componentType, i.e. looks for a certain component with a matching ID. The search is a DFS. The search starts with the calling component.
Returns first occurence that matches these criteria.
_id | - the id to look for |
_componentType | - the component type where to look for the id |
vector< Component * > Component::GetSubcomponentsByType | ( | int | _componentType | ) |
Retrieves a std::vector of Component pointers, which reside in the subtree and have a matching type. The tree is traversed DFS in order as the children are stored in the std::vector.
componentType | - componentType |
void Component::GetSubcomponentsByType | ( | vector< Component * > * | outArray, |
int | componentType ) |
Retrieves a std::vector of Component pointers, which reside in the subtree and have a matching type. The tree is traversed DFS in order as the children are stored in each std::vector children.
componentType | - componentType |
outArray | - output parameter (vector with results) An input is pointer to a std::vector<Component *>, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). The method pushes back the found elements – i.e. the elements(pointers) can be found in this array after the method returns. (If no found, the vector is not changed.) |
int Component::GetSubtreeDepth | ( | ) |
Retrieves maximal distance to a leaf (i.e. the depth of the subtree).
0=leaf, 1=children are leaves, 2=at most children's children are leaves .....
int Component::GetTopologySize | ( | unsigned * | out_component_size, |
unsigned * | out_dataPathSize ) |
Calculates approximate memory footprint of the subtree of this element (including the relevant data paths).
out_component_size | - output parameter (contains the footprint of the component tree elements); an already allocated unsigned * is the input, the value is expected to be 0 (the result is accumulated here) |
out_dataPathSize | - output parameter (contains the footprint of the data-path graph elements); an already allocated unsigned * is the input, the value is expected to be 0 (the result is accumulated here) |
int Component::InsertBetweenParentAndChild | ( | Component * | parent, |
Component * | child, | ||
bool | alreadyParentsChild ) |
Inserts this component between a parent and one of its children. The parent component remains the parent, this Component becomes a new child of the parent, and the specified child becomes this component's child.
parent | The parent component to which this component will be inserted as a child. |
child | The child component that will become the child of this component and will remain a descendant of the original parent. |
alreadyParentsChild | A boolean flag indicating whether this component is already a child of the parent. If true, the function assumes that this component is already present as a child of the parent and only needs to reassign the specified child. If false, the function will add this component as a new child of the parent after reassigning the specified child. |
int Component::InsertBetweenParentAndChildren | ( | Component * | parent, |
vector< Component * > | children, | ||
bool | alreadyParentsChild ) |
Inserts this component between a parent and a (subset of) his children. The parent component remains parent, this Component becomes a new child, and the children become parent's grandchildren.
parent | The parent component to which this component will be inserted as a child. |
children | A vector of child components that will become the children of this component and the grandchildren of the original parent. |
alreadyParentsChild | A boolean flag indicating whether this component is already a child of the parent. If true, the function assumes that this component is already present as a child of the parent and only needs to reassign the specified children. If false, the function will add this component as a new child of the parent after reassigning the specified children. |
void Component::InsertChild | ( | Component * | child | ) |
Inserts a Child component to this component (in the Component Tree). The child pointer will be inserted at the end of std::vector of children (retrievable through GetChildren(), GetChild(int _id) etc.)
void Component::PrintAllDataPathsInSubtree | ( | ) |
Prints to stdout basic information about all DataPaths that go either from or to the components in the subtree.
For each component, all outgoing and incoming DataPaths are printed, i.e. a DataPath may be printed twice.
void Component::PrintSubtree | ( | ) |
Prints the whole subtree of this component (including the component itself) to stdout. The tree is printed in DFS order, so that the hierarchy can be easily seen. Each child is indented by " ". For each component in the subtree, the following is printed: "<string component type> (name <name>) id <id> - children: <num children>
int Component::RemoveChild | ( | Component * | child | ) |
Removes the passed component from the list of children, without completely deleting (and deallocating) the child itself
child | - child to remove |
void Component::SetName | ( | string | _name | ) |
void Component::SetParent | ( | Component * | parent | ) |
Define a parent to the component. This is usually used when inserting a component in the tree (by calling InsertChild on the parent, and calling SetParent on the child).
std::map<std::string, void*> Component::attrib |
A map for storing arbitrary pieces of information or data.
key
denotes the name of the attribute.value
points to the data, stored as a void*
.This data structure is designed to store a wide variety of data types by utilizing pointers to void. Due to its flexibility, it is essential to manage the types and memory allocation/deallocation carefully to avoid issues such as memory leaks or undefined behavior.
Usage:
Note:
void*
pointers. Always ensure that dynamically allocated memory is freed when no longer needed.
|
protected |
Contains the list (std::vector) of pointers to children of the component in the component tree.
|
protected |
Component type of the component. The component type denotes of which class the instance is (Often the components are stored as Component*, even though they are a member of one of the child classes)
This attribute is constant, set by the constructor, and READONLY.
SYS_SAGE_COMPONENT_NONE -> class Component
SYS_SAGE_COMPONENT_THREAD -> class Thread
SYS_SAGE_COMPONENT_CORE -> class Core
SYS_SAGE_COMPONENT_CACHE -> class Cache
SYS_SAGE_COMPONENT_SUBDIVISION -> class Subdivision
SYS_SAGE_COMPONENT_NUMA -> class Numa
SYS_SAGE_COMPONENT_CHIP -> class Chip
SYS_SAGE_COMPONENT_MEMORY -> class Memory
SYS_SAGE_COMPONENT_STORAGE -> class Storage
SYS_SAGE_COMPONENT_NODE -> class Node
SYS_SAGE_COMPONENT_TOPOLOGY -> class Topology
|
protected |
Can be used to represent multiple Components with the same properties. By default, it represents only 1 component, and is set to -1.
|
protected |
Contains references to data paths that point to this component.
|
protected |
Contains references to data paths that point from this component.
|
protected |
Numeric ID of the component. There is no requirement for uniqueness of the ID, however it is advised to have unique IDs at least in the realm of parent's children. Some tree search functions, which take the id as a search parameter search for first match, so the user is responsible to manage uniqueness in the realm of the search subtree (or should be aware of the consequences of not doing so). Component's ID is set by the constructor, and is retrieved via int GetId();
|
protected |
Name of the component (as a string).
|
protected |
Contains pointer to the parent component in the component tree. If this component is the root, parent will be NULL.