diff --git a/editor/editor_profiler.cpp b/editor/editor_profiler.cpp index f625c69cc0e..27009453143 100644 --- a/editor/editor_profiler.cpp +++ b/editor/editor_profiler.cpp @@ -613,23 +613,35 @@ Vector> EditorProfiler::get_data_as_csv() const { return res; } - // signatures - Vector signatures; - const Vector &categories = frame_metrics[0].categories; - - for (int j = 0; j < categories.size(); j++) { - const EditorProfiler::Metric::Category &c = categories[j]; - signatures.push_back(c.signature); - - for (int k = 0; k < c.items.size(); k++) { - signatures.push_back(c.items[k].signature); + // Different metrics may contain different number of categories. + Set possible_signatures; + for (int i = 0; i < frame_metrics.size(); i++) { + const Metric &m = frame_metrics[i]; + if (!m.valid) { + continue; } + for (Map::Element *E = m.category_ptrs.front(); E; E = E->next()) { + possible_signatures.insert(E->key()); + } + for (Map::Element *E = m.item_ptrs.front(); E; E = E->next()) { + possible_signatures.insert(E->key()); + } + } + + // Generate CSV header and cache indices. + Map sig_map; + Vector signatures; + signatures.resize(possible_signatures.size()); + int sig_index = 0; + for (const Set::Element *E = possible_signatures.front(); E; E = E->next()) { + signatures.write[sig_index] = E->get(); + sig_map[E->get()] = sig_index; + sig_index++; } res.push_back(signatures); // values Vector values; - values.resize(signatures.size()); int index = last_metric; @@ -640,20 +652,23 @@ Vector> EditorProfiler::get_data_as_csv() const { index = 0; } - if (!frame_metrics[index].valid) { + const Metric &m = frame_metrics[index]; + + if (!m.valid) { continue; } - int it = 0; - const Vector &frame_cat = frame_metrics[index].categories; - for (int j = 0; j < frame_cat.size(); j++) { - const EditorProfiler::Metric::Category &c = frame_cat[j]; - values.write[it++] = String::num_real(c.total_time); + // Don't keep old values since there may be empty cells. + values.clear(); + values.resize(possible_signatures.size()); - for (int k = 0; k < c.items.size(); k++) { - values.write[it++] = String::num_real(c.items[k].total); - } + for (Map::Element *E = m.category_ptrs.front(); E; E = E->next()) { + values.write[sig_map[E->key()]] = String::num_real(E->value()->total_time); } + for (Map::Element *E = m.item_ptrs.front(); E; E = E->next()) { + values.write[sig_map[E->key()]] = String::num_real(E->value()->total); + } + res.push_back(values); }