Extended Performance Monitor [stebler]
#1
Extended Performance Monitor [stebler]

This displays the game's built-in (from the EGG library) performance monitor and adds an additional bar to it.

Overview of mkw's main loop:
1. Wait on the video interface to make sure we are at the beginning of a frame.
2. Call SceneManager::draw, which will traverse the game engine's hierarchy and call the draw method of every element, which will send commands to the GPU.
3. While the GPU is processing commands, call SceneManager::calc, which will traverse the game engine's hierarchy the same way and call the calc method of every element, which will update their respective internal state for the next frame.
4. Wait for everything to complete.

What the bars measure:
Red: total frame time.
Green: SceneManager::draw.
Blue: time spent by the GPU.
Pink (custom bar): SceneManager::calc.

WIP decompilation of ProcessMeter: https://github.com/stblr/mkw/commit/868e...2806904e2d

Credits: chadderz, riidefi (documentation), Bean (previous performance monitor code).

Screenshot:
[Image: JCO3mTG.png]

PAL:
040092b8 38600180
c2238a7c 0000000a
3c80802a 60843d60
909e0154 3c80ff50
6084ffff 909e0168
3c804040 909e016c
3c803f80 909e0170
38800000 989e0174
387e0060 389e0158
3d80800a 618cef80
7d8903a6 4e800421
7fc3f378 00000000
c200960c 00000004
80750050 81830048
818c0038 7d8903a6
4e800421 81950000
60000000 00000000
c200962c 00000004
4e800421 80750050
81830048 818c0040
7d8903a6 4e800421
60000000 00000000
c200968c 00000004
4e800421 80750050
81830048 818c0044
7d8903a6 4e800421
60000000 00000000
c2009700 00000004
9bf5006b 80750050
38630154 81830000
818c0010 7d8903a6
4e800421 00000000
c2009764 00000004
80750050 38630154
81830000 818c0014
7d8903a6 4e800421
2c180000 00000000
c20097a4 00000004
4e800421 80750050
81830048 818c003c
7d8903a6 4e800421
60000000 00000000
04238f34 60000000
0423910c 48000120


NTSC-U:
04009278 38600180
c22386f8 0000000a
3c808029 6084f9f8
909e0154 3c80ff50
6084ffff 909e0168
3c804040 909e016c
3c803f80 909e0170
38800000 989e0174
387e0060 389e0158
3d80800a 618ceee0
7d8903a6 4e800421
7fc3f378 00000000
c20095cc 00000004
80750050 81830048
818c0038 7d8903a6
4e800421 81950000
60000000 00000000
c20095ec 00000004
4e800421 80750050
81830048 818c0040
7d8903a6 4e800421
60000000 00000000
c200964c 00000004
4e800421 80750050
81830048 818c0044
7d8903a6 4e800421
60000000 00000000
c20096c0 00000004
9bf5006b 80750050
38630154 81830000
818c0010 7d8903a6
4e800421 00000000
c2009724 00000004
80750050 38630154
81830000 818c0014
7d8903a6 4e800421
2c180000 00000000
c2009764 00000004
4e800421 80750050
81830048 818c003c
7d8903a6 4e800421
60000000 00000000
04238bb0 60000000
04238d88 48000120


NTSC-J:
04009214 38600180
c223899c 0000000a
3c80802a 60843700
909e0154 3c80ff50
6084ffff 909e0168
3c804040 909e016c
3c803f80 909e0170
38800000 989e0174
387e0060 389e0158
3d80800a 618ceea0
7d8903a6 4e800421
7fc3f378 00000000
c2009568 00000004
80750050 81830048
818c0038 7d8903a6
4e800421 81950000
60000000 00000000
c2009588 00000004
4e800421 80750050
81830048 818c0040
7d8903a6 4e800421
60000000 00000000
c20095e8 00000004
4e800421 80750050
81830048 818c0044
7d8903a6 4e800421
60000000 00000000
c200965c 00000004
9bf5006b 80750050
38630154 81830000
818c0010 7d8903a6
4e800421 00000000
c20096c0 00000004
80750050 38630154
81830000 818c0014
7d8903a6 4e800421
2c180000 00000000
c2009700 00000004
4e800421 80750050
81830048 818c003c
7d8903a6 4e800421
60000000 00000000
04238e54 60000000
0423902c 48000120


