Refactor and add Wayland support.
[platform/core/uifw/dali-adaptor.git] / adaptors / common / object-profiler.h
1 #ifndef __DALI_ADAPTOR_OBJECT_PROFILER_H__
2 #define __DALI_ADAPTOR_OBJECT_PROFILER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 #include <dali/public-api/object/object-registry.h>
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/public-api/common/map-wrapper.h>
24 #include <dali/public-api/signals/connection-tracker.h>
25 #include <timer.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 namespace Adaptor
32 {
33
34 /**
35  * Class to profile the number of instances of Objects in the system
36  */
37 class ObjectProfiler : public ConnectionTracker
38 {
39 public:
40   /**
41    * Constructor
42    */
43   ObjectProfiler();
44
45   /**
46    * Destructor
47    */
48   ~ObjectProfiler();
49
50   /**
51    * Display a list of types with the current number of instances in the system
52    */
53   void DisplayInstanceCounts();
54
55 private:
56   /**
57    * If timer is running, display the instance counts
58    */
59   bool OnTimeout();
60
61   /**
62    * Callback used when objects are created. Increases instance count for that object type
63    * @param[in] handle of the created object
64    */
65   void OnObjectCreated(BaseHandle handle);
66
67   /**
68    * Callback used when objects are created. Decreases instance count for that object type
69    * @param[in] object The object being destroyed
70    */
71   void OnObjectDestroyed(const Dali::RefObject* object);
72
73   /**
74    * Get the memory size of the given object
75    */
76   int GetMemorySize(const std::string& name, int count);
77
78 private:
79   typedef std::map<std::string, int> InstanceCountMap;
80   typedef std::pair<const std::string, int> InstanceCountPair;
81   typedef InstanceCountMap::iterator InstanceCountMapIterator;
82   typedef std::pair<BaseObject*, std::string> InstanceTypePair;
83   typedef std::vector<InstanceTypePair> InstanceTypes;
84
85   Dali::ObjectRegistry    mObjectRegistry;
86   Dali::Timer             mTimer;
87   InstanceCountMap        mInstanceCountMap;
88   InstanceTypes           mInstanceTypes;
89   bool                    mIsActive;
90 };
91
92 } // Adaptor
93 } // Internal
94 } // Dali
95
96 #endif // __DALI_ADAPTOR_OBJECT_PROFILER_H__