}
const PhaseOption &option() const { return _option; }
- const MemoryPoller &mem_poll() const { return _mem_poll; }
+ const MemoryPoller &mem_poll() const { return *_mem_poll; }
const Phase &at(const std::string &tag) const { return _phases.at(tag); }
private:
private:
const PhaseOption _option;
std::unordered_map<std::string, Phase> _phases;
- MemoryPoller _mem_poll;
+ std::unique_ptr<MemoryPoller> _mem_poll;
};
} // namespace benchmark
namespace benchmark
{
-Phases::Phases(const PhaseOption &option)
- : _option(option),
- _mem_poll(std::chrono::milliseconds(option.memory_interval), option.memory_gpu)
+Phases::Phases(const PhaseOption &option) : _option(option)
{
- // DO NOTHING
+ if (_option.memory)
+ {
+ _mem_poll = std::make_unique<MemoryPoller>(std::chrono::milliseconds(option.memory_interval),
+ option.memory_gpu);
+ }
}
void Phases::run(const std::string &tag, const PhaseFunc &exec, const PhaseFunc *post,
for (uint32_t i = 0; i < loop_num; ++i)
{
if (!option_disable && _option.memory)
- _mem_poll.start(p);
+ _mem_poll->start(p);
uint64_t t = 0u;
t = nowMicros();
t = nowMicros() - t;
if (!option_disable && _option.memory)
- _mem_poll.end(p);
+ _mem_poll->end(p);
phase.time.emplace_back(t);
if (!option_disable && _option.memory)
{
- phase.memory[MemoryType::RSS].emplace_back(_mem_poll.getRssMap().at(p));
- phase.memory[MemoryType::HWM].emplace_back(_mem_poll.getHwmMap().at(p));
- phase.memory[MemoryType::PSS].emplace_back(_mem_poll.getPssMap().at(p));
+ phase.memory[MemoryType::RSS].emplace_back(_mem_poll->getRssMap().at(p));
+ phase.memory[MemoryType::HWM].emplace_back(_mem_poll->getHwmMap().at(p));
+ phase.memory[MemoryType::PSS].emplace_back(_mem_poll->getPssMap().at(p));
}
if (post)