2 * Copyright 2018 The TensorFlow Authors. All Rights Reserved.
3 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "benchmark/Phases.h"
19 #include "benchmark/Types.h"
32 gettimeofday(&tv, nullptr);
33 return static_cast<uint64_t>(tv.tv_sec) * 1e6 + tv.tv_usec;
36 void SleepForMicros(uint64_t micros)
39 sleep_time.tv_sec = micros / 1e6;
40 micros -= sleep_time.tv_sec * 1e6;
41 sleep_time.tv_nsec = micros * 1e3;
42 nanosleep(&sleep_time, nullptr);
49 Phases::Phases(const PhaseOption &option)
51 _mem_poll(std::chrono::milliseconds(option.memory_interval), option.memory_gpu)
56 void Phases::run(const std::string &tag, const PhaseFunc &exec, const PhaseFunc *post,
57 uint32_t loop_num, bool option_disable)
59 Phase phase{tag, loop_num};
60 PhaseEnum p = getPhaseEnum(tag);
61 for (uint32_t i = 0; i < loop_num; ++i)
63 if (!option_disable && _option.memory)
73 if (!option_disable && _option.memory)
76 phase.time.emplace_back(t);
78 if (!option_disable && _option.memory)
80 phase.memory[MemoryType::RSS].emplace_back(_mem_poll.getRssMap().at(p));
81 phase.memory[MemoryType::HWM].emplace_back(_mem_poll.getHwmMap().at(p));
82 phase.memory[MemoryType::PSS].emplace_back(_mem_poll.getPssMap().at(p));
88 if (_option.run_delay > 0 && p == PhaseEnum::EXECUTE && i != loop_num - 1)
90 SleepForMicros(_option.run_delay);
94 if (p == PhaseEnum::END_OF_PHASE)
99 assert(_phases.find(tag) == _phases.end());
100 _phases.emplace(tag, phase);
103 } // namespace benchmark