summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorGabriel Corona <gabriel.corona@enst-bretagne.fr>2014-10-28 01:03:19 +0100
committerGabriel Corona <gabriel.corona@enst-bretagne.fr>2014-11-24 23:18:18 +0100
commitcdce5ace256c2304e995aa149e9f8c2d9650b1ec (patch)
treea5e8ea1f3e1965b8f51235689a6246ffaf7e776b /Source/Core
parent60e9301f40601a1a3d6546a37ea71f18a43f9b3b (diff)
Add Linux perf JIT support (/tmp/perf-$pid.map)
'perf' is the standard builtin tool for performance analysis on recent Linux kernel. Its source code is shipped within the kernel repository. 'perf' has basic support for JIT. For each process, it can read a file named /tmp/perf-$PID.map. This file contains mapping from address range to function name in the format: 41187e2a 1a EmuCode_804a33fc with the following entries: 1. beginning of the range (hexadecimal); 2. size of the range (hexadecimal); 3. name of the function. We supply the PowerPC address of the basic block as function name. Usage: DOLPHIN_PERF_DIR=/tmp dolphin-emu & perf record -F99 -p $(pgrep dolphin-emu) --call-graph dwarf perf script | stackcollapse-perf.pl | grep EmuCode__ | flamegraph.pl > profile.svg Issue: perf does not have support for region invalidation. It reads the file in postprocessing. It probably does not work very well if a JIT region is reused for another basic block: wrong results should be expected in this case. Currently, nothing is done to prevent this.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/PowerPC/JitCommon/JitCache.cpp27
-rw-r--r--Source/Core/Core/PowerPC/JitCommon/JitCache.h3
2 files changed, 30 insertions, 0 deletions
diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp
index abcdfcd656..0c680dc020 100644
--- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp
+++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp
@@ -9,6 +9,14 @@
// performance hit, it's not enabled by default, but it's useful for
// locating performance issues.
+#include <cinttypes>
+
+#ifdef _WIN32
+#include <process.h>
+#else
+#include <unistd.h>
+#endif
+
#include "disasm.h"
#include "Common/CommonTypes.h"
@@ -50,6 +58,15 @@ using namespace Gen;
#if defined USE_OPROFILE && USE_OPROFILE
agent = op_open_agent();
#endif
+
+ const char* perf_dir = getenv("DOLPHIN_PERF_DIR");
+ if (perf_dir && perf_dir[0])
+ {
+ std::string filename = StringFromFormat("%s/perf-%d.map",
+ perf_dir, getpid());
+ m_perf_map_file.open(filename, std::ios::trunc);
+ }
+
iCache.fill(JIT_ICACHE_INVALID_BYTE);
iCacheEx.fill(JIT_ICACHE_INVALID_BYTE);
iCacheVMEM.fill(JIT_ICACHE_INVALID_BYTE);
@@ -69,6 +86,9 @@ using namespace Gen;
#ifdef USE_VTUNE
iJIT_NotifyEvent(iJVM_EVENT_TYPE_SHUTDOWN, nullptr);
#endif
+
+ if (m_perf_map_file.is_open())
+ m_perf_map_file.close();
}
// This clears the JIT cache. It's called from JitCache.cpp when the JIT cache
@@ -179,6 +199,13 @@ using namespace Gen;
jmethod.method_name = b.blockName;
iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, (void*)&jmethod);
#endif
+
+ if (m_perf_map_file.is_open())
+ {
+ m_perf_map_file << StringFromFormat(
+ "%" PRIx64 " %x EmuCode_%x\n",
+ (u64)blockCodePointers[block_num], b.codeSize, b.originalAddress);
+ }
}
const u8 **JitBaseBlockCache::GetCodePointers()
diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h
index 0a79344309..d53fa16d43 100644
--- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h
+++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h
@@ -6,6 +6,7 @@
#include <array>
#include <bitset>
+#include <fstream>
#include <map>
#include <memory>
#include <vector>
@@ -119,6 +120,8 @@ class JitBaseBlockCache
bool m_initialized;
+ std::ofstream m_perf_map_file;
+
bool RangeIntersect(int s1, int e1, int s2, int e2) const;
void LinkBlockExits(int i);
void LinkBlock(int i);