NTSC-K:
04009408 38600180
c2238df0 0000000a
3c808029 60841d60
909e0154 3c80ff50
6084ffff 909e0168
3c804040 909e016c
3c803f80 909e0170
38800000 989e0174
387e0060 389e0158
3d80800a 618cefe0
7d8903a6 4e800421
7fc3f378 00000000
c2009714 00000004
80750050 81830048
818c0038 7d8903a6
4e800421 81950000
60000000 00000000
c2009734 00000004
4e800421 80750050
81830048 818c0040
7d8903a6 4e800421
60000000 00000000
c2009794 00000004
4e800421 80750050
81830048 818c0044
7d8903a6 4e800421
60000000 00000000
c2009808 00000004
9bf5006b 80750050
38630154 81830000
818c0010 7d8903a6
4e800421 00000000
c200986c 00000004
80750050 38630154
81830000 818c0014
7d8903a6 4e800421
2c180000 00000000
c20098ac 00000004
4e800421 80750050
81830048 818c003c
7d8903a6 4e800421
60000000 00000000
042392a8 60000000
04239480 48000120


Source code:
Code:
# replace at 800092b8 (PAL)

# increase the size of ProcessMeter to store an additional CpuMonitor
li r3, 0x180
Code:
# inject at 80238a7c (PAL)

# set the vtable
.set CpuMonitor_vtable, 0x802a3d60
lis r4, CpuMonitor_vtable@h
ori r4, r4, CpuMonitor_vtable@l
stw r4, 0x154 + 0x0 (r30)

# set the color
.set color, 0xff50ffff # pink: rgba(255, 80, 255, 255)
lis r4, color@h
ori r4, r4, color@l
stw r4, 0x154 + 0x4 + 0x10 (r30)

# set the y position
.set posY, 0x40400000 # 3.0f
lis r4, posY@h
stw r4, 0x154 + 0x4 + 0x14 (r30)

# set the y dimension
.set dimY, 0x3f800000 # 1.0f
lis r4, dimY@h
stw r4, 0x154 + 0x4 + 0x18 (r30)

# set the flags
li r4, 0 # none
stb r4, 0x154 + 0x4 + 0x1c (r30)

# add it to the list
.set List_Append, 0x800aef80
addi r3, r30, 0x60 # the list
addi r4, r30, 0x154 + 0x4 # the bar
lis r12, List_Append@h
ori r12, r12, List_Append@l
mtctr r12
bctrl

mr r3, r30 # original instruction
Code:
# inject at 8000960c (PAL)

# call ProcessMeter::measureBeginFrame after Display::beginFrame
lwz r3, 0x50 (r21)
lwz r12, 0x48 (r3)
lwz r12, 0x38 (r12)
mtctr r12
bctrl

lwz r12, 0x0 (r21) # original instruction
Code:
# inject at 8000962c (PAL)

bctrl # original instruction

# call ProcessMeter::measureBeginRender after Display::beginRender and before SceneManager::draw
lwz r3, 0x50 (r21)
lwz r12, 0x48 (r3)
lwz r12, 0x40 (r12)
mtctr r12
bctrl
Code:
# inject at 8000968c (PAL)

bctrl # original instruction

# call ProcessMeter::measureEndRender after ProcessMeter::draw and before Display::endRender
lwz r3, 0x50 (r21)
lwz r12, 0x48 (r3)
lwz r12, 0x44 (r12)
mtctr r12
bctrl
Code:
# inject at 80009700 (PAL)

stb r31, 0x6b (r21) # original instruction

# start the timer of the custom CPU monitor before SceneManager::calc
lwz r3, 0x50 (r21)
addi r3, r3, 0x154
lwz r12, 0x0 (r3)
lwz r12, 0x10 (r12)
mtctr r12
bctrl
Code:
# inject at 80009764 (PAL)

# stop the timer of the custom CPU monitor after SceneManager::calc
lwz r3, 0x50 (r21)
addi r3, r3, 0x154
lwz r12, 0x0 (r3)
lwz r12, 0x14 (r12)
mtctr r12
bctrl

cmpwi r24, 0x0 # original instruction
Code:
# inject at 800097a4 (PAL)

bctrl # original instruction

# call ProcessMeter::endFrame after Display::endFrame
lwz r3, 0x50 (r21)
lwz r12, 0x48 (r3)
lwz r12, 0x3c (r12)
mtctr r12
bctrl
Code:
# replace at 80238f34 (PAL)

nop # prevent the game from hiding the bars
Code:
# replace at 8023910c (PAL)

b 0x120 # hide the ugly element on the left
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)