Merge branch 'devel/master' into devel/graphics
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / object-profiler.h
1 #ifndef DALI_ADAPTOR_OBJECT_PROFILER_H
2 #define DALI_ADAPTOR_OBJECT_PROFILER_H
3
4 /*
5  * Copyright (c) 2021 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/object-registry.h>
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/public-api/signals/connection-tracker.h>
26 #include <cstddef> // size_t
27 #include <cstdint> // uint32_t
28
29 // INTERNAL INCLUDES
30 #include <dali/public-api/adaptor-framework/timer.h>
31
32 namespace Dali
33 {
34 namespace Internal
35 {
36 namespace Adaptor
37 {
38 /**
39  * Class to profile the number of instances of Objects in the system
40  */
41 class ObjectProfiler : public ConnectionTracker
42 {
43 public:
44   /**
45    * Constructor
46    * @param objectRegistry The objectRegistry
47    * @param timeInterval to specify the frequency of reporting
48    */
49   ObjectProfiler(Dali::ObjectRegistry objectRegistry, uint32_t timeInterval);
50
51   /**
52    * Destructor
53    */
54   ~ObjectProfiler();
55
56   /**
57    * Display a list of types with the current number of instances in the system
58    */
59   void DisplayInstanceCounts();
60
61 private:
62   /**
63    * If timer is running, display the instance counts
64    */
65   bool OnTimeout();
66
67   /**
68    * Callback used when objects are created. Increases instance count for that object type
69    * @param[in] handle of the created object
70    */
71   void OnObjectCreated(BaseHandle handle);
72
73   /**
74    * Callback used when objects are created. Decreases instance count for that object type
75    * @param[in] object The object being destroyed
76    */
77   void OnObjectDestroyed(const Dali::RefObject* object);
78
79   /**
80    * Get the memory size of the given object
81    */
82   std::size_t GetMemorySize(const std::string& name, uint32_t count);
83
84 private:
85   using InstanceCountPair = std::pair<const std::string, uint32_t>;
86   using InstanceTypePair  = std::pair<BaseObject*, std::string>;
87
88   Dali::ObjectRegistry           mObjectRegistry;
89   Dali::Timer                    mTimer;
90   std::vector<InstanceCountPair> mInstanceCountContainer;
91   std::vector<InstanceTypePair>  mInstanceTypes;
92 };
93
94 } // namespace Adaptor
95 } // namespace Internal
96 } // namespace Dali
97
98 #endif // DALI_ADAPTOR_OBJECT_PROFILER_H