mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-26 08:01:51 +08:00
#0 [Core] Minor cosmetic changes
This commit is contained in:
parent
50cd560722
commit
f9a132e9ee
@ -135,30 +135,32 @@ char KERNEL_LOGGER[] = KERNEL_LOGGER_NAME;
|
||||
::std::atomic_uint64_t TRACING_END_TIME = ATOMIC_VAR_INIT(~0ULL);
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Retrieve the process name of the given process.
|
||||
*
|
||||
* This method is NOT thread-safe: the returned string has to be copied somewhere before this
|
||||
* method can be used by another thread or call.
|
||||
*
|
||||
* getProcessName() owns the returned string.
|
||||
*
|
||||
* \return a pair of the process name string and the string length.
|
||||
*/
|
||||
std::pair<const char*, std::size_t> getProcessName(HANDLE hProcess)
|
||||
{
|
||||
static TCHAR buf[MAX_PATH] = {};
|
||||
std::size_t len = static_cast<std::size_t>(GetModuleBaseName(hProcess, 0, buf, MAX_PATH));
|
||||
/**
|
||||
* Retrieve the process name of the given process.
|
||||
*
|
||||
* This method is NOT thread-safe: the returned string has to be copied somewhere before this
|
||||
* method can be used by another thread or call.
|
||||
*
|
||||
* getProcessName() owns the returned string.
|
||||
*
|
||||
* \param len the process name string length [output].
|
||||
*
|
||||
* \return the process name string.
|
||||
*/
|
||||
static const char* getProcessName(HANDLE hProcess, std::size_t& len)
|
||||
{
|
||||
static TCHAR buf[MAX_PATH] = {};
|
||||
len = static_cast<std::size_t>(GetModuleBaseName(hProcess, 0, buf, MAX_PATH));
|
||||
if (len == 0)
|
||||
return nullptr;
|
||||
|
||||
#if UNICODE
|
||||
static char charbuf[MAX_PATH] = {};
|
||||
std::size_t charbufLength = std::wcstombs(charbuf, buf, len);
|
||||
return std::make_pair(charbuf, charbufLength);
|
||||
static char charbuf[MAX_PATH] = {};
|
||||
len = std::wcstombs(charbuf, buf, len);
|
||||
return charbuf;
|
||||
#else
|
||||
return std::make_pair(buf, len);
|
||||
return buf;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
namespace profiler {
|
||||
@ -263,13 +265,14 @@ namespace profiler {
|
||||
auto hProc = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ, FALSE, pid);
|
||||
if (hProc != nullptr)
|
||||
{
|
||||
const auto& processName = getProcessName(hProc); // Using thread-unsafe method is safe because processTraceEvent() is called from one thread
|
||||
std::size_t len = 0;
|
||||
auto processName = getProcessName(hProc, len); // Using thread-unsafe method is safe because processTraceEvent() is called from one thread
|
||||
|
||||
if (processName.second != 0)
|
||||
if (len != 0)
|
||||
{
|
||||
pinfo->name.reserve(pinfo->name.size() + 2 + processName.second);
|
||||
pinfo->name.reserve(pinfo->name.size() + 2 + len);
|
||||
pinfo->name.append(" ", 1);
|
||||
pinfo->name.append(processName.first, processName.second);
|
||||
pinfo->name.append(processName, len);
|
||||
pinfo->valid = 1;
|
||||
}
|
||||
|
||||
|
@ -217,7 +217,7 @@ typedef ::std::unordered_map<::profiler::hashed_stdstring, ::profiler::BlockStat
|
||||
automatically receive statistics update.
|
||||
|
||||
*/
|
||||
::profiler::BlockStatistics* update_statistics(StatsMap& _stats_map, const ::profiler::BlocksTree& _current, ::profiler::block_index_t _current_index, ::profiler::block_index_t _parent_index, const ::profiler::blocks_t& _blocks, bool _calculate_children = true)
|
||||
static ::profiler::BlockStatistics* update_statistics(StatsMap& _stats_map, const ::profiler::BlocksTree& _current, ::profiler::block_index_t _current_index, ::profiler::block_index_t _parent_index, const ::profiler::blocks_t& _blocks, bool _calculate_children = true)
|
||||
{
|
||||
auto duration = _current.node->duration();
|
||||
//StatsMap::key_type key(_current.node->name());
|
||||
@ -272,7 +272,7 @@ automatically receive statistics update.
|
||||
return stats;
|
||||
}
|
||||
|
||||
::profiler::BlockStatistics* update_statistics(CsStatsMap& _stats_map, const ::profiler::BlocksTree& _current, ::profiler::block_index_t _current_index, ::profiler::block_index_t _parent_index, const ::profiler::blocks_t& _blocks, bool _calculate_children = true)
|
||||
static ::profiler::BlockStatistics* update_statistics(CsStatsMap& _stats_map, const ::profiler::BlocksTree& _current, ::profiler::block_index_t _current_index, ::profiler::block_index_t _parent_index, const ::profiler::blocks_t& _blocks, bool _calculate_children = true)
|
||||
{
|
||||
auto duration = _current.node->duration();
|
||||
CsStatsMap::key_type key(_current.node->name());
|
||||
@ -327,7 +327,7 @@ automatically receive statistics update.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void update_statistics_recursive(StatsMap& _stats_map, ::profiler::BlocksTree& _current, ::profiler::block_index_t _current_index, ::profiler::block_index_t _parent_index, ::profiler::blocks_t& _blocks)
|
||||
static void update_statistics_recursive(StatsMap& _stats_map, ::profiler::BlocksTree& _current, ::profiler::block_index_t _current_index, ::profiler::block_index_t _parent_index, ::profiler::blocks_t& _blocks)
|
||||
{
|
||||
_current.per_frame_stats = update_statistics(_stats_map, _current, _current_index, _parent_index, _blocks, false);
|
||||
for (auto i : _current.children)
|
||||
|
Loading…
x
Reference in New Issue
Block a user