提交 ba82924d 编写于 作者: D dolphin8

fix profile, sort by total cpu ticks

上级 5647e651
...@@ -14,9 +14,13 @@ limitations under the License. */ ...@@ -14,9 +14,13 @@ limitations under the License. */
#include "io.h" #include "io.h"
#include <vector> #include <vector>
#define PADDLE_MOBILE_PROFILE
#ifdef PADDLE_MOBILE_PROFILE #ifdef PADDLE_MOBILE_PROFILE
#include <ctime> #include <ctime>
#include <unordered_map>
#include <map> #include <map>
#include <algorithm>
#include <numeric>
#endif #endif
#include "common/enforce.h" #include "common/enforce.h"
...@@ -346,26 +350,31 @@ std::shared_ptr<framework::Tensor> Executor<Dtype, P>::Predict( ...@@ -346,26 +350,31 @@ std::shared_ptr<framework::Tensor> Executor<Dtype, P>::Predict(
for (int j = 0; j < ops_of_block_[*to_predict_block.get()].size(); ++j) { for (int j = 0; j < ops_of_block_[*to_predict_block.get()].size(); ++j) {
auto op = ops_of_block_[*to_predict_block.get()][j]; auto op = ops_of_block_[*to_predict_block.get()][j];
#ifdef PADDLE_MOBILE_PROFILE #ifdef PADDLE_MOBILE_PROFILE
_profile[op->Type()] = clock(); clock_t _tic = clock();
#endif #endif
op->Run(); op->Run();
#ifdef PADDLE_MOBILE_PROFILE #ifdef PADDLE_MOBILE_PROFILE
_profile[op->Type()] = clock() - _profile[op->Type()]; _profile[op->Type()] += clock() - _tic;
#endif #endif
} }
#ifdef PADDLE_MOBILE_PROFILE #ifdef PADDLE_MOBILE_PROFILE
{ {
DLOG << "========================[ profile ]=========================="; std::cout << "========================[ profile ]==========================\n";
clock_t _ptotal = 0; std::vector<std::pair<std::string, clock_t>> _tprofile(_profile.begin(), _profile.end());
for (auto const &p : _profile) { clock_t _ptotal;
for (auto const& p : _tprofile) {
_ptotal += p.second; _ptotal += p.second;
} }
for (auto const &p : _profile) { std::sort(_tprofile.begin(), _tprofile.end(), [](auto& a, auto& b) {
DLOG << p.first << std::string(16 - p.first.size(), ' ') << "\t" return a.second > b.second;
<< (float)p.second << "\t\t" });
<< (float)p.second / (float)_ptotal * 100.0; _tprofile.push_back(std::make_pair("total", _ptotal));
for (auto const &p : _tprofile) {
std::cout << p.first << std::string(16 - p.first.size(), ' ') << "\t"
<< p.second << "\t\t"
<< (float)p.second / _ptotal * 100.0 << "\n";
} }
DLOG << "========================[ ]=========================="; std::cout << "========================[---------]==========================\n";
} }
#endif #endif
auto ops = ops_of_block_[*to_predict_program_->Block(0)]; auto ops = ops_of_block_[*to_predict_program_->Block(0)];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册