Revert "Resolving memory leak issue in Reply function of AppControl"
[platform/framework/web/crosswalk-tizen.git] / common / profiler.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef XWALK_COMMON_PROFILER_H_
18 #define XWALK_COMMON_PROFILER_H_
19
20 #include <time.h>
21
22 #include <map>
23 #include <memory>
24 #include <string>
25
26 namespace common {
27
28 #define PROFILE_START() PrintProfileLog(__FUNCTION__, "START");
29 #define PROFILE_END() PrintProfileLog(__FUNCTION__, "END");
30 #define PROFILE(x) PrintProfileLog(__FUNCTION__, x);
31
32 void PrintProfileLog(const char* func, const char* tag);
33
34 class ScopeProfile {
35  public:
36   explicit ScopeProfile(const char* step, const bool isStep);
37   ~ScopeProfile();
38   void Reset();
39   void End();
40  private:
41   std::string step_;
42   struct timespec start_;
43   bool expired_;
44   bool isStep_;
45 };
46
47 class StepProfile {
48  public:
49   static StepProfile* GetInstance();
50   void Start(const char* step);
51   void End(const char* step);
52  private:
53   StepProfile();
54   ~StepProfile();
55   typedef std::map<const std::string,
56                    std::unique_ptr<ScopeProfile> > ProfileMapT;
57   ProfileMapT map_;
58 };
59
60 }  // namespace common
61
62 #define SCOPE_PROFILE() \
63   common::ScopeProfile __profile(__PRETTY_FUNCTION__, false);
64
65 #define STEP_PROFILE_START(x) \
66   common::StepProfile::GetInstance()->Start(x)
67
68 #define STEP_PROFILE_END(x) \
69   common::StepProfile::GetInstance()->End(x)
70
71
72 #endif  // XWALK_COMMON_PROFILER_H_