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

#0 Simplified some lambdas

This commit is contained in:
Victor Zarubkin 2018-01-29 23:42:18 +03:00
parent 091d5447ce
commit 192ab87e4c
5 changed files with 32 additions and 42 deletions

View File

@ -169,7 +169,7 @@ EASY_CONSTEXPR uint8_t FORCE_ON_FLAG = profiler::FORCE_ON & ~profiler::ON;
const int64_t CPU_FREQUENCY = EASY_CHRONO_CLOCK::period::den / EASY_CHRONO_CLOCK::period::num;
# define TICKS_TO_US(ticks) ticks * 1000000LL / CPU_FREQUENCY
#elif defined(_WIN32)
const decltype(LARGE_INTEGER::QuadPart) CPU_FREQUENCY = ([](){ LARGE_INTEGER freq; QueryPerformanceFrequency(&freq); return freq.QuadPart; })();
const decltype(LARGE_INTEGER::QuadPart) CPU_FREQUENCY = ([]{ LARGE_INTEGER freq; QueryPerformanceFrequency(&freq); return freq.QuadPart; })();
# define TICKS_TO_US(ticks) ticks * 1000000LL / CPU_FREQUENCY
#else
# ifndef __APPLE__
@ -1621,8 +1621,7 @@ void ProfileManager::listen(uint16_t _port)
std::future<uint32_t> dumpingResult;
bool dumping = false;
const auto stopDumping = [this, &dumping, &dumpingResult, &os]
{
const auto stopDumping = [&] {
dumping = false;
m_stopDumping.store(true, std::memory_order_release);
join(dumpingResult);

View File

@ -842,7 +842,7 @@ extern "C" {
auto& per_parent_statistics = parent_statistics[it.first];
per_parent_statistics.clear();
statistics_threads.emplace_back(::std::thread([&per_parent_statistics, &per_frame_statistics, &blocks, &descriptors](::profiler::BlocksTreeRoot& root)
statistics_threads.emplace_back(::std::thread([&] (::profiler::BlocksTreeRoot& _root)
{
//::std::sort(root.sync.begin(), root.sync.end(), [&blocks](::profiler::block_index_t left, ::profiler::block_index_t right)
//{
@ -850,48 +850,48 @@ extern "C" {
//});
::profiler::block_index_t cs_index = 0;
for (auto i : root.children)
for (auto child_index : _root.children)
{
auto& frame = blocks[i];
auto& frame = blocks[child_index];
if (descriptors[frame.node->id()]->type() == ::profiler::BlockType::Block)
++root.frames_number;
++_root.frames_number;
frame.per_parent_stats = update_statistics(per_parent_statistics, frame, i, ~0U, blocks);//, root.thread_id, blocks);
frame.per_parent_stats = update_statistics(per_parent_statistics, frame, child_index, ~0U, blocks);//, root.thread_id, blocks);
per_frame_statistics.clear();
update_statistics_recursive(per_frame_statistics, frame, i, i, blocks);
update_statistics_recursive(per_frame_statistics, frame, child_index, child_index, blocks);
if (cs_index < root.sync.size())
if (cs_index < _root.sync.size())
{
CsStatsMap frame_stats_cs;
do {
auto j = root.sync[cs_index];
auto j = _root.sync[cs_index];
auto& cs = blocks[j];
if (cs.node->end() < frame.node->begin())
continue;
if (cs.node->begin() > frame.node->end())
break;
cs.per_frame_stats = update_statistics(frame_stats_cs, cs, cs_index, i, blocks);
cs.per_frame_stats = update_statistics(frame_stats_cs, cs, cs_index, child_index, blocks);
} while (++cs_index < root.sync.size());
} while (++cs_index < _root.sync.size());
}
if (root.depth < frame.depth)
root.depth = frame.depth;
if (_root.depth < frame.depth)
_root.depth = frame.depth;
root.profiled_time += frame.node->duration();
_root.profiled_time += frame.node->duration();
}
++root.depth;
++_root.depth;
}, ::std::ref(root)));
}
int j = 0, n = static_cast<int>(statistics_threads.size());
for (auto& t : statistics_threads)
for (auto& thread : statistics_threads)
{
t.join();
thread.join();
progress.store(90 + (10 * ++j) / n, ::std::memory_order_release);
}
}

View File

@ -199,13 +199,9 @@ void ArbitraryValuesCollection::collectValues(profiler::thread_id_t _threadId, p
m_jobType = ValuesJob;
if (_valueId == 0)
{
m_worker.enqueue([this, _threadId, _valueName] { collectByName(_threadId, _valueName); }, m_bInterrupt);
}
m_worker.enqueue([=] { collectByName(_threadId, _valueName); }, m_bInterrupt);
else
{
m_worker.enqueue([this, _threadId, _valueId] { collectById(_threadId, _valueId); }, m_bInterrupt);
}
m_worker.enqueue([=] { collectById(_threadId, _valueId); }, m_bInterrupt);
}
void ArbitraryValuesCollection::collectValues(profiler::thread_id_t _threadId, profiler::vin_t _valueId, const char* _valueName, profiler::timestamp_t _beginTime)
@ -220,13 +216,9 @@ void ArbitraryValuesCollection::collectValues(profiler::thread_id_t _threadId, p
m_jobType = ValuesJob | PointsJob;
if (_valueId == 0)
{
m_worker.enqueue([this, _threadId, _valueName] { collectByName(_threadId, _valueName); }, m_bInterrupt);
}
m_worker.enqueue([=] { collectByName(_threadId, _valueName); }, m_bInterrupt);
else
{
m_worker.enqueue([this, _threadId, _valueId] { collectById(_threadId, _valueId); }, m_bInterrupt);
}
m_worker.enqueue([=] { collectById(_threadId, _valueId); }, m_bInterrupt);
}
bool ArbitraryValuesCollection::calculatePoints(profiler::timestamp_t _beginTime)
@ -535,8 +527,7 @@ bool ArbitraryValuesChartItem::updateImage()
const auto bindMode = widget->bindMode();
const auto beginTime = EASY_GLOBALS.begin_time;
const auto autoHeight = EASY_GLOBALS.auto_adjust_chart_height;
m_worker.enqueue([this, rect, scale, left, right, value, window, bindMode, beginTime, autoHeight]
{
m_worker.enqueue([=] {
updateImageAsync(rect, scale, left, right, right - left, value, window, bindMode,
beginTime, autoHeight);
}, m_bReady);

View File

@ -822,8 +822,7 @@ bool GraphicsHistogramItem::updateImage()
const auto frameTime = EASY_GLOBALS.frame_time;
const auto beginTime = EASY_GLOBALS.begin_time;
const auto autoHeight = EASY_GLOBALS.auto_adjust_histogram_height;
m_worker.enqueue([this, rect, regime, scale, left, right, value, window, top, bottom, bindMode, frameTime, beginTime, autoHeight]
{
m_worker.enqueue([=] {
updateImageAsync(rect, regime, scale, left, right, right - left, value, window, top, bottom, bindMode,
frameTime, beginTime, autoHeight);
}, m_bReady);

View File

@ -176,13 +176,14 @@ void TreeWidgetLoader::fillTree(::profiler::timestamp_t& _beginTime, const unsig
const auto decoratedNames = EASY_GLOBALS.use_decorated_thread_name;
const auto hexThreadIds = EASY_GLOBALS.hex_thread_id;
const auto timeUnits = EASY_GLOBALS.time_units;
m_worker.enqueue([this, &_beginTime, _blocksNumber, &_blocksTree, zeroBlocks, decoratedNames, hexThreadIds, timeUnits]
{
setTreeInternal1(_beginTime, _blocksNumber, _blocksTree, zeroBlocks, decoratedNames, hexThreadIds, timeUnits);
const auto beginTime = std::ref(_beginTime);
const auto blocksTree = std::ref(_blocksTree);
m_worker.enqueue([=] {
setTreeInternal1(beginTime, _blocksNumber, blocksTree, zeroBlocks, decoratedNames, hexThreadIds, timeUnits);
}, m_bInterrupt);
}
void TreeWidgetLoader::fillTreeBlocks(const::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _beginTime, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, TreeMode _mode)
void TreeWidgetLoader::fillTreeBlocks(const ::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _beginTime, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, TreeMode _mode)
{
interrupt();
m_mode = _mode;
@ -191,9 +192,9 @@ void TreeWidgetLoader::fillTreeBlocks(const::profiler_gui::TreeBlocks& _blocks,
const auto decoratedNames = EASY_GLOBALS.use_decorated_thread_name;
const auto hexThreadIds = EASY_GLOBALS.hex_thread_id;
const auto timeUnits = EASY_GLOBALS.time_units;
m_worker.enqueue([this, _beginTime, &_blocks, _left, _right, _strict, zeroBlocks, decoratedNames, hexThreadIds, timeUnits]
{
setTreeInternal2(_beginTime, _blocks, _left, _right, _strict, zeroBlocks, decoratedNames, hexThreadIds, timeUnits);
const auto blocks = std::ref(_blocks);
m_worker.enqueue([=] {
setTreeInternal2(_beginTime, blocks, _left, _right, _strict, zeroBlocks, decoratedNames, hexThreadIds, timeUnits);
}, m_bInterrupt);
}