| 103 | } |
| 104 | |
| 105 | void ProfilerOverlay::updateWithFrame(const ProfilerFrame& frame) { |
| 106 | // log::debug("Add new frame (time {}):", frame.totalTime); |
| 107 | // for (auto& s : frame.samples) { |
| 108 | // log::debug("- {}: {}", s.name, s.time); |
| 109 | // } |
| 110 | |
| 111 | m_frames.emplace_back(Instant::now(), frame); |
| 112 | |
| 113 | // keep last 2 seconds of data in the graph |
| 114 | auto cutoff = Instant::now() - Duration::fromSecs(2); |
| 115 | |
| 116 | while (!m_frames.empty()) { |
| 117 | auto& [time, _] = m_frames.front(); |
| 118 | if (time < cutoff) { |
| 119 | m_frames.pop_front(); |
| 120 | } else { |
| 121 | break; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | for (auto& sample : frame.samples) { |
| 126 | if (m_legendNames.insert(sample.name).second) { |
| 127 | this->addNewEntryToLegend(sample.name, sample.color); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | void ProfilerOverlay::addNewEntryToLegend(std::string_view name, cocos2d::ccColor4F color) { |
| 133 | auto container = Build<RowContainer>::create() |
no test coverage detected