SST 16.0.0
Structural Simulation Toolkit
syncProfileTool.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_SYNCPROFILETOOL_H
13#define SST_CORE_PROFILE_SYNCPROFILETOOL_H
14
15#include "sst/core/eli/elementinfo.h"
16#include "sst/core/profile/profiletool.h"
17#include "sst/core/rankInfo.h"
18#include "sst/core/sst_types.h"
19#include "sst/core/ssthandler.h"
20#include "sst/core/warnmacros.h"
21
22#include <chrono>
23#include <cstddef>
24#include <cstdint>
25#include <map>
26#include <string>
27#include <vector>
28
29namespace SST::Util {
30class DataRecord;
31}
32
33namespace SST::Profile {
34
35// Initial version of sync profiling tool. The API is not yet complete.
37{
38public:
39 SST_ELI_REGISTER_PROFILETOOL_DERIVED_API(SST::Profile::SyncProfileTool, SST::Profile::ProfileTool, Params&)
40
41 // Still to enable the level param in the class
42 SST_ELI_DOCUMENT_PARAMS(
43 // { "level", "Level at which to track profile (global, type, component, subcomponent)", "component" },
44 )
45 // enum class Profile_Level { Global, Type, Component, Subcomponent };
46
47 SyncProfileTool(const std::string& name, Params& params);
48
49 virtual void syncManagerStart(bool UNUSED(ranksync)) {}
50 virtual void syncManagerEnd() {}
51
52 virtual void updateSyncSize(size_t UNUSED(bytes), size_t UNUSED(events)) {}
53};
54
55
56/**
57 Profile tool that will count the number of times a handler is
58 called
59 */
61{
62
63public:
64 SST_ELI_REGISTER_PROFILETOOL(
67 "sst",
68 "profile.sync.count",
69 SST_ELI_ELEMENT_VERSION(0, 1, 0),
70 "Profiler that will count calls to sync"
71 )
72
73 SyncProfileToolCount(const std::string& name, Params& params);
74
75 virtual ~SyncProfileToolCount() {}
76
77 void syncManagerStart(bool ranksync) override;
78
79 void updateSyncSize(size_t bytes, size_t events) override;
80
81 void outputData(SST::Util::DataRecord* record, RankInfo rank) override;
82
83private:
84 uint64_t syncmanager_count = 0;
85 uint64_t threadsync_count_ = 0;
86 uint64_t events_exchanged_ = 0;
87 uint64_t bytes_exchanged_ = 0;
88};
89
90/**
91 Profile tool that will count the number of times a handler is
92 called
93 */
94template <typename T>
95class SyncProfileToolTime : public SyncProfileTool
96{
97public:
98 SyncProfileToolTime(const std::string& name, Params& params);
99
100 virtual ~SyncProfileToolTime() {}
101
102 void syncManagerStart(bool ranksync) override
103 {
104 start_time_ = T::now();
105 rank_sync_ = ranksync;
106 }
107
108 void syncManagerEnd() override
109 {
110 auto total_time = T::now() - start_time_;
111
112 if ( !rank_sync_ ) {
113 threadsync_count++;
114 threadsync_time += std::chrono::duration_cast<std::chrono::nanoseconds>(total_time).count();
115 }
116 else {
117 syncmanager_time += std::chrono::duration_cast<std::chrono::nanoseconds>(total_time).count();
118 syncmanager_count++;
119 }
120 }
121
122 void updateSyncSize(size_t bytes, size_t events) override
123 {
124 bytes_exchanged_ += bytes;
125 events_exchanged_ += events;
126 }
127
128 void outputData(SST::Util::DataRecord* record, RankInfo rank) override;
129
130private:
131 uint64_t syncmanager_time = 0;
132 uint64_t syncmanager_count = 0;
133 uint64_t threadsync_count = 0;
134 uint64_t threadsync_time = 0;
135 uint64_t events_exchanged_ = 0;
136 uint64_t bytes_exchanged_ = 0;
137 bool rank_sync_ = false;
138
139 typename T::time_point start_time_;
140};
141
142// Class used to hold the list of profile tools installed in the SyncManager
143// Here so that it can be used by multiple classes throughout the sync objects
144class SyncProfileToolList
145{
146public:
147 SyncProfileToolList() = default;
148
149 void syncManagerStart(bool ranksync)
150 {
151 for ( auto* x : tools )
152 x->syncManagerStart(ranksync);
153 }
154
155 void syncManagerEnd()
156 {
157 for ( auto* x : tools )
158 x->syncManagerEnd();
159 }
160
161 void updateSyncSize(size_t bytes, size_t events)
162 {
163 for ( auto* x : tools )
164 x->updateSyncSize(bytes, events);
165 }
166
167 /**
168 Adds a profile tool the the list and registers this handler
169 with the profile tool
170 */
171 void addProfileTool(Profile::SyncProfileTool* tool) { tools.push_back(tool); }
172
173private:
174 std::vector<Profile::SyncProfileTool*> tools;
175};
176
177} // namespace SST::Profile
178
179#endif // SST_CORE_PROFILE_SYNCPROFILETOOL_H
Parameter store.
Definition params.h:65
ProfileTool is a class loadable through the factory which allows dynamic addition of profiling capabi...
Definition profiletool.h:38
Profile tool that will count the number of times a handler is called.
Definition syncProfileTool.h:61
void addProfileTool(Profile::SyncProfileTool *tool)
Adds a profile tool the the list and registers this handler with the profile tool.
Definition syncProfileTool.h:171
Definition syncProfileTool.h:37
Definition rankInfo.h:24
Definition perfReporter.h:64