SST  15.1.0
StructuralSimulationToolkit
syncProfileTool.h
1 // Copyright 2009-2025 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-2025, 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/sst_types.h"
18 #include "sst/core/ssthandler.h"
19 #include "sst/core/warnmacros.h"
20 
21 #include <chrono>
22 #include <cstdint>
23 #include <map>
24 #include <string>
25 
26 namespace SST::Profile {
27 
28 // Initial version of sync profiling tool. The API is not yet complete.
30 {
31 public:
32  SST_ELI_REGISTER_PROFILETOOL_DERIVED_API(SST::Profile::SyncProfileTool, SST::Profile::ProfileTool, Params&)
33 
34  // Still to enable the level param in the class
35  SST_ELI_DOCUMENT_PARAMS(
36  // { "level", "Level at which to track profile (global, type, component, subcomponent)", "component" },
37  )
38  // enum class Profile_Level { Global, Type, Component, Subcomponent };
39 
40  SyncProfileTool(const std::string& name, Params& params);
41 
42  virtual void syncManagerStart() {}
43  virtual void syncManagerEnd() {}
44 };
45 
46 
47 /**
48  Profile tool that will count the number of times a handler is
49  called
50  */
52 {
53 
54 public:
55  SST_ELI_REGISTER_PROFILETOOL(
58  "sst",
59  "profile.sync.count",
60  SST_ELI_ELEMENT_VERSION(0, 1, 0),
61  "Profiler that will count calls to sync"
62  )
63 
64  SyncProfileToolCount(const std::string& name, Params& params);
65 
66  virtual ~SyncProfileToolCount() {}
67 
68  void syncManagerStart() override;
69 
70  void outputData(FILE* fp) override;
71 
72 private:
73  uint64_t syncmanager_count = 0;
74 };
75 
76 /**
77  Profile tool that will count the number of times a handler is
78  called
79  */
80 template <typename T>
82 {
83 public:
84  SyncProfileToolTime(const std::string& name, Params& params);
85 
86  virtual ~SyncProfileToolTime() {}
87 
88  void syncManagerStart() override { start_time_ = T::now(); }
89 
90  void syncManagerEnd() override
91  {
92  auto total_time = T::now() - start_time_;
93  syncmanager_time += std::chrono::duration_cast<std::chrono::nanoseconds>(total_time).count();
94  syncmanager_count++;
95  }
96 
97  void outputData(FILE* fp) override;
98 
99 private:
100  uint64_t syncmanager_time = 0;
101  uint64_t syncmanager_count = 0;
102 
103  typename T::time_point start_time_;
104 };
105 
106 } // namespace SST::Profile
107 
108 #endif // SST_CORE_PROFILE_SYNCPROFILETOOL_H
Profile tool that will count the number of times a handler is called.
Definition: syncProfileTool.h:81
Definition: syncProfileTool.h:29
Definition: link.h:37
ProfileTool is a class loadable through the factory which allows dynamic addition of profiling capabi...
Definition: profiletool.h:31
Parameter store.
Definition: params.h:63
Profile tool that will count the number of times a handler is called.
Definition: syncProfileTool.h:51