| 102 | new ::tensorflow::StatsCalculator(GetProfileSummarizerOptions())) {} |
| 103 | |
| 104 | void ProfileSummarizer::ProcessProfiles( |
| 105 | const std::vector<const ProfileEvent*>& profile_stats, |
| 106 | const tflite::Interpreter& interpreter) { |
| 107 | std::vector<const ProfileEvent*> events; |
| 108 | std::copy_if(profile_stats.begin(), profile_stats.end(), |
| 109 | std::back_inserter(events), [](const ProfileEvent* e) { |
| 110 | return e->event_type == |
| 111 | ProfileEvent::EventType::OPERATOR_INVOKE_EVENT && |
| 112 | e->end_timestamp_us >= e->begin_timestamp_us; |
| 113 | }); |
| 114 | // Sort with begin_time. |
| 115 | std::sort(events.begin(), events.end(), |
| 116 | [](const ProfileEvent* const& a, const ProfileEvent* const& b) { |
| 117 | return a->begin_timestamp_us < b->begin_timestamp_us; |
| 118 | }); |
| 119 | if (events.empty()) { |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | int64_t base_start_us = events[0]->begin_timestamp_us; |
| 124 | int node_num = 0; |
| 125 | int64_t curr_total_us = 0; |
| 126 | auto tag_string = [](const string& s, const string& t) { |
| 127 | return t == "OpInvoke" ? s : s + "/" + t; |
| 128 | }; |
| 129 | for (auto event : events) { |
| 130 | auto op_details = GetOperatorDetails(interpreter, event->event_metadata); |
| 131 | auto node_name = ToString(op_details.outputs); |
| 132 | int64_t start_us = event->begin_timestamp_us - base_start_us; |
| 133 | int64_t node_exec_time = |
| 134 | event->end_timestamp_us - event->begin_timestamp_us; |
| 135 | stats_calculator_->AddNodeStats(tag_string(node_name, event->tag), |
| 136 | tag_string(op_details.name, event->tag), |
| 137 | node_num, start_us, node_exec_time, |
| 138 | 0 /*memory */); |
| 139 | |
| 140 | curr_total_us += node_exec_time; |
| 141 | ++node_num; |
| 142 | } |
| 143 | stats_calculator_->UpdateRunTotalUs(curr_total_us); |
| 144 | } |
| 145 | } // namespace profiling |
| 146 | } // namespace tflite |