SST 16.0.0
Structural Simulation Toolkit
clockHandlerProfileTool.h
1// Copyright 2009-2026 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2026, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_PROFILE_CLOCKHANDLERPROFILETOOL_H
13#define SST_CORE_PROFILE_CLOCKHANDLERPROFILETOOL_H
14
15#include "sst/core/clock.h"
16#include "sst/core/eli/elementinfo.h"
17#include "sst/core/profile/profiletool.h"
18#include "sst/core/rankInfo.h"
19#include "sst/core/sst_types.h"
20#include "sst/core/ssthandler.h"
21#include "sst/core/warnmacros.h"
22
23#include <chrono>
24#include <cstdint>
25#include <map>
26#include <string>
27
28namespace SST {
29
30namespace Util {
31class DataRecord;
32}
33
34namespace Profile {
35
36class ClockHandlerProfileTool : public ProfileTool, public Clock::HandlerBase::AttachPoint
37{
38public:
39 SST_ELI_REGISTER_PROFILETOOL_DERIVED_API(SST::Profile::ClockHandlerProfileTool, SST::Profile::ProfileTool, Params&)
40
41 SST_ELI_DOCUMENT_PARAMS(
42 { "level", "Level at which to track profile (global, type, component, subcomponent)", "type" },
43 )
44
45 enum class Profile_Level { Global, Type, Component, Subcomponent };
46
47 ClockHandlerProfileTool(const std::string& name, Params& params);
48
49 // Default implementations of attach point functions for profile
50 // tools that don't use them
51 void beforeHandler(uintptr_t UNUSED(key), const Cycle_t& UNUSED(cycle)) override {}
52 void afterHandler(uintptr_t UNUSED(key), const bool& UNUSED(remove)) override {}
53
54protected:
55 std::string getKeyForHandler(const AttachPointMetaData& mdata);
56
57 Profile_Level profile_level_;
58};
59
60
61/**
62 Profile tool that will count the number of times a handler is
63 called
64 */
65class ClockHandlerProfileToolCount : public ClockHandlerProfileTool
66{
67public:
68 SST_ELI_REGISTER_PROFILETOOL(
71 "sst",
72 "profile.handler.clock.count",
73 SST_ELI_ELEMENT_VERSION(0, 1, 0),
74 "Profiler that will count calls to handler functions"
75 )
76
77 ClockHandlerProfileToolCount(const std::string& name, Params& params);
78
80
81 uintptr_t registerHandler(const AttachPointMetaData& mdata) override;
82
83 void beforeHandler(uintptr_t key, const Cycle_t& cycle) override;
84
85 void outputData(SST::Util::DataRecord* record, RankInfo rank) override;
86
87private:
88 std::map<std::string, uint64_t> counts_;
89};
90
91/**
92 Profile tool that will count the number of times a handler is
93 called
94 */
95template <typename T>
96class ClockHandlerProfileToolTime : public ClockHandlerProfileTool
97{
98 struct clock_data_t
99 {
100 uint64_t time;
101 uint64_t count;
102
103 clock_data_t() :
104 time(0),
105 count(0)
106 {}
107 };
108
109public:
110 ClockHandlerProfileToolTime(const std::string& name, Params& params);
111
112 virtual ~ClockHandlerProfileToolTime() {}
113
114 uintptr_t registerHandler(const AttachPointMetaData& mdata) override;
115
116 void beforeHandler(uintptr_t UNUSED(key), const Cycle_t& UNUSED(cycle)) override { start_time_ = T::now(); }
117
118 void afterHandler(uintptr_t key, const bool& UNUSED(remove)) override
119 {
120 auto total_time = T::now() - start_time_;
121 clock_data_t* entry = reinterpret_cast<clock_data_t*>(key);
122 entry->time += std::chrono::duration_cast<std::chrono::nanoseconds>(total_time).count();
123 entry->count++;
124 }
125
126 void outputData(SST::Util::DataRecord* record, RankInfo rank) override;
127
128private:
129 typename T::time_point start_time_;
130 std::map<std::string, clock_data_t> times_;
131};
132
133} // namespace Profile
134} // namespace SST
135
136#endif // SST_CORE_PROFILE_CLOCKHANDLERPROFILETOOL_H
Main component object for the simulation.
Definition component.h:32
Parameter store.
Definition params.h:65
Profile tool that will count the number of times a handler is called.
Definition clockHandlerProfileTool.h:66
Definition clockHandlerProfileTool.h:37
ProfileTool is a class loadable through the factory which allows dynamic addition of profiling capabi...
Definition profiletool.h:38
Definition rankInfo.h:24
Definition perfReporter.h:64
Struct used as a base class for all AttachPoint metadata passed to registration functions.
Definition sst_types.h:201