2015-12-06 11:57:54 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2021-09-26 14:54:53 +00:00
|
|
|
* Copyright (C) 2002-2021 PCSX2 Dev Team
|
2015-12-06 11:57:54 +00:00
|
|
|
*
|
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-09-01 20:31:46 +00:00
|
|
|
#include "common/Perf.h"
|
|
|
|
#include "common/Pcsx2Types.h"
|
2021-09-26 14:54:53 +00:00
|
|
|
#include "common/Dependencies.h"
|
2016-11-25 16:46:52 +00:00
|
|
|
#ifdef __unix__
|
2021-09-01 20:31:46 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_VTUNE
|
|
|
|
#include "jitprofiling.h"
|
2016-11-25 16:46:52 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-06 11:57:54 +00:00
|
|
|
//#define ProfileWithPerf
|
|
|
|
#define MERGE_BLOCK_RESULT
|
|
|
|
|
2016-11-25 16:46:52 +00:00
|
|
|
#ifdef ENABLE_VTUNE
|
2016-11-29 21:57:45 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#pragma comment(lib, "jitprofiling.lib")
|
|
|
|
#endif
|
2016-11-25 16:46:52 +00:00
|
|
|
#endif
|
2015-12-06 11:57:54 +00:00
|
|
|
|
|
|
|
namespace Perf
|
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
// Warning object aren't thread safe
|
|
|
|
InfoVector any("");
|
|
|
|
InfoVector ee("EE");
|
|
|
|
InfoVector iop("IOP");
|
|
|
|
InfoVector vu("VU");
|
|
|
|
InfoVector vif("VIF");
|
2015-12-06 11:57:54 +00:00
|
|
|
|
|
|
|
// Perf is only supported on linux
|
2016-11-25 16:46:52 +00:00
|
|
|
#if defined(__linux__) && (defined(ProfileWithPerf) || defined(ENABLE_VTUNE))
|
2015-12-06 11:57:54 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Implementation of the Info object
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
Info::Info(uptr x86, u32 size, const char* symbol)
|
|
|
|
: m_x86(x86)
|
|
|
|
, m_size(size)
|
|
|
|
, m_dynamic(false)
|
|
|
|
{
|
|
|
|
strncpy(m_symbol, symbol, sizeof(m_symbol));
|
|
|
|
}
|
|
|
|
|
|
|
|
Info::Info(uptr x86, u32 size, const char* symbol, u32 pc)
|
|
|
|
: m_x86(x86)
|
|
|
|
, m_size(size)
|
|
|
|
, m_dynamic(true)
|
|
|
|
{
|
|
|
|
snprintf(m_symbol, sizeof(m_symbol), "%s_0x%08x", symbol, pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Info::Print(FILE* fp)
|
|
|
|
{
|
|
|
|
fprintf(fp, "%x %x %s\n", m_x86, m_size, m_symbol);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Implementation of the InfoVector object
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
InfoVector::InfoVector(const char* prefix)
|
|
|
|
{
|
|
|
|
strncpy(m_prefix, prefix, sizeof(m_prefix));
|
2016-12-04 20:47:04 +00:00
|
|
|
#ifdef ENABLE_VTUNE
|
2021-09-06 18:28:26 +00:00
|
|
|
m_vtune_id = iJIT_GetNewMethodID();
|
2016-12-04 20:47:04 +00:00
|
|
|
#else
|
2021-09-06 18:28:26 +00:00
|
|
|
m_vtune_id = 0;
|
2016-12-04 20:47:04 +00:00
|
|
|
#endif
|
2021-09-06 18:28:26 +00:00
|
|
|
}
|
2016-11-12 15:28:37 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void InfoVector::print(FILE* fp)
|
|
|
|
{
|
|
|
|
for (auto&& it : m_v)
|
|
|
|
it.Print(fp);
|
|
|
|
}
|
2016-11-12 15:28:37 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void InfoVector::map(uptr x86, u32 size, const char* symbol)
|
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
// This function is typically used for dispatcher and recompiler.
|
|
|
|
// Dispatchers are on a page and must always be kept.
|
|
|
|
// Recompilers are much bigger (TODO check VIF) and are only
|
|
|
|
// useful when MERGE_BLOCK_RESULT is defined
|
2016-12-04 20:47:04 +00:00
|
|
|
#if defined(ENABLE_VTUNE) || !defined(MERGE_BLOCK_RESULT)
|
2021-09-06 18:28:26 +00:00
|
|
|
u32 max_code_size = 16 * _1kb;
|
2015-12-06 11:57:54 +00:00
|
|
|
#else
|
2021-09-06 18:28:26 +00:00
|
|
|
u32 max_code_size = _1gb;
|
2015-12-06 11:57:54 +00:00
|
|
|
#endif
|
2016-11-25 16:46:52 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (size < max_code_size)
|
|
|
|
{
|
|
|
|
m_v.emplace_back(x86, size, symbol);
|
2016-12-04 20:47:04 +00:00
|
|
|
|
2016-11-25 16:46:52 +00:00
|
|
|
#ifdef ENABLE_VTUNE
|
2021-09-06 18:28:26 +00:00
|
|
|
std::string name = std::string(symbol);
|
2016-11-25 16:46:52 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
iJIT_Method_Load ml;
|
2016-11-25 16:46:52 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
memset(&ml, 0, sizeof(ml));
|
2016-11-25 16:46:52 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
ml.method_id = iJIT_GetNewMethodID();
|
|
|
|
ml.method_name = (char*)name.c_str();
|
|
|
|
ml.method_load_address = (void*)x86;
|
|
|
|
ml.method_size = size;
|
2016-11-25 16:46:52 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, &ml);
|
2016-12-04 20:47:04 +00:00
|
|
|
|
|
|
|
//fprintf(stderr, "mapF %s: %p size %dKB\n", ml.method_name, ml.method_load_address, ml.method_size / 1024u);
|
2016-11-25 16:46:52 +00:00
|
|
|
#endif
|
2021-09-06 18:28:26 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-06 11:57:54 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void InfoVector::map(uptr x86, u32 size, u32 pc)
|
|
|
|
{
|
2015-12-06 11:57:54 +00:00
|
|
|
#ifndef MERGE_BLOCK_RESULT
|
2021-09-06 18:28:26 +00:00
|
|
|
m_v.emplace_back(x86, size, m_prefix, pc);
|
2015-12-06 11:57:54 +00:00
|
|
|
#endif
|
2016-11-25 16:46:52 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_VTUNE
|
2021-09-06 18:28:26 +00:00
|
|
|
iJIT_Method_Load_V2 ml;
|
2016-11-25 16:46:52 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
memset(&ml, 0, sizeof(ml));
|
2016-11-25 16:46:52 +00:00
|
|
|
|
2016-12-04 20:47:04 +00:00
|
|
|
#ifdef MERGE_BLOCK_RESULT
|
2021-09-06 18:28:26 +00:00
|
|
|
ml.method_id = m_vtune_id;
|
|
|
|
ml.method_name = m_prefix;
|
2016-12-04 20:47:04 +00:00
|
|
|
#else
|
2021-09-06 18:28:26 +00:00
|
|
|
std::string name = std::string(m_prefix) + "_" + std::to_string(pc);
|
|
|
|
ml.method_id = iJIT_GetNewMethodID();
|
|
|
|
ml.method_name = (char*)name.c_str();
|
2016-12-04 20:47:04 +00:00
|
|
|
#endif
|
2021-09-06 18:28:26 +00:00
|
|
|
ml.method_load_address = (void*)x86;
|
|
|
|
ml.method_size = size;
|
2016-11-25 16:46:52 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED_V2, &ml);
|
2016-12-04 20:47:04 +00:00
|
|
|
|
|
|
|
//fprintf(stderr, "mapB %s: %p size %d\n", ml.method_name, ml.method_load_address, ml.method_size);
|
2016-11-25 16:46:52 +00:00
|
|
|
#endif
|
2021-09-06 18:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InfoVector::reset()
|
|
|
|
{
|
|
|
|
auto dynamic = std::remove_if(m_v.begin(), m_v.end(), [](Info i) { return i.m_dynamic; });
|
|
|
|
m_v.erase(dynamic, m_v.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Global function
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void dump()
|
|
|
|
{
|
|
|
|
char file[256];
|
|
|
|
snprintf(file, 250, "/tmp/perf-%d.map", getpid());
|
|
|
|
FILE* fp = fopen(file, "w");
|
|
|
|
|
|
|
|
any.print(fp);
|
|
|
|
ee.print(fp);
|
|
|
|
iop.print(fp);
|
|
|
|
vu.print(fp);
|
|
|
|
|
|
|
|
if (fp)
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump_and_reset()
|
|
|
|
{
|
|
|
|
dump();
|
|
|
|
|
|
|
|
any.reset();
|
|
|
|
ee.reset();
|
|
|
|
iop.reset();
|
|
|
|
vu.reset();
|
|
|
|
}
|
2015-12-06 11:57:54 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Dummy implementation
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2015-12-06 11:57:54 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
InfoVector::InfoVector(const char* prefix)
|
|
|
|
: m_vtune_id(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void InfoVector::map(uptr x86, u32 size, const char* symbol) {}
|
|
|
|
void InfoVector::map(uptr x86, u32 size, u32 pc) {}
|
|
|
|
void InfoVector::reset() {}
|
2015-12-06 11:57:54 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void dump() {}
|
|
|
|
void dump_and_reset() {}
|
2015-12-06 11:57:54 +00:00
|
|
|
|
|
|
|
#endif
|
2021-09-06 18:28:26 +00:00
|
|
|
} // namespace Perf
|