00001 /* 00002 ** (c) 1996-2000 The Regents of the University of California (through 00003 ** E.O. Lawrence Berkeley National Laboratory), subject to approval by 00004 ** the U.S. Department of Energy. Your use of this software is under 00005 ** license -- the license agreement is attached and included in the 00006 ** directory as license.txt or you may contact Berkeley Lab's Technology 00007 ** Transfer Department at TTD@lbl.gov. NOTICE OF U.S. GOVERNMENT RIGHTS. 00008 ** The Software was developed under funding from the U.S. Government 00009 ** which consequently retains certain rights as follows: the 00010 ** U.S. Government has been granted for itself and others acting on its 00011 ** behalf a paid-up, nonexclusive, irrevocable, worldwide license in the 00012 ** Software to reproduce, prepare derivative works, and perform publicly 00013 ** and display publicly. Beginning five (5) years after the date 00014 ** permission to assert copyright is obtained from the U.S. Department of 00015 ** Energy, and subject to any subsequent five (5) year renewals, the 00016 ** U.S. Government is granted for itself and others acting on its behalf 00017 ** a paid-up, nonexclusive, irrevocable, worldwide license in the 00018 ** Software to reproduce, prepare derivative works, distribute copies to 00019 ** the public, perform publicly and display publicly, and to permit 00020 ** others to do so. 00021 */ 00022 00023 #ifndef _BL_PROFILER_H_ 00024 #define _BL_PROFILER_H_ 00025 // 00026 // $Id: Profiler.H,v 1.8 2001/08/21 22:16:26 car Exp $ 00027 // 00028 #include <iostream> 00029 #include <string> 00030 #include <typeinfo> 00031 00032 class Profiler 00033 { 00034 public: 00035 class Tag; 00036 Profiler(const Tag& tag_, bool hold = false); 00037 void start(); 00038 void stop(); 00039 ~Profiler(); 00040 static void on(); 00041 static void off(); 00042 static bool is_profiling(); 00043 static std::string clean_name(const std::string& str); 00044 static void Initialize(); 00045 static void Finalize(); 00046 private: 00047 static void glean(); 00048 const Tag& tag; 00049 bool started; 00050 static bool profiling; 00051 Profiler(const Profiler& prf); 00052 Profiler& operator=(const Profiler& prf); 00053 }; 00054 00055 class Profiler::Tag 00056 { 00057 public: 00058 explicit Tag(const std::string& tag_); 00059 const std::string& name() const; 00060 private: 00061 int itag; 00062 const std::string tag; 00063 static int next_itag; 00064 }; 00065 00066 #define BL_PROFILE(a) 00067 #define BL_PROFILE_TIMER(var, a) 00068 #define BL_PROFILE_START(var) 00069 #define BL_PROFILE_STOP(var) 00070 #define BL_PROFILE_THIS_NAME() 00071 00072 #endif