MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / to_json

Method to_json

src/plugin/impl/profiler.cpp:143–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141}
142
143std::shared_ptr<json::Object> GraphProfiler::to_json() const {
144 using namespace json;
145 auto dev_prof = Object::make();
146
147 auto visit_json_obj = [](Object& obj, const std::string& key) -> Object& {
148 auto&& v = obj[key];
149 if (!v)
150 v = Object::make();
151 return *static_cast<Object*>(v.get());
152 };
153
154 for (auto&& kern_ev : m_kern_event) {
155 auto&& opr_prof = visit_json_obj(*dev_prof, kern_ev.first.first->id_str());
156 auto comp_node = kern_ev.first.second;
157 auto&& event = kern_ev.second;
158 auto&& start = m_start_of_time->at(comp_node);
159 event.end->host_wait();
160 //! every event needs to be synchronized on the atlas to ensure that the event
161 //! completes ???
162#if MGB_ATLAS
163 event.kern->host_wait();
164 event.start->host_wait();
165#endif
166 opr_prof[comp_node.to_string()] = Object::make({
167 {"start", Number::make(start->elapsed_time_until(*event.start))},
168 {"kern", Number::make(start->elapsed_time_until(*event.kern))},
169 {"end", Number::make(start->elapsed_time_until(*event.end))},
170 });
171 }
172
173 auto host_prof = Object::make();
174 for (auto&& tpair : m_host_time) {
175 auto&& opr_prof = visit_json_obj(*host_prof, tpair.first.first->id_str());
176 auto&& ev = tpair.second;
177 opr_prof[sys::get_thread_name(tpair.first.second)] = Object::make(
178 {{"start", Number::make(ev.start)},
179 {"kern", Number::make(ev.kern)},
180 {"end", Number::make(ev.end)}});
181 }
182
183 auto opr_fp = Object::make();
184 for (auto&& tpair : m_opr_fp_rst) {
185 auto&& opr_fp_item = *static_cast<Object*>(opr_fp.get());
186 opr_fp_item[tpair.first->id_str()] = tpair.second.to_json();
187 }
188
189 auto pf_holder_pair =
190 m_owner_graph->options()
191 .user_data.get_user_data<opr_profile::OprProfileHolder>();
192 mgb_assert(pf_holder_pair.second, "UserData OprProfileHolder not exist.");
193 auto opr_internal_pf = Object::make();
194 if ((pf_holder_pair.first[0]->id2object_map).size()) {
195 for (auto&& pf_pair : pf_holder_pair.first[0]->id2object_map) {
196 auto&& opr_itnl_pf_item = *static_cast<Object*>(opr_internal_pf.get());
197 opr_itnl_pf_item[pf_pair.first->id_str()] = pf_pair.second;
198 }
199 }
200 return Object::make(

Callers 12

compile_and_runFunction · 0.45
run_testFunction · 0.45
on_var_producedMethod · 0.45
to_json_fullMethod · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
test_nestedFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45

Calls 8

host_waitMethod · 0.80
elapsed_time_untilMethod · 0.80
makeFunction · 0.50
getMethod · 0.45
id_strMethod · 0.45
atMethod · 0.45
to_stringMethod · 0.45
sizeMethod · 0.45

Tested by 10

compile_and_runFunction · 0.36
run_testFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36
test_nestedFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36