60 SST_ELI_DOCUMENT_PARAMS(
61 {
"level",
"Level at which to track profile (global, type, component, subcomponent)",
"type" },
62 {
"track_points",
"Determines whether independent profiling points are tracked",
"true" },
65 enum class Profile_Level { Global, Type,
Component, Subcomponent };
67 ComponentProfileTool(
const std::string& name,
Params& params);
70 virtual uintptr_t registerProfilePoint(
71 const std::string& point, ComponentId_t
id,
const std::string& name,
const std::string& type) = 0;
72 std::string getKeyForCodeSegment(
73 const std::string& point, ComponentId_t
id,
const std::string& name,
const std::string& type);
76 Profile_Level profile_level_;
85class ComponentCodeSegmentProfileTool :
public ComponentProfileTool
87 friend class BaseComponent;
92 ComponentCodeSegmentProfileTool(
const std::string& name,
Params& params);
94 virtual void codeSegmentStart(uintptr_t UNUSED(key)) {}
95 virtual void codeSegmentEnd(uintptr_t UNUSED(key)) {}
103 inline void codeSegmentStart()
105 for (
auto& x : tools ) {
106 x.first->codeSegmentStart(x.second);
109 inline void codeSegmentEnd()
111 for (
auto& x : tools ) {
112 x.first->codeSegmentEnd(x.second);
116 void registerProfilePoint(ComponentCodeSegmentProfileTool* tool,
const std::string& point, ComponentId_t
id,
117 const std::string& name,
const std::string& type)
119 uintptr_t key = tool->registerProfilePoint(point,
id, name, type);
120 tools.push_back(std::make_pair(tool, key));
124 std::vector<std::pair<ComponentCodeSegmentProfileTool*, uintptr_t>> tools;
136 SST_ELI_REGISTER_PROFILETOOL(
140 "profile.component.codesegment.count",
141 SST_ELI_ELEMENT_VERSION(0, 1, 0),
142 "Profiler that will count times through a marked code segment"
149 uintptr_t registerProfilePoint(
150 const std::string& point, ComponentId_t
id,
const std::string& name,
const std::string& type)
override;
152 void codeSegmentStart(uintptr_t key)
override;
157 std::map<std::string, uint64_t> counts_;
165class ComponentCodeSegmentProfileToolTime :
public ComponentCodeSegmentProfileTool
167 struct segment_data_t
179 ComponentCodeSegmentProfileToolTime(
const std::string& name,
Params& params);
181 virtual ~ComponentCodeSegmentProfileToolTime() {}
183 uintptr_t registerProfilePoint(
184 const std::string& point, ComponentId_t
id,
const std::string& name,
const std::string& type)
override;
186 void codeSegmentStart(uintptr_t UNUSED(key))
override { start_time_ = T::now(); }
188 void codeSegmentEnd(uintptr_t key)
override
190 auto total_time = T::now() - start_time_;
191 segment_data_t* entry =
reinterpret_cast<segment_data_t*
>(key);
192 entry->time += std::chrono::duration_cast<std::chrono::nanoseconds>(total_time).count();
199 typename T::time_point start_time_;
200 std::map<std::string, segment_data_t> times_;