SST 12.1.0
Structural Simulation Toolkit
eventHandlerProfileTool.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_EVENTHANDLERPROFILETOOL_H
13#define SST_CORE_PROFILE_EVENTHANDLERPROFILETOOL_H
14
15#include "sst/core/eli/elementinfo.h"
16#include "sst/core/event.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::EventHandlerProfileTool, SST::HandlerProfileToolAPI, Params&)
33
34 SST_ELI_DOCUMENT_PARAMS(
35 { "level", "Level at which to track profile (global, type, component, subcomponent)", "type" },
36 { "track_ports", "Controls whether to track by individual ports", "false" },
37 { "profile_sends", "Controls whether sends are profiled (due to location of profiling point in the code, turning on send profiling will incur relatively high overhead)", "false" },
38 { "profile_receives", "Controls whether receives are profiled", "true" },
39 )
40
41 enum class Profile_Level { Global, Type, Component, Subcomponent };
42
43 EventHandlerProfileTool(const std::string& name, Params& params);
44
45 virtual void eventSent(uintptr_t UNUSED(key), Event* UNUSED(ev)) {}
46
47 bool profileSends() { return profile_sends_; }
48 bool profileReceives() { return profile_receives_; }
49
50protected:
51 std::string getKeyForHandler(const HandlerMetaData& mdata);
52
53 Profile_Level profile_level_;
54 bool track_ports_;
55
56 bool profile_sends_;
57 bool profile_receives_;
58};
59
60
61/**
62 Profile tool that will count the number of times a handler is
63 called
64 */
66{
67 struct event_data_t
68 {
69 uint64_t recv_count;
70 uint64_t send_count;
71
72 event_data_t() : recv_count(0), send_count(0) {}
73 };
74
75public:
76 SST_ELI_REGISTER_PROFILETOOL(
79 "sst",
80 "profile.handler.event.count",
81 SST_ELI_ELEMENT_VERSION(0, 1, 0),
82 "Profiler that will count calls to handler functions"
83 )
84
85 EventHandlerProfileToolCount(const std::string& name, Params& params);
86
88
89 uintptr_t registerHandler(const HandlerMetaData& mdata) override;
90
91 void handlerStart(uintptr_t key) override;
92 void eventSent(uintptr_t UNUSED(key), Event* UNUSED(ev)) override;
93
94 void outputData(FILE* fp) override;
95
96private:
97 std::map<std::string, event_data_t> counts_;
98};
99
100/**
101 Profile tool that will count the number of times a handler is
102 called
103 */
104template <typename T>
106{
107 struct event_data_t
108 {
109 uint64_t recv_time;
110 uint64_t recv_count;
111 uint64_t send_count;
112
113 event_data_t() : recv_time(0), recv_count(0), send_count(0) {}
114 };
115
116public:
117 EventHandlerProfileToolTime(const std::string& name, Params& params);
118
120
121 uintptr_t registerHandler(const HandlerMetaData& mdata) override;
122
123 void handlerStart(uintptr_t UNUSED(key)) override { start_time_ = T::now(); }
124
125 void handlerEnd(uintptr_t key) override
126 {
127 auto total_time = T::now() - start_time_;
128 event_data_t* entry = reinterpret_cast<event_data_t*>(key);
129 entry->recv_time += std::chrono::duration_cast<std::chrono::nanoseconds>(total_time).count();
130 entry->recv_count++;
131 }
132
133 void eventSent(uintptr_t key, Event* UNUSED(ev)) override { reinterpret_cast<event_data_t*>(key)->send_count++; }
134
135 void outputData(FILE* fp) override;
136
137private:
138 typename T::time_point start_time_;
139 std::map<std::string, event_data_t> times_;
140};
141
142} // namespace Profile
143} // namespace SST
144
145#endif // SST_CORE_PROFILE_EVENTHANDLERPROFILETOOL_H
Main component object for the simulation.
Definition: component.h:31
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:35
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: eventHandlerProfileTool.h:66
Profile tool that will count the number of times a handler is called.
Definition: eventHandlerProfileTool.h:106
Definition: eventHandlerProfileTool.h:30