BVB Source Codes

CRYENGINE Show CodeCoverageTracker.h Source code

Return Download CRYENGINE: download CodeCoverageTracker.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   CodeCoverageTracker.h
  5. //  Created:     18/06/2008 by Matthew
  6. //  Description: Defines code coverage check points
  7. //               and a central class to track their registration
  8. // -------------------------------------------------------------------------
  9. //  History:
  10. //
  11. ////////////////////////////////////////////////////////////////////////////
  12.  
  13. /**
  14.  * Design notes:
  15.  *   See the CodeCoverageManager class that acts as the high-level API to the system
  16.  *   A (separate) tracking GUI is crucial to this system - an efficient interface to service this is not trivial
  17.  *
  18.  * Technical notes:
  19.  *   The manager would appear to lend itself to a map of names to checkpoint pointers for quick lookup
  20.  *   However I really want to keep overhead to a minimum even in registering and I guess we might have 1000 CCCPoints
  21.  *   A vector, with some sorting or heapifying might be better when the code matures
  22.  */
  23.  
  24. #ifndef __CODE_COVERAGE_TRACKER_H_
  25. #define __CODE_COVERAGE_TRACKER_H_
  26.  
  27. #pragma once
  28.  
  29. #include <CrySystem/ICodeCheckpointMgr.h>
  30.  
  31. #ifdef CODECHECKPOINT_ENABLED
  32.  
  33. // Hijack the old CCCPOINT definition (and add a semi-colon to allow compilation)
  34.         #define CCCPOINT(x) CODECHECKPOINT(x);
  35.  
  36. #else   // Use old CCCPOINT system
  37.  
  38. // Code coverage works on console too, but for performance sake lets keep it to PC for now
  39.         #if CRY_PLATFORM_WINDOWS && !defined(_RELEASE)
  40.                 #define CCCPOINT_ENABLE
  41.         #endif
  42.  
  43. /**
  44.  * The key macro
  45.  * If this is ever used by other systems, just break out the "AI" part into new macros
  46.  * Clever people will think of using method names automatically rather than having to type them
  47.  * Please don't do this - if code is moved, renamed, copy/pasted, it's more useful to preserve the label
  48.  */
  49.         #ifdef CCCPOINT_ENABLE
  50.                 #define CCCPOINT(x) static CCodeCoverageCheckPoint autoReg ## x("AI_" # x); autoReg ## x.Touch();
  51.         #else
  52.                 #define CCCPOINT(x) ;
  53.         #endif
  54.  
  55. #endif
  56.  
  57. #if !defined(_RELEASE)
  58.  
  59. // Forward declarations
  60.  
  61. /**
  62.  * A check point
  63.  * As above, static creation occurs once and then Touching happens often
  64.  * I suspect it will be better to keep an explicit flag for registration, to allow clean reset at runtime
  65.  */
  66. class CCodeCoverageCheckPoint
  67. {
  68.         friend class CCodeCoverageTracker;
  69.  
  70. public:
  71.  
  72.         CCodeCoverageCheckPoint(const char* label);
  73.  
  74.         inline void Touch()          { m_nCount++; }
  75.  
  76.         void        Reset()          { m_nCount = 0; }
  77.  
  78.         int         GetCount() const { return m_nCount; }
  79.  
  80.         const char* GetLabel() const { return m_psLabel; }
  81.  
  82. protected:
  83.  
  84.         int         m_nCount;
  85.         const char* m_psLabel;
  86. };
  87.  
  88. /**
  89.  * The check point manager
  90.  * Collects pointers to all checkpoints that have registered
  91.  * If a checkpoint is never hit, it will never be registered
  92.  */
  93. class CCodeCoverageTracker
  94. {
  95.         typedef std::vector<CCodeCoverageCheckPoint*> CheckPointVector;
  96.  
  97. public:
  98.         CCodeCoverageTracker(void);
  99.  
  100.         void Register(CCodeCoverageCheckPoint* pPoint);
  101.  
  102.         // Zero all counters
  103.         void Clear();
  104.  
  105.         // Zero all counters and discard all pointers
  106.         // This might well never be needed
  107.         void Reset();
  108.  
  109.         // Get number of checkpoints registered so far
  110.         // Important for monitoring coverage progress
  111.         int GetTotalRegistered();
  112.  
  113.         // Retrieves the last 3 encountered checkpoints in the current frame.
  114.         // It also resets the buffer for storing the last 3 checkpoints.
  115.         // This is used by the CCodeCoverageGUI class to display the last few checkpoints encountered.
  116.         void GetMostRecentAndReset(const char* pRet[3]);
  117.  
  118.         // Get pointer to checkpoint of this label
  119.         CCodeCoverageCheckPoint* GetCheckPoint(const char* sLabel) const;
  120.  
  121.         const CheckPointVector&  GetRecentCheckpoints() const
  122.         {
  123.                 return m_vecCheckPoints;
  124.         }
  125.  
  126.         void ResetRecentCheckpoints()
  127.         {
  128.                 m_vecCheckPoints.clear();
  129.         }
  130.  
  131.         void AddCheckpoint(CCodeCoverageCheckPoint* pPoint)
  132.         {
  133.                 m_mCheckPoints.insert(std::make_pair(pPoint->GetLabel(), pPoint));
  134.         }
  135.  
  136. protected:
  137.         // String comparison for map
  138.         struct cmp_str : public std::binary_function<const char*, const char*, bool>
  139.         {
  140.                 bool operator()(char const* a, char const* b) const
  141.                 {
  142.                         return strcmp(a, b) < 0;
  143.                 }
  144.         };
  145.  
  146.         // Map that keeps all the points that have been hit
  147.         typedef std::map<const char*, CCodeCoverageCheckPoint*, cmp_str> CheckPointMap;
  148.         CheckPointMap m_mCheckPoints;
  149.  
  150.         // Temporary list to keep track of points
  151.         // before the CodeCoverageManager has been initialized
  152.         // After the CodeCoverageManager has been initialized this becomes a list checkpoints per frame
  153.         CheckPointVector m_vecCheckPoints;
  154.  
  155.         const char*      m_pMostRecent[3];
  156.         int              m_nLastEntry; // Last entry in m_pMostRecent
  157. };
  158.  
  159. #endif //_RELEASE
  160.  
  161. #endif // __CODE_COVERAGE_TRACKER_H_
  162.  
downloadCodeCoverageTracker.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top