Merge pull request #1432 from randomstuff/linux-perf
Add Linux perf JIT support (/tmp/perf-$pid.map)
This commit is contained in:
commit
c5a0b6bf50
|
@ -6,6 +6,7 @@ set(SRCS BreakPoints.cpp
|
||||||
GekkoDisassembler.cpp
|
GekkoDisassembler.cpp
|
||||||
Hash.cpp
|
Hash.cpp
|
||||||
IniFile.cpp
|
IniFile.cpp
|
||||||
|
JitRegister.cpp
|
||||||
MathUtil.cpp
|
MathUtil.cpp
|
||||||
MemArena.cpp
|
MemArena.cpp
|
||||||
MemoryUtil.cpp
|
MemoryUtil.cpp
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
<ClInclude Include="GekkoDisassembler.h" />
|
<ClInclude Include="GekkoDisassembler.h" />
|
||||||
<ClInclude Include="Hash.h" />
|
<ClInclude Include="Hash.h" />
|
||||||
<ClInclude Include="IniFile.h" />
|
<ClInclude Include="IniFile.h" />
|
||||||
|
<ClInclude Include="JitRegister.h" />
|
||||||
<ClInclude Include="LinearDiskCache.h" />
|
<ClInclude Include="LinearDiskCache.h" />
|
||||||
<ClInclude Include="MathUtil.h" />
|
<ClInclude Include="MathUtil.h" />
|
||||||
<ClInclude Include="MemArena.h" />
|
<ClInclude Include="MemArena.h" />
|
||||||
|
@ -98,6 +99,7 @@
|
||||||
<ClCompile Include="GekkoDisassembler.cpp" />
|
<ClCompile Include="GekkoDisassembler.cpp" />
|
||||||
<ClCompile Include="Hash.cpp" />
|
<ClCompile Include="Hash.cpp" />
|
||||||
<ClCompile Include="IniFile.cpp" />
|
<ClCompile Include="IniFile.cpp" />
|
||||||
|
<ClCompile Include="JitRegister.cpp" />
|
||||||
<ClCompile Include="MathUtil.cpp" />
|
<ClCompile Include="MathUtil.cpp" />
|
||||||
<ClCompile Include="MemArena.cpp" />
|
<ClCompile Include="MemArena.cpp" />
|
||||||
<ClCompile Include="MemoryUtil.cpp" />
|
<ClCompile Include="MemoryUtil.cpp" />
|
||||||
|
|
|
@ -0,0 +1,115 @@
|
||||||
|
// Copyright 2014 Dolphin Emulator Project
|
||||||
|
// Licensed under GPLv2
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <cinttypes>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "Common/CommonTypes.h"
|
||||||
|
#include "Common/FileUtil.h"
|
||||||
|
#include "Common/JitRegister.h"
|
||||||
|
#include "Common/StringUtil.h"
|
||||||
|
#include "Core/ConfigManager.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <process.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined USE_OPROFILE && USE_OPROFILE
|
||||||
|
#include <opagent.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined USE_VTUNE
|
||||||
|
#include <jitprofiling.h>
|
||||||
|
#pragma comment(lib, "libittnotify.lib")
|
||||||
|
#pragma comment(lib, "jitprofiling.lib")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined USE_OPROFILE && USE_OPROFILE
|
||||||
|
static op_agent_t s_agent = nullptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static File::IOFile s_perf_map_file;
|
||||||
|
|
||||||
|
namespace JitRegister
|
||||||
|
{
|
||||||
|
|
||||||
|
void Init()
|
||||||
|
{
|
||||||
|
#if defined USE_OPROFILE && USE_OPROFILE
|
||||||
|
s_agent = op_open_agent();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const std::string& perf_dir = SConfig::GetInstance().m_LocalCoreStartupParameter.m_perfDir;
|
||||||
|
if (!perf_dir.empty())
|
||||||
|
{
|
||||||
|
std::string filename = StringFromFormat("%s/perf-%d.map", perf_dir.data(), getpid());
|
||||||
|
s_perf_map_file.Open(filename, "w");
|
||||||
|
// Disable buffering in order to avoid missing some mappings
|
||||||
|
// if the event of a crash:
|
||||||
|
std::setvbuf(s_perf_map_file.GetHandle(), NULL, _IONBF, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shutdown()
|
||||||
|
{
|
||||||
|
#if defined USE_OPROFILE && USE_OPROFILE
|
||||||
|
op_close_agent(s_agent);
|
||||||
|
s_agent = nullptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_VTUNE
|
||||||
|
iJIT_NotifyEvent(iJVM_EVENT_TYPE_SHUTDOWN, nullptr);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (s_perf_map_file.IsOpen())
|
||||||
|
s_perf_map_file.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Register(const void* base_address, u32 code_size,
|
||||||
|
const char* name, u32 original_address)
|
||||||
|
{
|
||||||
|
#if !(defined USE_OPROFILE && USE_OPROFILE) && !defined(USE_VTUNE)
|
||||||
|
if (!s_perf_map_file.IsOpen())
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string symbol_name;
|
||||||
|
if (original_address)
|
||||||
|
symbol_name = StringFromFormat("%s_%x", name, original_address);
|
||||||
|
else
|
||||||
|
symbol_name = name;
|
||||||
|
|
||||||
|
#if defined USE_OPROFILE && USE_OPROFILE
|
||||||
|
op_write_native_code(s_agent, symbol_name.data(), (u64)base_address,
|
||||||
|
base_address, code_size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_VTUNE
|
||||||
|
iJIT_Method_Load jmethod = {0};
|
||||||
|
jmethod.method_id = iJIT_GetNewMethodID();
|
||||||
|
jmethod.class_file_name = "";
|
||||||
|
jmethod.source_file_name = __FILE__;
|
||||||
|
jmethod.method_load_address = base_address;
|
||||||
|
jmethod.method_size = code_size;
|
||||||
|
jmethod.line_number_size = 0;
|
||||||
|
jmethod.method_name = symbol_name.data();
|
||||||
|
iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, (void*)&jmethod);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Linux perf /tmp/perf-$pid.map:
|
||||||
|
if (s_perf_map_file.IsOpen())
|
||||||
|
{
|
||||||
|
std::string entry = StringFromFormat(
|
||||||
|
"%" PRIx64 " %x %s\n",
|
||||||
|
(u64)base_address, code_size, symbol_name.data());
|
||||||
|
s_perf_map_file.WriteBytes(entry.data(), entry.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright 2014 Dolphin Emulator Project
|
||||||
|
// Licensed under GPLv2
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace JitRegister
|
||||||
|
{
|
||||||
|
|
||||||
|
void Init();
|
||||||
|
void Shutdown();
|
||||||
|
void Register(const void* base_address, u32 code_size,
|
||||||
|
const char* name, u32 original_address=0);
|
||||||
|
|
||||||
|
}
|
|
@ -249,6 +249,8 @@ struct SCoreStartupParameter
|
||||||
std::string m_strGameIniDefaultRevisionSpecific;
|
std::string m_strGameIniDefaultRevisionSpecific;
|
||||||
std::string m_strGameIniLocal;
|
std::string m_strGameIniLocal;
|
||||||
|
|
||||||
|
std::string m_perfDir;
|
||||||
|
|
||||||
// Constructor just calls LoadDefaults
|
// Constructor just calls LoadDefaults
|
||||||
SCoreStartupParameter();
|
SCoreStartupParameter();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "disasm.h"
|
#include "disasm.h"
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
#include "Common/JitRegister.h"
|
||||||
#include "Common/MemoryUtil.h"
|
#include "Common/MemoryUtil.h"
|
||||||
#include "Core/PowerPC/JitInterface.h"
|
#include "Core/PowerPC/JitInterface.h"
|
||||||
#include "Core/PowerPC/JitCommon/JitBase.h"
|
#include "Core/PowerPC/JitCommon/JitBase.h"
|
||||||
|
@ -20,18 +21,6 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined USE_OPROFILE && USE_OPROFILE
|
|
||||||
#include <opagent.h>
|
|
||||||
|
|
||||||
op_agent_t agent;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined USE_VTUNE
|
|
||||||
#include <jitprofiling.h>
|
|
||||||
#pragma comment(lib, "libittnotify.lib")
|
|
||||||
#pragma comment(lib, "jitprofiling.lib")
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace Gen;
|
using namespace Gen;
|
||||||
|
|
||||||
bool JitBaseBlockCache::IsFull() const
|
bool JitBaseBlockCache::IsFull() const
|
||||||
|
@ -47,9 +36,8 @@ using namespace Gen;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined USE_OPROFILE && USE_OPROFILE
|
JitRegister::Init();
|
||||||
agent = op_open_agent();
|
|
||||||
#endif
|
|
||||||
iCache.fill(JIT_ICACHE_INVALID_BYTE);
|
iCache.fill(JIT_ICACHE_INVALID_BYTE);
|
||||||
iCacheEx.fill(JIT_ICACHE_INVALID_BYTE);
|
iCacheEx.fill(JIT_ICACHE_INVALID_BYTE);
|
||||||
iCacheVMEM.fill(JIT_ICACHE_INVALID_BYTE);
|
iCacheVMEM.fill(JIT_ICACHE_INVALID_BYTE);
|
||||||
|
@ -62,13 +50,8 @@ using namespace Gen;
|
||||||
{
|
{
|
||||||
num_blocks = 0;
|
num_blocks = 0;
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
#if defined USE_OPROFILE && USE_OPROFILE
|
|
||||||
op_close_agent(agent);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_VTUNE
|
JitRegister::Shutdown();
|
||||||
iJIT_NotifyEvent(iJVM_EVENT_TYPE_SHUTDOWN, nullptr);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This clears the JIT cache. It's called from JitCache.cpp when the JIT cache
|
// This clears the JIT cache. It's called from JitCache.cpp when the JIT cache
|
||||||
|
@ -164,27 +147,8 @@ using namespace Gen;
|
||||||
LinkBlockExits(block_num);
|
LinkBlockExits(block_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined USE_OPROFILE && USE_OPROFILE
|
JitRegister::Register(blockCodePointers[block_num], b.codeSize,
|
||||||
char buf[100];
|
"JIT_PPC", b.originalAddress);
|
||||||
sprintf(buf, "EmuCode%x", b.originalAddress);
|
|
||||||
const u8* blockStart = blockCodePointers[block_num];
|
|
||||||
op_write_native_code(agent, buf, (uint64_t)blockStart,
|
|
||||||
blockStart, b.codeSize);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_VTUNE
|
|
||||||
sprintf(b.blockName, "EmuCode_0x%08x", b.originalAddress);
|
|
||||||
|
|
||||||
iJIT_Method_Load jmethod = {0};
|
|
||||||
jmethod.method_id = iJIT_GetNewMethodID();
|
|
||||||
jmethod.class_file_name = "";
|
|
||||||
jmethod.source_file_name = __FILE__;
|
|
||||||
jmethod.method_load_address = (void*)blockCodePointers[block_num];
|
|
||||||
jmethod.method_size = b.codeSize;
|
|
||||||
jmethod.line_number_size = 0;
|
|
||||||
jmethod.method_name = b.blockName;
|
|
||||||
iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, (void*)&jmethod);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const u8 **JitBaseBlockCache::GetCodePointers()
|
const u8 **JitBaseBlockCache::GetCodePointers()
|
||||||
|
|
|
@ -57,10 +57,6 @@ struct JitBlock
|
||||||
u64 ticStart; // for profiling - time.
|
u64 ticStart; // for profiling - time.
|
||||||
u64 ticStop; // for profiling - time.
|
u64 ticStop; // for profiling - time.
|
||||||
u64 ticCounter; // for profiling - time.
|
u64 ticCounter; // for profiling - time.
|
||||||
|
|
||||||
#ifdef USE_VTUNE
|
|
||||||
char blockName[32];
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*CompiledCode)();
|
typedef void (*CompiledCode)();
|
||||||
|
|
|
@ -142,10 +142,12 @@ bool DolphinApp::OnInit()
|
||||||
bool UseLogger = false;
|
bool UseLogger = false;
|
||||||
bool selectVideoBackend = false;
|
bool selectVideoBackend = false;
|
||||||
bool selectAudioEmulation = false;
|
bool selectAudioEmulation = false;
|
||||||
|
bool selectPerfDir = false;
|
||||||
|
|
||||||
wxString videoBackendName;
|
wxString videoBackendName;
|
||||||
wxString audioEmulationName;
|
wxString audioEmulationName;
|
||||||
wxString userPath;
|
wxString userPath;
|
||||||
|
wxString perfDir;
|
||||||
|
|
||||||
#if wxUSE_CMDLINE_PARSER // Parse command lines
|
#if wxUSE_CMDLINE_PARSER // Parse command lines
|
||||||
wxCmdLineEntryDesc cmdLineDesc[] =
|
wxCmdLineEntryDesc cmdLineDesc[] =
|
||||||
|
@ -195,6 +197,11 @@ bool DolphinApp::OnInit()
|
||||||
"User folder path",
|
"User folder path",
|
||||||
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
|
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
wxCMD_LINE_OPTION, "P", "perf_dir",
|
||||||
|
"Directory for Lionux perf perf-$pid.map file",
|
||||||
|
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
|
||||||
|
},
|
||||||
{
|
{
|
||||||
wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0
|
wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0
|
||||||
}
|
}
|
||||||
|
@ -219,6 +226,7 @@ bool DolphinApp::OnInit()
|
||||||
BatchMode = parser.Found("batch");
|
BatchMode = parser.Found("batch");
|
||||||
selectVideoBackend = parser.Found("video_backend", &videoBackendName);
|
selectVideoBackend = parser.Found("video_backend", &videoBackendName);
|
||||||
selectAudioEmulation = parser.Found("audio_emulation", &audioEmulationName);
|
selectAudioEmulation = parser.Found("audio_emulation", &audioEmulationName);
|
||||||
|
selectPerfDir = parser.Found("perf_dir", &perfDir);
|
||||||
playMovie = parser.Found("movie", &movieFile);
|
playMovie = parser.Found("movie", &movieFile);
|
||||||
|
|
||||||
if (parser.Found("user", &userPath))
|
if (parser.Found("user", &userPath))
|
||||||
|
@ -243,6 +251,12 @@ bool DolphinApp::OnInit()
|
||||||
UICommon::CreateDirectories();
|
UICommon::CreateDirectories();
|
||||||
UICommon::Init();
|
UICommon::Init();
|
||||||
|
|
||||||
|
if (selectPerfDir)
|
||||||
|
{
|
||||||
|
SConfig::GetInstance().m_LocalCoreStartupParameter.m_perfDir =
|
||||||
|
WxStrToStr(perfDir);
|
||||||
|
}
|
||||||
|
|
||||||
if (selectVideoBackend && videoBackendName != wxEmptyString)
|
if (selectVideoBackend && videoBackendName != wxEmptyString)
|
||||||
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend =
|
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend =
|
||||||
WxStrToStr(videoBackendName);
|
WxStrToStr(videoBackendName);
|
||||||
|
|
Loading…
Reference in New Issue