MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Add

Method Add

tensorflow/core/profiler/internal/tfprof_code.cc:185–236  ·  view source on GitHub ↗

'node' is the leaf of the displayed trace. It includes all graph nodes created by it. 'location_ids' contains the call stack, from callee to caller. This method adds the statistics of graph nodes created by the python call.

Source from the content-addressed store, hash-verified

183 // This method adds the statistics of graph nodes created by the python
184 // call.
185 void Add(const CodeNode* node, const std::vector<uint64>& location_ids) {
186 // displayed leaf might not be true leaf. Retrieve the true leaves for
187 // stats.
188 std::vector<const CodeNode*> all_leaf = FetchAllLeaf(node);
189 CHECK(!all_leaf.empty()) << node->name();
190
191 for (const CodeNode* cn : all_leaf) {
192 for (auto gn_it : cn->node->graph_nodes()) {
193 const TFGraphNode* gn = gn_it.second;
194 string name = gn->name();
195 // Generate a new trace name, in case the name is taken.
196 while (sample_table_.find(name) != sample_table_.end()) {
197 name += '@';
198 }
199 pprof::Sample* sample_pb = &sample_table_[name];
200 for (uint64 id : location_ids) {
201 sample_pb->mutable_location_id()->Add(id);
202 }
203 pprof::Label* label_pb = sample_pb->mutable_label()->Add();
204 label_pb->set_key(string_table_->GetIndex("graph node:"));
205 label_pb->set_str(string_table_->GetIndex(gn->name()));
206
207 sample_pb->mutable_value()->Add(1);
208 string type = *opts_->select.begin();
209 if (type == kShown[1]) {
210 sample_pb->mutable_value()->Add(gn->exec_micros(node->node->step()));
211 } else if (type == kShown[9]) {
212 sample_pb->mutable_value()->Add(
213 gn->accelerator_exec_micros(node->node->step()));
214 } else if (type == kShown[10]) {
215 sample_pb->mutable_value()->Add(
216 gn->cpu_exec_micros(node->node->step()));
217 } else if (type == kShown[0]) {
218 sample_pb->mutable_value()->Add(
219 gn->requested_bytes(node->node->step()));
220 } else if (type == kShown[11]) {
221 sample_pb->mutable_value()->Add(gn->peak_bytes(node->node->step()));
222 } else if (type == kShown[12]) {
223 sample_pb->mutable_value()->Add(
224 gn->residual_bytes(node->node->step()));
225 } else if (type == kShown[13]) {
226 sample_pb->mutable_value()->Add(gn->output_bytes(node->node->step()));
227 } else if (type == kShown[2]) {
228 sample_pb->mutable_value()->Add(gn->parameters());
229 } else if (type == kShown[3]) {
230 sample_pb->mutable_value()->Add(gn->float_ops(node->node->step()));
231 } else {
232 fprintf(stderr, "pprof doesn't support -select=%s\n", type.c_str());
233 }
234 }
235 }
236 }
237
238 const std::map<string, pprof::Sample>& samples() const {
239 return sample_table_;

Callers 2

AddSampleMethod · 0.45
BuildMethod · 0.45

Calls 15

c_strMethod · 0.80
nameMethod · 0.65
emptyMethod · 0.45
findMethod · 0.45
endMethod · 0.45
GetIndexMethod · 0.45
beginMethod · 0.45
exec_microsMethod · 0.45
stepMethod · 0.45
cpu_exec_microsMethod · 0.45
requested_bytesMethod · 0.45

Tested by

no test coverage detected