PixelLightAPI  .
Profiling.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Profiling.h                                    *
00003  *
00004  *  Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_PROFILING_H__
00024 #define __PLCORE_PROFILING_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/Core/Singleton.h"
00032 #include "PLCore/Container/Element.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLCore {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Classes                                               ]
00043 //[-------------------------------------------------------]
00044 /**
00045 *  @brief
00046 *    Profiling group element
00047 */
00048 class ProfileGroupElement : public Element<ProfileGroupElement> {
00049 
00050 
00051     //[-------------------------------------------------------]
00052     //[ Public functions                                      ]
00053     //[-------------------------------------------------------]
00054     public:
00055         /**
00056         *  @brief
00057         *    Constructor
00058         *
00059         *  @param[in] sName
00060         *    Element name to set
00061         *  @param[in] pManager
00062         *    Element manager using this element, can be a null pointer
00063         */
00064         PLCORE_API ProfileGroupElement(const String &sName = "", ElementManager<ProfileGroupElement> *pManager = nullptr);
00065 
00066         /**
00067         *  @brief
00068         *    Destructor
00069         */
00070         PLCORE_API virtual ~ProfileGroupElement();
00071 
00072         /**
00073         *  @brief
00074         *    Returns the text of the element
00075         *
00076         *  @return
00077         *    Text of the element
00078         */
00079         inline String GetText() const;
00080 
00081         /**
00082         *  @brief
00083         *    Sets the element text
00084         *
00085         *  @param[in] sText
00086         *    Text to be set
00087         *
00088         *  @return
00089         *    'true' if all went fine, else 'false'
00090         */
00091         inline bool SetText(const String &sText);
00092 
00093         /**
00094         *  @brief
00095         *    Copy operator
00096         *
00097         *  @param[in] cSource
00098         *    Source to copy from
00099         *
00100         *  @return
00101         *    Reference to this instance
00102         */
00103         inline ProfileGroupElement &operator =(const ProfileGroupElement &cSource);
00104 
00105 
00106     //[-------------------------------------------------------]
00107     //[ Private functions                                     ]
00108     //[-------------------------------------------------------]
00109     private:
00110         /**
00111         *  @brief
00112         *    Copy constructor
00113         *
00114         *  @param[in] cSource
00115         *    Source to copy from
00116         */
00117         ProfileGroupElement(const ProfileGroupElement &cSource);
00118 
00119 
00120     //[-------------------------------------------------------]
00121     //[ Private data                                          ]
00122     //[-------------------------------------------------------]
00123     private:
00124         String m_sText; /**< Text to be shown */
00125 
00126 
00127 };
00128 
00129 /**
00130 *  @brief
00131 *    Profiling group
00132 */
00133 class ProfileGroup : public Element<ProfileGroup>, public ElementManager<ProfileGroupElement> {
00134 
00135 
00136     //[-------------------------------------------------------]
00137     //[ Friends                                               ]
00138     //[-------------------------------------------------------]
00139     friend class Profiling;
00140 
00141 
00142     //[-------------------------------------------------------]
00143     //[ Public functions                                      ]
00144     //[-------------------------------------------------------]
00145     public:
00146         /**
00147         *  @brief
00148         *    Constructor
00149         *
00150         *  @param[in] sName
00151         *    Element name to set
00152         *  @param[in] pManager
00153         *    Element manager using this element, can be a null pointer
00154         */
00155         PLCORE_API ProfileGroup(const String &sName = "", ElementManager<ProfileGroup> *pManager = nullptr);
00156 
00157         /**
00158         *  @brief
00159         *    Destructor
00160         */
00161         PLCORE_API virtual ~ProfileGroup();
00162 
00163         /**
00164         *  @brief
00165         *    Returns the text of the element group
00166         *
00167         *  @return
00168         *    Text of the element group
00169         */
00170         inline String GetText() const;
00171 
00172         /**
00173         *  @brief
00174         *    Sets the element group text
00175         *
00176         *  @param[in] sText
00177         *    Text to be set
00178         *
00179         *  @return
00180         *    'true' if all went fine, else 'false'
00181         */
00182         inline bool SetText(const String &sText);
00183 
00184         /**
00185         *  @brief
00186         *    Copy operator
00187         *
00188         *  @param[in] cSource
00189         *    Source to copy from
00190         *
00191         *  @return
00192         *    Reference to this instance
00193         */
00194         inline ProfileGroup &operator =(const ProfileGroup &cSource);
00195 
00196 
00197     //[-------------------------------------------------------]
00198     //[ Private functions                                     ]
00199     //[-------------------------------------------------------]
00200     private:
00201         /**
00202         *  @brief
00203         *    Copy constructor
00204         *
00205         *  @param[in] cSource
00206         *    Source to copy from
00207         */
00208         ProfileGroup(const ProfileGroup &cSource);
00209 
00210 
00211     //[-------------------------------------------------------]
00212     //[ Private data                                          ]
00213     //[-------------------------------------------------------]
00214     private:
00215         String m_sText; /**< Text to be shown */
00216 
00217 
00218     //[-------------------------------------------------------]
00219     //[ Private virtual ElementManager functions              ]
00220     //[-------------------------------------------------------]
00221     private:
00222         virtual ProfileGroupElement *CreateElement(const String &sName) override;
00223 
00224 
00225 };
00226 
00227 /**
00228 *  @brief
00229 *    PixelLight profiling system
00230 *
00231 *  @remarks
00232 *    The PL API profiling tool is extreme useful to acquire information about certain code
00233 *    parts and their performance. If the profiling is activated with Profiling::GetInstance()->SetActive()
00234 *    it displays you information like current FPS, triangle count, number of scene nodes, scene
00235 *    update time etc. With this information you are able to find out were your performance is
00236 *    burned. The profiling information are subdivided in groups like general, scene, textures
00237 *    etc. containing elements were you could ’browse’ through using offered functions like
00238 *    Profiling::GetInstance()->SelectNextGroup().
00239 *    By default the PL console offers all required commands to handle the profiling tool in a
00240 *    comfortable way therefore there’s no real need to use the profiling browse functions offered
00241 *    by the profiling interface. :)\n
00242 *
00243 *    Adding own groups and elements:\n
00244 *    The profiling information could be expand with own information you maybe want to add
00245 *    to inspect the runtime behavior of certain codes. In fact that’s much easier as it may
00246 *    sound first... in real it’s only ONE function called Profiling::GetInstance()->Set() you need to
00247 *    use to customize the PL profiling tool!!\n
00248 *    Example:\n
00249 *    // Add profiling information\n
00250 *    Profiling::GetInstance()->Set("MyProfilingGroup", "Name: " + sName);\n
00251 *    Profiling::GetInstance()->Set("MyProfilingGroup", String("Current level: ") + nLevel);\n
00252 *    This will add the defined elements to the own profiling group ’MyProfilingGroup’.
00253 *    If this group doesn’t exist yet it’s created automatically, therefore you done have to be
00254 *    interested in the stuff behind all! If you want to do more that only the described above it’s
00255 *    still possible because you have FULL access to all required to remove groups etc. (because
00256 *    the profiling class is derived from ElementManager)
00257 *
00258 *  @note
00259 *    - You can manipulate each element by hand, but it's recommended
00260 *      to use the helper functions provided by the profiling system
00261 */
00262 class Profiling : public ElementManager<ProfileGroup>, public Singleton<Profiling> {
00263 
00264 
00265     //[-------------------------------------------------------]
00266     //[ Friends                                               ]
00267     //[-------------------------------------------------------]
00268     friend class Singleton<Profiling>;
00269 
00270 
00271     //[-------------------------------------------------------]
00272     //[ Public static PLCore::Singleton functions             ]
00273     //[-------------------------------------------------------]
00274     // This solution enhances the compatibility with legacy compilers like GCC 4.2.1 used on Mac OS X 10.6
00275     // -> The C++11 feature "extern template" (C++11, see e.g. http://www2.research.att.com/~bs/C++0xFAQ.html#extern-templates) can only be used on modern compilers like GCC 4.6
00276     // -> We can't break legacy compiler support, especially when only the singletons are responsible for the break
00277     // -> See PLCore::Singleton for more details about singletons
00278     public:
00279         static PLCORE_API Profiling *GetInstance();
00280         static PLCORE_API bool HasInstance();
00281 
00282 
00283     //[-------------------------------------------------------]
00284     //[ Public functions                                      ]
00285     //[-------------------------------------------------------]
00286     public:
00287         /**
00288         *  @brief
00289         *    Returns whether the profiling system is active or not
00290         *
00291         *  @return
00292         *    'true' if the profiling system is active, else 'false'
00293         *
00294         *  @note
00295         *    - If the profiling system is active the current profile group
00296         *      information will be shown automatically
00297         */
00298         inline bool IsActive() const;
00299 
00300         /**
00301         *  @brief
00302         *    Sets whether the profiling system is active or not
00303         *
00304         *  @param[in] bActive
00305         *    Should the profiling system be active?
00306         */
00307         inline void SetActive(bool bActive = false);
00308 
00309         /**
00310         *  @brief
00311         *    Returns the name of the current selected profile group
00312         *
00313         *  @return
00314         *    Name of the current selected profile group
00315         */
00316         inline String GetSelectedGroup() const;
00317 
00318         /**
00319         *  @brief
00320         *    Selects a profile group
00321         *
00322         *  @param[in] sName
00323         *    Name of the profile group which should be the current one
00324         *    If "" general profile information are shown.
00325         *
00326         *  @return
00327         *    'true' if all went fine, else 'false'
00328         *    (maybe there's no group with this name??)
00329         */
00330         PLCORE_API bool SelectGroup(const String &sName = "");
00331 
00332         /**
00333         *  @brief
00334         *    Selects the next profile group
00335         *
00336         *  @return
00337         *    Name of the current selected profile group
00338         */
00339         PLCORE_API String SelectNextGroup();
00340 
00341         /**
00342         *  @brief
00343         *    Selects the previous profile group
00344         *
00345         *  @return
00346         *    Name of the current selected profile group
00347         */
00348         PLCORE_API String SelectPreviousGroup();
00349 
00350         /**
00351         *  @brief
00352         *    Sets the element text
00353         *
00354         *  @param[in] sGroup
00355         *    Group name
00356         *  @param[in] sElement
00357         *    Element name
00358         *  @param[in] sText
00359         *    Text to be set
00360         *
00361         *  @return
00362         *    'true' if all went fine, else 'false'
00363         *    (maybe the profiling is deactivated??)
00364         *
00365         *  @note
00366         *    - The group/element is created automatically
00367         *    - If the profiling system is currently deactivated this
00368         *      function makes nothing
00369         */
00370         PLCORE_API bool Set(const String &sGroup, const String &sElement, const String &sText);
00371 
00372         /**
00373         *  @brief
00374         *    Returns the element text
00375         *
00376         *  @param[in] sGroup
00377         *    Group name
00378         *  @param[in] sElement
00379         *    Element name
00380         *
00381         *  @return
00382         *    The text of the element, empty if there was an error
00383         */
00384         PLCORE_API String GetText(const String &sGroup, const String &sElement) const;
00385 
00386 
00387     //[-------------------------------------------------------]
00388     //[ Private functions                                     ]
00389     //[-------------------------------------------------------]
00390     private:
00391         /**
00392         *  @brief
00393         *    Constructor
00394         */
00395         Profiling();
00396 
00397         /**
00398         *  @brief
00399         *    Copy constructor
00400         *
00401         *  @param[in] cSource
00402         *    Source to copy from
00403         */
00404         Profiling(const Profiling &cSource);
00405 
00406         /**
00407         *  @brief
00408         *    Destructor
00409         */
00410         virtual ~Profiling();
00411 
00412         /**
00413         *  @brief
00414         *    Copy operator
00415         *
00416         *  @param[in] cSource
00417         *    Source to copy from
00418         *
00419         *  @return
00420         *    Reference to this instance
00421         */
00422         Profiling &operator =(const Profiling &cSource);
00423 
00424 
00425     //[-------------------------------------------------------]
00426     //[ Private data                                          ]
00427     //[-------------------------------------------------------]
00428     private:
00429         bool   m_bActive;       /**< Is the profiling system active? */
00430         String m_sGroupName;    /**< Name of the current selected profile group */
00431 
00432 
00433     //[-------------------------------------------------------]
00434     //[ Private virtual ElementManager functions              ]
00435     //[-------------------------------------------------------]
00436     private:
00437         virtual ProfileGroup *CreateElement(const String &sName) override;
00438 
00439 
00440 };
00441 
00442 
00443 //[-------------------------------------------------------]
00444 //[ Namespace                                             ]
00445 //[-------------------------------------------------------]
00446 } // PLCore
00447 
00448 
00449 //[-------------------------------------------------------]
00450 //[ Implementation                                        ]
00451 //[-------------------------------------------------------]
00452 #include "PLCore/Tools/Profiling.inl"
00453 
00454 
00455 #endif // __PLCORE_PROFILING_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:50:59
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported