//----------------------------------------------------------------------- OverlayElement* Profiler::createTextArea(const String& name, Real width, Real height, Real top, Real left, uint fontSize, const String& caption, bool show) { OverlayElement* textArea = OverlayManager::getSingleton().createOverlayElement("TextArea", name); textArea->setMetricsMode(GMM_PIXELS); textArea->setWidth(width); textArea->setHeight(height); textArea->setTop(top); textArea->setLeft(left); textArea->setParameter("font_name", "BlueHighway"); textArea->setParameter("char_height", StringConverter::toString(fontSize)); textArea->setCaption(caption); textArea->setParameter("colour_top", "1 1 1"); textArea->setParameter("colour_bottom", "1 1 1"); if (show) { textArea->show(); } else { textArea->hide(); } return textArea; }
//----------------------------------------------------------------------- OverlayElement* OverlayProfileSessionListener::createPanel(const String& name, Real width, Real height, Real top, Real left, const String& materialName, bool show) { OverlayElement* panel = OverlayManager::getSingleton().createOverlayElement("Panel", name); panel->setMetricsMode(GMM_PIXELS); panel->setWidth(width); panel->setHeight(height); panel->setTop(top); panel->setLeft(left); panel->setMaterialName(materialName); if (show) { panel->show(); } else { panel->hide(); } return panel; }
//----------------------------------------------------------------------- void Profiler::displayResults() { if (!mEnabled) { return; } // if its time to update the display if (!(mCurrentFrame % mUpdateDisplayFrequency)) { ProfileHistoryList::iterator iter; ProfileBarList::iterator bIter; OverlayElement* g; Real newGuiHeight = mGuiHeight; int profileCount = 0; Real maxTimeMillisecs = (Real)mMaxTotalFrameTime / 1000.0f; // go through each profile and display it for (iter = mProfileHistory.begin(), bIter = mProfileBars.begin(); iter != mProfileHistory.end() && bIter != mProfileBars.end(); ++iter, ++bIter) { // display the profile's name and the number of times it was called in a frame g = *bIter; g->show(); g->setCaption(String((*iter).name + " (" + StringConverter::toString((*iter).numCallsThisFrame) + ")")); g->setLeft(10 + (*iter).hierarchicalLvl * 15.0f); // display the main bar that show the percentage of the frame time that this // profile has taken bIter++; g = *bIter; g->show(); // most of this junk has been set before, but we do this to get around a weird // Ogre gui issue (bug?) g->setMetricsMode(GMM_PIXELS); g->setHeight(mBarHeight); if (mDisplayMode == DISPLAY_PERCENTAGE) g->setWidth(((*iter).currentTimePercent) * mGuiWidth); else g->setWidth(((*iter).currentTimeMillisecs / maxTimeMillisecs) * mGuiWidth); g->setLeft(mGuiWidth); g->setTop(mGuiBorderWidth + profileCount * (mBarHeight + mBarSpacing)); // display line to indicate the minimum frame time for this profile bIter++; g = *bIter; g->show(); if (mDisplayMode == DISPLAY_PERCENTAGE) g->setLeft(mBarIndent + (*iter).minTimePercent * mGuiWidth); else g->setLeft(mBarIndent + ((*iter).minTimeMillisecs / maxTimeMillisecs) * mGuiWidth); // display line to indicate the maximum frame time for this profile bIter++; g = *bIter; g->show(); if (mDisplayMode == DISPLAY_PERCENTAGE) g->setLeft(mBarIndent + (*iter).maxTimePercent * mGuiWidth); else g->setLeft(mBarIndent + ((*iter).maxTimeMillisecs / maxTimeMillisecs) * mGuiWidth); // display line to indicate the average frame time for this profile bIter++; g = *bIter; g->show(); if ((*iter).totalCalls != 0) if (mDisplayMode == DISPLAY_PERCENTAGE) g->setLeft(mBarIndent + ((*iter).totalTimePercent / (*iter).totalCalls) * mGuiWidth); else g->setLeft(mBarIndent + (((*iter).totalTimeMillisecs / (*iter).totalCalls) / maxTimeMillisecs) * mGuiWidth); else g->setLeft(mBarIndent); // display text bIter++; g = *bIter; g->show(); if (mDisplayMode == DISPLAY_PERCENTAGE) { g->setLeft(mBarIndent + (*iter).currentTimePercent * mGuiWidth + 2); g->setCaption(StringConverter::toString((*iter).currentTimePercent * 100.0f, 3, 3) + "%"); } else { g->setLeft(mBarIndent + ((*iter).currentTimeMillisecs / maxTimeMillisecs) * mGuiWidth + 2); g->setCaption(StringConverter::toString((*iter).currentTimeMillisecs, 3, 3) + "ms"); } // we set the height of the display with respect to the number of profiles displayed newGuiHeight += mBarHeight + mBarSpacing; profileCount++; } // set the main display dimensions mProfileGui->setMetricsMode(GMM_PIXELS); mProfileGui->setHeight(newGuiHeight); mProfileGui->setWidth(mGuiWidth * 2 + 15); mProfileGui->setTop(5); mProfileGui->setLeft(5); // we hide all the remaining pre-created bars for (; bIter != mProfileBars.end(); ++bIter) { (*bIter)->hide(); } } mCurrentFrame++; }
//----------------------------------------------------------------------- void OverlayProfileSessionListener::displayResults(ProfileInstance* instance, ProfileBarList::const_iterator& bIter, Real& maxTimeMillisecs, Real& newGuiHeight, int& profileCount) { OverlayElement* g; // display the profile's name and the number of times it was called in a frame g = *bIter; ++bIter; g->show(); g->setCaption(String(instance->name + " (" + StringConverter::toString(instance->history.numCallsThisFrame) + ")")); g->setLeft(10 + instance->hierarchicalLvl * 15.0f); // display the main bar that show the percentage of the frame time that this // profile has taken g = *bIter; ++bIter; g->show(); // most of this junk has been set before, but we do this to get around a weird // Ogre gui issue (bug?) g->setMetricsMode(GMM_PIXELS); g->setHeight(mBarHeight); if (mDisplayMode == DISPLAY_PERCENTAGE) g->setWidth( (instance->history.currentTimePercent) * mGuiWidth); else g->setWidth( (instance->history.currentTimeMillisecs / maxTimeMillisecs) * mGuiWidth); g->setLeft(mGuiWidth); g->setTop(mGuiBorderWidth + profileCount * (mBarHeight + mBarSpacing)); // display line to indicate the minimum frame time for this profile g = *bIter; ++bIter; g->show(); if(mDisplayMode == DISPLAY_PERCENTAGE) g->setLeft(mBarIndent + instance->history.minTimePercent * mGuiWidth); else g->setLeft(mBarIndent + (instance->history.minTimeMillisecs / maxTimeMillisecs) * mGuiWidth); // display line to indicate the maximum frame time for this profile g = *bIter; ++bIter; g->show(); if(mDisplayMode == DISPLAY_PERCENTAGE) g->setLeft(mBarIndent + instance->history.maxTimePercent * mGuiWidth); else g->setLeft(mBarIndent + (instance->history.maxTimeMillisecs / maxTimeMillisecs) * mGuiWidth); // display line to indicate the average frame time for this profile g = *bIter; ++bIter; g->show(); if(instance->history.totalCalls != 0) { if (mDisplayMode == DISPLAY_PERCENTAGE) g->setLeft(mBarIndent + (instance->history.totalTimePercent / instance->history.totalCalls) * mGuiWidth); else g->setLeft(mBarIndent + ((instance->history.totalTimeMillisecs / instance->history.totalCalls) / maxTimeMillisecs) * mGuiWidth); } else g->setLeft(mBarIndent); // display text g = *bIter; ++bIter; g->show(); if (mDisplayMode == DISPLAY_PERCENTAGE) { g->setLeft(mBarIndent + instance->history.currentTimePercent * mGuiWidth + 2); g->setCaption(StringConverter::toString(instance->history.currentTimePercent * 100.0f, 3, 3) + "%"); } else { g->setLeft(mBarIndent + (instance->history.currentTimeMillisecs / maxTimeMillisecs) * mGuiWidth + 2); g->setCaption(StringConverter::toString(instance->history.currentTimeMillisecs, 3, 3) + "ms"); } // we set the height of the display with respect to the number of profiles displayed newGuiHeight += mBarHeight + mBarSpacing; ++profileCount; // display children ProfileInstance::ProfileChildren::const_iterator it = instance->children.begin(), endit = instance->children.end(); for(;it != endit; ++it) { ProfileInstance* child = it->second; displayResults(child, bIter, maxTimeMillisecs, newGuiHeight, profileCount); } }