0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 08:41:02 +08:00

#0 [Core] Minor cosmetic changes

This commit is contained in:
Victor Zarubkin 2018-01-04 17:38:59 +03:00
parent 50cd560722
commit f9a132e9ee
2 changed files with 30 additions and 27 deletions

View File

@ -135,8 +135,7 @@ char KERNEL_LOGGER[] = KERNEL_LOGGER_NAME;
::std::atomic_uint64_t TRACING_END_TIME = ATOMIC_VAR_INIT(~0ULL); ::std::atomic_uint64_t TRACING_END_TIME = ATOMIC_VAR_INIT(~0ULL);
#endif #endif
namespace { /**
/**
* Retrieve the process name of the given process. * Retrieve the process name of the given process.
* *
* This method is NOT thread-safe: the returned string has to be copied somewhere before this * This method is NOT thread-safe: the returned string has to be copied somewhere before this
@ -144,21 +143,24 @@ namespace {
* *
* getProcessName() owns the returned string. * getProcessName() owns the returned string.
* *
* \return a pair of the process name string and the string length. * \param len the process name string length [output].
*
* \return the process name string.
*/ */
std::pair<const char*, std::size_t> getProcessName(HANDLE hProcess) static const char* getProcessName(HANDLE hProcess, std::size_t& len)
{ {
static TCHAR buf[MAX_PATH] = {}; static TCHAR buf[MAX_PATH] = {};
std::size_t len = static_cast<std::size_t>(GetModuleBaseName(hProcess, 0, buf, MAX_PATH)); len = static_cast<std::size_t>(GetModuleBaseName(hProcess, 0, buf, MAX_PATH));
if (len == 0)
return nullptr;
#if UNICODE #if UNICODE
static char charbuf[MAX_PATH] = {}; static char charbuf[MAX_PATH] = {};
std::size_t charbufLength = std::wcstombs(charbuf, buf, len); len = std::wcstombs(charbuf, buf, len);
return std::make_pair(charbuf, charbufLength); return charbuf;
#else #else
return std::make_pair(buf, len); return buf;
#endif #endif
}
} }
namespace profiler { namespace profiler {
@ -263,13 +265,14 @@ namespace profiler {
auto hProc = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ, FALSE, pid); auto hProc = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ, FALSE, pid);
if (hProc != nullptr) 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(" ", 1);
pinfo->name.append(processName.first, processName.second); pinfo->name.append(processName, len);
pinfo->valid = 1; pinfo->valid = 1;
} }

View File

@ -217,7 +217,7 @@ typedef ::std::unordered_map<::profiler::hashed_stdstring, ::profiler::BlockStat
automatically receive statistics update. 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(); auto duration = _current.node->duration();
//StatsMap::key_type key(_current.node->name()); //StatsMap::key_type key(_current.node->name());
@ -272,7 +272,7 @@ automatically receive statistics update.
return stats; 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(); auto duration = _current.node->duration();
CsStatsMap::key_type key(_current.node->name()); 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); _current.per_frame_stats = update_statistics(_stats_map, _current, _current_index, _parent_index, _blocks, false);
for (auto i : _current.children) for (auto i : _current.children)