Memory and C++ Debuging at EA - Scott Wardle - CppCon 2015
Memory and C++ Debuging at EA - Scott Wardle - CppCon 2015
1
debugging at Electronic Arts
By Scott Wardle
2 Introduction
Scott Wardle,
20+ years Game Dev
Solving problems through visualization and
drawing pictures
I am also badly dyslexic, so please note spelling
mistakes and inform me later after the
presentation
4 Vocabulary
Polymorphic Allocator
SQLQuery *NewQuery(ICoreAllocator* a) {
return CORE_NEW(a, "sql", MEM_LOW) SQLQuery(a);
}
Calls ~SQLQuery()
not delete!!
11 2005 Organizing Heaps/Arenas
Sub
Static Global Level Temp Time
Level
Medium
Small Size
Large
R S Medium
Small Render 0 SIM0 SIM1 Render 2 SIM3 Render 1
3 2 Large
Categories are a Fragmentation between
way to tags teams is hard. Who to
allocations so you blame when you are
can budget them out of memory?
together.
2005 Better Tracking and Logging
13
Start End of
of time time
Select Time
whole
delta
snapshot
between
of memory
2 times
15 2005 Arena Block View
Green Systems
Yellow selected block
Purple Presentation
Grey Free
Info about
selected
block
16 2005 Stomp Allocator!!
Stomp Allocator – so good it is worth it’s own
slide
Lots of memory, 4k per alloc
Crash!
Page 4KiB
Page 4KiB Alloc
Read Only
Read/Write
512 bytes
(Or not mapped)
No Crash but bad
Use sentinel? Or Flip
2005 Ref Counted Pointers
17
shared_ptr
Sim Render are useful !!
Oh No Player Player
memory but use
leak! unique_ptr
Collision particle or bare pointers
Mesh system for easy life times
18 2005 EASTL
A 2010 version of EASTL is available now from webkit.
Why EASTL
STL allocators are painful to work with
Intrusive containers, Ring Buffers, etc…
Superior readability and performance
Memory is Allocated in empty versions of some STL
objects
Etc…
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4526.pdf
19 EASTL faster for optimized code
Faster
188 tests.
100
71
80
EASTL Even
NUM TESTS
• Faster means 1.3x
60
Slower 107
40
or better. 20
10
0
vc 2015
# Tests EASTL Faster
as quick or slower
20 EASTL MUCH faster for debug code
140
120
NUM TESTS
100
80
60 EASTL Even
40 Slower 19
20 2
0
# Tests EASTL Slower # Tests Even # Tests EASTL Faster
vc 2015 debug
Open sourcing EASTL
21
Macro used to implement STL like types for each large system.
#define EASTLICA_VECTOR( EASTLICA_TYPE,
GET_DEFAULT_ALLOC, ALLOC_NAME )\
template< typename T> class EASTLICA_TYPE : public
EASTLICA::Vector<T>
Level 1
Level 2
37 IO Load profiler (Turbo Tuner)
Bundle is a group of
files that have to be
loaded to move the
Timeline
game to the next
level or sub level.
Bundles
Chunks are blocks of
data that are
steamed in. Like Chunks
movies or music or
terrain in open world
games.
38 IO Load profiler (Turbo Tuner)
Each Printf on the selected channel
gets an event line so you can undersand
when it happened
39 IO Load profiler (Turbo Tuner)
Why do I continue
to load bundle
while playing
40 IO Load profiler (Turbo Tuner)
Hover
Name of
the Bundle
41
Frame rate and Job thread profiler
(Performance Timer)
Each Rectangle is a Frame
The height is the time in ms
of this frame
CPU1
View of
CPUs
and CPU2
Jobs
CPU3
CPU4
CPU5
GPU
Use Memory Investigator for leaks
44
Before After
Memory Categorization
47
big allocs 2M or
greater take the
space
• Rendering
(procedural
textures and
other buffers
used to draw
the scene)
• Content,
meshes,
textures and
entities that
tie these
together
49 Summary
DeltaViewer
Has many views:
TTY Event Timing
IO and Load times
Jobs and threads
Memory changes
We have a lot of work to do to ship the game I am on
(Good thing I have one year left)
50 Summary
EASTL and STL allocators
Hard to track
Use the “if you made it you own it rule”
Use the “this” pointer of allocator as a parameter for your
allocators
EASTLICA
Good at enforcing allocator use for a large group of SEs
Helped with type erasure problems in stl::string and other
classes. MyString does not work with YourString
51 Summary
Games in general
Most memory is used by large allocation
Most memory is mostly content (meshes and
textures) or rendering
There are a large number of small allocations.
Small block allocators, pool systems, slab allocators
are a good idea
Stomp Allocator are great (Use memory map to find
who stomped you…)
52 Questions?