Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-12 09:53:16

0001 // Created on: 2002-04-03
0002 // Created by: Michael SAZONOV
0003 // Copyright (c) 2002-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef OSD_PerfMeter_HeaderFile
0017 #define OSD_PerfMeter_HeaderFile
0018 
0019 #include <OSD_PerfMeter.h>
0020 
0021 //! This class enables measuring the CPU time between two points of code execution, regardless of the scope of these points of code.
0022 //! A meter is identified by its name (string). So multiple objects in various places of user code may point to the same meter.
0023 //! The results will be printed on stdout upon finish of the program.
0024 //! For details see OSD_PerfMeter.h
0025 class OSD_PerfMeter
0026 {
0027 
0028 public:
0029 
0030   //! Constructs a void meter (to further call Init and Start)
0031   OSD_PerfMeter() : myIMeter(-1) {}
0032 
0033   //! Constructs and starts (if autoStart is true) the named meter
0034   OSD_PerfMeter (const char* theMeter,
0035                  const bool  theToAutoStart = true)
0036   : myIMeter (perf_get_meter (theMeter, 0, 0))
0037   {
0038     if (myIMeter < 0) myIMeter = perf_init_meter (theMeter);
0039     if (theToAutoStart) Start();
0040   }
0041 
0042   //! Prepares the named meter
0043   void Init (const char* theMeter)
0044   {
0045     myIMeter = perf_get_meter (theMeter, 0, 0);
0046     if (myIMeter < 0) myIMeter = perf_init_meter (theMeter);
0047   }
0048 
0049   //! Starts the meter
0050   void Start() const { perf_start_imeter(myIMeter); }
0051 
0052   //! Stops the meter
0053   void Stop() const { perf_stop_imeter(myIMeter); }
0054 
0055   //! Increments the counter w/o time measurement
0056   void Tick() const { perf_tick_imeter(myIMeter); }
0057 
0058   //! Outputs the meter data and resets it to initial state
0059   void Flush() const { perf_close_imeter(myIMeter); }
0060 
0061   //! Assures stopping upon destruction
0062   ~OSD_PerfMeter() { if (myIMeter >= 0) Stop(); }
0063 
0064 private:
0065 
0066   OSD_PerfMeter(const OSD_PerfMeter&);
0067   OSD_PerfMeter& operator= (const OSD_PerfMeter&);
0068 
0069 protected:
0070 
0071   int myIMeter;
0072 
0073 };
0074 
0075 #endif // OSD_PerfMeter_HeaderFile