Line data Source code
1 : /*
2 : * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Martin Rupp
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 :
33 : #include "registry/registry.h"
34 : #include "bridge/bridge.h"
35 : #include "common/profiler/profiler.h"
36 : #include "common/profiler/profile_node.h"
37 : #include "ug.h" // Required for UGOutputProfileStatsOnExit.
38 : #include <string>
39 : #include <sstream>
40 : #include "../util_overloaded.h"
41 : #ifdef UG_CPU_FREQ
42 : #include "common/profiler/freq_adapt.h"
43 : #endif
44 : using namespace std;
45 :
46 : namespace ug
47 : {
48 :
49 0 : static void UpdateProfiler_BridgeImpl(number damping){
50 : PROFILER_UPDATE(damping);
51 0 : }
52 :
53 0 : static void SetShinyCallLoggingMaxFrequency(int maxFreq)
54 : {
55 : #ifdef SHINY_CALL_LOGGING
56 : ug::g_ShinyCallLoggingMaxFreq = maxFreq;
57 : #else
58 : UG_LOG("SHINY CALL LOGGING NOT ENABLED! Enable with 'cmake -DSHINY_CALL_LOGGING=ON ..'")
59 : #endif
60 0 : }
61 :
62 :
63 0 : static void SetFrequency(const std::string& csvFile){
64 : #ifdef UG_CPU_FREQ
65 : FreqAdaptValues::set_freqs(csvFile);
66 : #endif
67 0 : }
68 :
69 :
70 : //void PrintLUA();
71 : namespace bridge
72 : {
73 :
74 :
75 : /// \defgroup profiler_bridge Profiler Bridge
76 : /// \ingroup misc_bridge
77 : /// \{
78 : //////////////////////////////////////////////////////////////////////////////////////////
79 :
80 1 : void RegisterBridge_Profiler(Registry ®, string parentGroup)
81 : {
82 2 : stringstream ss; ss << parentGroup << "/Util/Profiler";
83 : string grp = ss.str();
84 :
85 3 : reg.add_class_<UGProfileNode>("UGProfileNode", grp)
86 : // call tree
87 3 : .add_method("call_tree",
88 : OVERLOADED_CONST_METHOD_PTR(string, UGProfileNode, call_tree, ()),
89 : "string with call tree")
90 4 : .add_method("call_tree",
91 : OVERLOADED_CONST_METHOD_PTR(string, UGProfileNode, call_tree, (double dSkipMarginal)),
92 : "string with call tree",
93 : "dSkipMarginal")
94 :
95 : // self time
96 4 : .add_method("child_self_time_sorted",
97 : OVERLOADED_CONST_METHOD_PTR(string, UGProfileNode, child_self_time_sorted, ()),
98 : "string with sorted childs", "", "childs are sorted by self time")
99 4 : .add_method("child_self_time_sorted",
100 : OVERLOADED_CONST_METHOD_PTR(string, UGProfileNode, child_self_time_sorted, (double dSkipMarginal)),
101 : "string with sorted childs", "dSkipMarginal", "childs are sorted by self time")
102 :
103 : // total time
104 4 : .add_method("total_time_sorted",
105 : OVERLOADED_CONST_METHOD_PTR(string, UGProfileNode, total_time_sorted, ()),
106 : "string with sorted childs", "", "childs are sorted by total time")
107 4 : .add_method("total_time_sorted",
108 : OVERLOADED_CONST_METHOD_PTR(string, UGProfileNode, total_time_sorted, (double dSkipMarginal)),
109 : "string with sorted childs", "dSkipMarginal", "childs are sorted by total time")
110 :
111 :
112 : // self memory
113 4 : .add_method("child_self_memory_sorted",
114 : OVERLOADED_CONST_METHOD_PTR(string, UGProfileNode, child_self_memory_sorted, ()),
115 : "string with sorted childs", "", "childs are sorted by self memory")
116 4 : .add_method("child_self_memory_sorted",
117 : OVERLOADED_CONST_METHOD_PTR(string, UGProfileNode, child_self_memory_sorted, (double dSkipMarginal)),
118 : "string with sorted childs", "dSkipMarginal", "childs are sorted by self memory")
119 :
120 : // total memory
121 4 : .add_method("total_memory_sorted",
122 : OVERLOADED_CONST_METHOD_PTR(string, UGProfileNode, total_memory_sorted, ()),
123 : "string with sorted childs", "", "childs are sorted by total memory")
124 4 : .add_method("total_memory_sorted",
125 : OVERLOADED_CONST_METHOD_PTR(string, UGProfileNode, total_memory_sorted, (double dSkipMarginal)),
126 : "string with sorted childs", "dSkipMarginal", "childs are sorted by total memory")
127 :
128 : // entry count
129 4 : .add_method("entry_count_sorted",
130 : OVERLOADED_CONST_METHOD_PTR(string, UGProfileNode, entry_count_sorted, ()),
131 : "string with sorted childs", "", "childs are sorted by entry count")
132 4 : .add_method("entry_count_sorted",
133 : OVERLOADED_CONST_METHOD_PTR(string, UGProfileNode, entry_count_sorted, (double dSkipMarginal)),
134 : "string with sorted childs", "dSkipMarginal", "childs are sorted by entry count")
135 :
136 : // misc
137 3 : .add_method("get_avg_entry_count", &UGProfileNode::get_avg_entry_count,
138 : "number of entries in this profiler node", "")
139 2 : .add_method("get_avg_self_time_ms", &UGProfileNode::get_avg_self_time_ms,
140 : "time in milliseconds spend in this node excluding subnodes", "")
141 2 : .add_method("get_avg_total_time_ms", &UGProfileNode::get_avg_total_time_ms,
142 : "time in milliseconds spend in this node including subnodes", "")
143 2 : .add_method("is_valid", &UGProfileNode::valid, "true if node has been found", "")
144 :
145 2 : .add_method("groups", &UGProfileNode::groups, "", "")
146 :
147 : ;
148 : /*.add_method("__tostring", &UGProfileNode::tostring, "tostring")
149 : .add_method("__unm", &UGProfileNode::unm, "unm")
150 : .add_method("__add", &UGProfileNode::add, "add");*/
151 :
152 : // reg.add_function("PrintLUA", &PrintLUA, grp);
153 :
154 :
155 : // typedef const UGProfileNode* TT;
156 3 : reg.add_function("GetProfileNode", OVERLOADED_FUNCTION_PTR(const UGProfileNode *, GetProfileNode, (const char*name)),
157 : grp, "a profile node", "name", "if root = null, return");
158 3 : reg.add_function("GetProfileNode", OVERLOADED_FUNCTION_PTR(const UGProfileNode *, GetProfileNode, (const char*name, const UGProfileNode*)),
159 : grp, "a profile node", "name", "if root = null, return");
160 3 : reg.add_function("GetProfilerAvailable", &GetProfilerAvailable, grp,
161 : "true if profiler available");
162 3 : reg.add_function("SetOutputProfileStats", &UGOutputProfileStatsOnExit, grp,
163 : "", "bOutput", "if set to true and profiler available, profile stats are printed at the end of the program. true is default");
164 3 : reg.add_function("WriteProfileData",
165 : OVERLOADED_FUNCTION_PTR(void, WriteProfileDataXML, (const char*)),
166 : grp,
167 : "", "filename|save-dialog|endings=[\"pdxml\"]", "writes a XML-file with profile data viewable with the ShinyProfileViewer. Pick a filename ending with .pdxml");
168 3 : reg.add_function("WriteProfileData",
169 : OVERLOADED_FUNCTION_PTR(void, WriteProfileDataXML, (const char*, int)),
170 : grp,
171 : "", "filename|save-dialog|endings=[\"pdxml\"]", "writes a XML-file with profile data viewable with the ShinyProfileViewer. Pick a filename ending with .pdxml");
172 3 : reg.add_function("WriteCallLog",
173 : OVERLOADED_FUNCTION_PTR(void, WriteCallLog, (const char*)),
174 : grp,
175 : "", "filename|save-dialog|endings=[\"txt\"]", "writes txt file with call log");
176 3 : reg.add_function("WriteCallLog",
177 : OVERLOADED_FUNCTION_PTR(void, WriteCallLog, (const char*, int)),
178 : grp,
179 : "", "filename|save-dialog|endings=[\"txt\"]", "writes txt file with call log");
180 :
181 3 : reg.add_function("UpdateProfiler", &UpdateProfiler_BridgeImpl, grp);
182 :
183 3 : reg.add_function("SetShinyCallLoggingMaxFrequency", &SetShinyCallLoggingMaxFrequency, grp, "", "maxFreq");
184 :
185 3 : reg.add_function("SetFrequency", &SetFrequency, grp, "", "CSV-File");
186 :
187 1 : }
188 :
189 :
190 : // end group profiler_bridge
191 : /// \}
192 :
193 : } // namespace bridge
194 :
195 : } // namespace ug
|