print mem used
This commit is contained in:
parent
84ca6a6b59
commit
d093936211
5 changed files with 33 additions and 8 deletions
|
@ -8,7 +8,7 @@ Size=1152,1414
|
||||||
|
|
||||||
[Window][main]
|
[Window][main]
|
||||||
Pos=0,0
|
Pos=0,0
|
||||||
Size=1777,680
|
Size=1183,680
|
||||||
|
|
||||||
[Window][Hex View]
|
[Window][Hex View]
|
||||||
Pos=91,62
|
Pos=91,62
|
||||||
|
|
14
src/mem.cpp
14
src/mem.cpp
|
@ -1,7 +1,6 @@
|
||||||
// Mostly taken from the raddebugger -- thanks, Ryan.
|
// Mostly taken from the raddebugger -- thanks, Ryan.
|
||||||
|
|
||||||
#define align_pow2(x, b) (((x) + (b) - 1) & ( ~((b) - 1)))
|
#define align_pow2(x, b) (((x) + (b) - 1) & ( ~((b) - 1)))
|
||||||
#define SLLStackPush_N(f,n,next) ((n)->next=(f), (f)=(n))
|
|
||||||
#define SLLStackPop_N(f,next) ((f)=(f)->next)
|
#define SLLStackPop_N(f,next) ((f)=(f)->next)
|
||||||
|
|
||||||
#ifdef ENABLE_ASAN
|
#ifdef ENABLE_ASAN
|
||||||
|
@ -60,6 +59,16 @@ void arena_release(Arena *arena)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal u64
|
||||||
|
arena_mem_used(Arena *arena)
|
||||||
|
{
|
||||||
|
u64 tot = 0;
|
||||||
|
for (Arena *node = arena->cur, *prev = 0; node; node = prev) {
|
||||||
|
tot += node->pos - node->base_pos;
|
||||||
|
}
|
||||||
|
return tot;
|
||||||
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
u64 arena_huge_push_threshold()
|
u64 arena_huge_push_threshold()
|
||||||
{
|
{
|
||||||
|
@ -86,7 +95,8 @@ void *arena_push_impl(Arena *arena, u64 size)
|
||||||
|
|
||||||
if (new_block) {
|
if (new_block) {
|
||||||
new_block->base_pos = cur->base_pos + cur->res;
|
new_block->base_pos = cur->base_pos + cur->res;
|
||||||
SLLStackPush_N(arena->cur, new_block, prev);
|
new_block->prev = arena->cur;
|
||||||
|
arena->cur = new_block;
|
||||||
|
|
||||||
cur = new_block;
|
cur = new_block;
|
||||||
pos_mem = align_pow2(cur->pos, cur->align);
|
pos_mem = align_pow2(cur->pos, cur->align);
|
||||||
|
|
|
@ -21,6 +21,15 @@ f32 calc_avg_dt_ms(const Delta_Time_Accum &accum)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal
|
||||||
|
String8 to_pretty_size(Arena *arena, u64 bytes)
|
||||||
|
{
|
||||||
|
if (bytes >= GiB(1)) return push_str8f(arena, "%.1f GiB", (f32)bytes / GiB(1));
|
||||||
|
if (bytes >= MiB(1)) return push_str8f(arena, "%.1f MiB", (f32)bytes / MiB(1));
|
||||||
|
if (bytes >= KiB(1)) return push_str8f(arena, "%.1f KiB", (f32)bytes / KiB(1));
|
||||||
|
return push_str8f(arena, "%zu B", bytes);
|
||||||
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
u32 mem_edit_bg_color_fn(const u8 *data, u64 off, const void *user_data)
|
u32 mem_edit_bg_color_fn(const u8 *data, u64 off, const void *user_data)
|
||||||
{
|
{
|
||||||
|
@ -84,19 +93,22 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms)
|
||||||
String8 ntpl_desc = rntuple_description(scratch.arena, app.rntinfo.anchor);
|
String8 ntpl_desc = rntuple_description(scratch.arena, app.rntinfo.anchor);
|
||||||
ImGui::Text("Inspecting RNTuple '%s' (%s)", app.ntpl_name, ntpl_desc.c());
|
ImGui::Text("Inspecting RNTuple '%s' (%s)", app.ntpl_name, ntpl_desc.c());
|
||||||
|
|
||||||
// Draw avg delta time
|
// Draw stats
|
||||||
{
|
{
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
u64 mem_used = arena_mem_used(arena);
|
||||||
f32 avg_dt = calc_avg_dt_ms(app.delta_time_accum);
|
f32 avg_dt = calc_avg_dt_ms(app.delta_time_accum);
|
||||||
String8 dt_txt = push_str8f(scratch.arena, "avg dt: %.1f", avg_dt);
|
|
||||||
|
|
||||||
f32 pos_x = (ImGui::GetCursorPosX() + ImGui::GetColumnWidth() - ImGui::CalcTextSize(dt_txt.c()).x
|
String8 stat_txt = push_str8f(scratch.arena, "mem used: %s | avg dt: %.1f",
|
||||||
|
to_pretty_size(scratch.arena, mem_used), avg_dt);
|
||||||
|
|
||||||
|
f32 pos_x = (ImGui::GetCursorPosX() + ImGui::GetColumnWidth() - ImGui::CalcTextSize(stat_txt.c()).x
|
||||||
- ImGui::GetScrollX() - 2 * ImGui::GetStyle().ItemSpacing.x);
|
- ImGui::GetScrollX() - 2 * ImGui::GetStyle().ItemSpacing.x);
|
||||||
if (pos_x > ImGui::GetCursorPosX())
|
if (pos_x > ImGui::GetCursorPosX())
|
||||||
ImGui::SetCursorPosX(pos_x);
|
ImGui::SetCursorPosX(pos_x);
|
||||||
|
|
||||||
ImGui::Text("%s", dt_txt.c());
|
ImGui::Text("%s", stat_txt.c());
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
|
@ -61,7 +61,6 @@ void app_cleanup(App_State &app)
|
||||||
os_stop_file_watch(app);
|
os_stop_file_watch(app);
|
||||||
os_unmap_file(app.inspected_fmem, app.inspected_file_size);
|
os_unmap_file(app.inspected_fmem, app.inspected_file_size);
|
||||||
if (app.inspected_file) fclose(app.inspected_file);
|
if (app.inspected_file) fclose(app.inspected_file);
|
||||||
app.inspected_file = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
|
|
@ -18,3 +18,7 @@ using i64 = int64_t;
|
||||||
|
|
||||||
#define max(a, b) ((a) > (b)) ? (a) : (b)
|
#define max(a, b) ((a) > (b)) ? (a) : (b)
|
||||||
#define min(a, b) ((a) < (b)) ? (a) : (b)
|
#define min(a, b) ((a) < (b)) ? (a) : (b)
|
||||||
|
|
||||||
|
#define KiB(b) (b * 1024)
|
||||||
|
#define MiB(b) (KiB(b) * 1024)
|
||||||
|
#define GiB(b) (MiB(b) * 1024)
|
||||||
|
|
Loading…
Reference in a new issue