Skip to content

Commit

Permalink
Metrics: Added io.MetricsActiveAllocations, moving away from the cros…
Browse files Browse the repository at this point in the history
…s-context global counters than we previously used. (#1565, #1599, #586)
  • Loading branch information
ocornut committed Aug 15, 2018
1 parent 4e33aee commit 8972eba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Other Changes:
- Metrics: Changed io.MetricsActiveWindows to reflect the number of active windows (!= from visible windows), which is useful
for lazy/idle render mechanisms as new windows are typically not visible for one frame.
- Metrics: Added io.MetricsRenderWindow to reflect the number of visible windows.
- Metrics: Added io.MetricsActiveAllocations, moving away from the cross-context global counters than we previously used. (#1565, #1599, #586)
- Demo: Added basic Drag and Drop demo. (#143)
- Demo: Clarified the use of IsItemHovered()/IsItemActive() right after being in the "Active, Focused, Hovered & Focused Tests" section.
- Examples: Tweaked the main.cpp of each example.
Expand Down
12 changes: 7 additions & 5 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ static void SetClipboardTextFn_DefaultImpl(void* user_data, const ch
static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y);

//-----------------------------------------------------------------------------
// Context
// Context and Memory Allocators
//-----------------------------------------------------------------------------

// Current context pointer. Implicitly used by all ImGui functions. Always assumed to be != NULL.
Expand All @@ -960,7 +960,6 @@ static void FreeWrapper(void* ptr, void* user_data) { (void)user_data;
static void* (*GImAllocatorAllocFunc)(size_t size, void* user_data) = MallocWrapper;
static void (*GImAllocatorFreeFunc)(void* ptr, void* user_data) = FreeWrapper;
static void* GImAllocatorUserData = NULL;
static size_t GImAllocatorActiveAllocationsCount = 0;

//-----------------------------------------------------------------------------
// User facing structures
Expand Down Expand Up @@ -2845,13 +2844,16 @@ float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)

void* ImGui::MemAlloc(size_t size)
{
GImAllocatorActiveAllocationsCount++;
if (ImGuiContext* ctx = GImGui)
ctx->IO.MetricsActiveAllocations++;
return GImAllocatorAllocFunc(size, GImAllocatorUserData);
}

void ImGui::MemFree(void* ptr)
{
if (ptr) GImAllocatorActiveAllocationsCount--;
if (ptr)
if (ImGuiContext* ctx = GImGui)
ctx->IO.MetricsActiveAllocations--;
return GImAllocatorFreeFunc(ptr, GImAllocatorUserData);
}

Expand Down Expand Up @@ -14032,7 +14034,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::Text("%d vertices, %d indices (%d triangles)", io.MetricsRenderVertices, io.MetricsRenderIndices, io.MetricsRenderIndices / 3);
ImGui::Text("%d active windows (%d visible)", io.MetricsActiveWindows, io.MetricsRenderWindows);
ImGui::Text("%d allocations", (int)GImAllocatorActiveAllocationsCount);
ImGui::Text("%d allocations", io.MetricsActiveAllocations);
ImGui::Checkbox("Show clipping rectangles when hovering draw commands", &show_draw_cmd_clip_rects);
ImGui::Checkbox("Ctrl shows window begin order", &show_window_begin_order);

Expand Down
1 change: 1 addition & 0 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@ struct ImGuiIO
int MetricsRenderIndices; // Indices output during last call to Render() = number of triangles * 3
int MetricsRenderWindows; // Number of visible windows
int MetricsActiveWindows; // Number of active windows
int MetricsActiveAllocations; // Number of active allocations, updated by MemAlloc/MemFree based on current context. May be off if you have multiple imgui contexts.
ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are invalid (-FLT_MAX,-FLT_MAX), so a disappearing/reappearing mouse won't have a huge delta.

//------------------------------------------------------------------
Expand Down

0 comments on commit 8972eba

Please sign in to comment.