SST 12.1.0
Structural Simulation Toolkit
clockHandlerProfileTool.h
1// Copyright 2009-2022 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-2022, 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/sst_types.h"
18#include "sst/core/ssthandler.h"
19#include "sst/core/warnmacros.h"
20
21#include <chrono>
22#include <map>
23
24namespace SST {
25
26namespace Profile {
27
28
30{
31public:
32 SST_ELI_REGISTER_PROFILETOOL_DERIVED_API(SST::Profile::ClockHandlerProfileTool, SST::HandlerProfileToolAPI, Params&)
33
34 SST_ELI_DOCUMENT_PARAMS(
35 { "level", "Level at which to track profile (global, type, component, subcomponent)", "type" },
36 )
37
38 enum class Profile_Level { Global, Type, Component, Subcomponent };
39
40 ClockHandlerProfileTool(const std::string& name, Params& params);
41
42protected:
43 std::string getKeyForHandler(const HandlerMetaData& mdata);
44
45 Profile_Level profile_level_;
46};
47
48
49/**
50 Profile tool that will count the number of times a handler is
51 called
52 */
54{
55public:
56 SST_ELI_REGISTER_PROFILETOOL(
59 "sst",
60 "profile.handler.clock.count",
61 SST_ELI_ELEMENT_VERSION(0, 1, 0),
62 "Profiler that will count calls to handler functions"
63 )
64
65 ClockHandlerProfileToolCount(const std::string& name, Params& params);
66
68
69 uintptr_t registerHandler(const HandlerMetaData& mdata) override;
70
71 void handlerStart(uintptr_t key) override;
72
73 void outputData(FILE* fp) override;
74
75private:
76 std::map<std::string, uint64_t> counts_;
77};
78
79/**
80 Profile tool that will count the number of times a handler is
81 called
82 */
83template <typename T>
85{
86 struct clock_data_t
87 {
88 uint64_t time;
89 uint64_t count;
90
91 clock_data_t() : time(0), count(0) {}
92 };
93
94public:
95 ClockHandlerProfileToolTime(const std::string& name, Params& params);
96
98
99 uintptr_t registerHandler(const HandlerMetaData& mdata) override;
100
101 void handlerStart(uintptr_t UNUSED(key)) override { start_time_ = T::now(); }
102
103 void handlerEnd(uintptr_t key) override
104 {
105 auto total_time = T::now() - start_time_;
106 clock_data_t* entry = reinterpret_cast<clock_data_t*>(key);
107 entry->time += std::chrono::duration_cast<std::chrono::nanoseconds>(total_time).count();
108 entry->count++;
109 }
110
111 void outputData(FILE* fp) override;
112
113private:
114 typename T::time_point start_time_;
115 std::map<std::string, clock_data_t> times_;
116};
117
118} // namespace Profile
119} // namespace SST
120
121#endif // SST_CORE_PROFILE_CLOCKHANDLERPROFILETOOL_H
Main component object for the simulation.
Definition: component.h:31
Just a tag class for the various metadata that will need to be stored in the simulation object to all...
Definition: ssthandler.h:28
Definition: ssthandler.h:35
Parameter store.
Definition: params.h:56
Profile tool that will count the number of times a handler is called.
Definition: clockHandlerProfileTool.h:54
Profile tool that will count the number of times a handler is called.
Definition: clockHandlerProfileTool.h:85
Definition: clockHandlerProfileTool.h:30