Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / mkldnn_plugin / perf_count.h
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <chrono>
8
9 namespace MKLDNNPlugin {
10
11 class PerfCount {
12     uint64_t duration;
13     uint32_t num;
14
15     std::chrono::high_resolution_clock::time_point __start;
16     std::chrono::high_resolution_clock::time_point __finish;
17
18 public:
19     PerfCount(): duration(0), num(0) {}
20
21     uint64_t avg() { return (num == 0) ? 0 : duration / num; }
22
23 private:
24     void start_itr() {
25         __start = std::chrono::high_resolution_clock::now();
26     }
27
28     void finish_itr() {
29         __finish = std::chrono::high_resolution_clock::now();
30
31         duration += std::chrono::duration_cast<std::chrono::microseconds>(__finish - __start).count();
32         num++;
33     }
34
35     friend class PerfHelper;
36 };
37
38 class PerfHelper {
39     PerfCount &counter;
40
41 public:
42     explicit PerfHelper(PerfCount &count): counter(count) { counter.start_itr(); }
43
44     ~PerfHelper() { counter.finish_itr(); }
45 };
46
47 }  // namespace MKLDNNPlugin
48
49 #define PERF(_counter) PerfHelper __helper##__counter (_counter->PerfCounter());