mirror of https://github.com/CGAL/cgal
New profiler, for profiling time spent in a function/block.
This commit is contained in:
parent
af48d47506
commit
68c1bcc095
|
|
@ -0,0 +1,15 @@
|
|||
#define CGAL_PROFILE
|
||||
|
||||
#include <CGAL/Profile_timer.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
CGAL_TIME_PROFILER("seconds spent in this for loop");
|
||||
for (int i=0; i<10; ++i)
|
||||
{
|
||||
// do something
|
||||
double d = 1+1;
|
||||
(void) d;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -21,21 +21,25 @@
|
|||
#ifndef CGAL_PROFILE_COUNTER_H
|
||||
#define CGAL_PROFILE_COUNTER_H
|
||||
|
||||
// This file contains 3 classes to help in profiling, together with macros
|
||||
// This file contains several classes to help in profiling, together with macros
|
||||
// triggered by CGAL_PROFILE to enable them:
|
||||
//
|
||||
// - Profile_counter which is able to keep track of a number, and prints a
|
||||
// message in the destructor. Typically, it can be used as a profile counter
|
||||
// in a static variable.
|
||||
// message in the destructor. Typically, it can be used as a profile counter
|
||||
// in a static variable.
|
||||
//
|
||||
// - Profile_histogram_counter which is similar, but the counter is indexed by
|
||||
// a value (unsigned int), and the final dump is the histogram of the non-zero
|
||||
// counters.
|
||||
// a value (unsigned int), and the final dump is the histogram of the non-zero
|
||||
// counters.
|
||||
//
|
||||
// - Profile_branch_counter which keeps track of 2 counters, aiming at measuring
|
||||
// the ratio corresponding to the number of times a branch is taken.
|
||||
// the ratio corresponding to the number of times a branch is taken.
|
||||
//
|
||||
// See also CGAL/Profile_timer.h
|
||||
|
||||
// TODO : complete the documentation.
|
||||
// TODO :
|
||||
// - Really complete the documentation!
|
||||
// - Probably at some point we will need ways to selectively enable/disable profilers?
|
||||
|
||||
#include <CGAL/config.h>
|
||||
#include <iostream>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
// Copyright (c) 2008 INRIA Sophia-Antipolis (France).
|
||||
// All rights reserved.
|
||||
//
|
||||
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; version 2.1 of the License.
|
||||
// See the file LICENSE.LGPL distributed with CGAL.
|
||||
//
|
||||
// Licensees holding a valid commercial license may use this file in
|
||||
// accordance with the commercial license agreement provided with the software.
|
||||
//
|
||||
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// $URL$
|
||||
// $Id$
|
||||
//
|
||||
// Author(s) : Sylvain Pion
|
||||
|
||||
#ifndef CGAL_PROFILE_TIMER_H
|
||||
#define CGAL_PROFILE_TIMER_H
|
||||
|
||||
// This file contains a class to help in profiling, together with macros
|
||||
// triggered by CGAL_PROFILE to enable it:
|
||||
//
|
||||
// - Profile_timer which keeps track of the time spent in its scope-block.
|
||||
// (be careful at recursive functions :-).
|
||||
//
|
||||
// See also CGAL/Profile_counter.h
|
||||
|
||||
#include <CGAL/config.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <CGAL/Real_timer.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
struct Profile_timer
|
||||
{
|
||||
class Local {
|
||||
Profile_timer &p;
|
||||
public:
|
||||
Local(Profile_timer& p_) : p(p_) { p.start(); }
|
||||
~Local() { p.stop(); }
|
||||
};
|
||||
|
||||
Profile_timer(const std::string & ss)
|
||||
: s(ss) { t.reset(); }
|
||||
|
||||
void start() { t.start(); }
|
||||
void stop() { t.stop(); }
|
||||
|
||||
~Profile_timer()
|
||||
{
|
||||
std::cerr << "[CGAL::Profile_timer] "
|
||||
<< std::setw(10) << t.time() << " " << s << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
Real_timer t;
|
||||
const std::string s;
|
||||
};
|
||||
|
||||
|
||||
#ifdef CGAL_PROFILE
|
||||
# define CGAL_TIME_PROFILER(NAME) \
|
||||
static CGAL::Profile_timer CGAL_profile_timer_tmp(NAME); \
|
||||
CGAL::Profile_timer::Local CGAL_local_profile_timer_tmp(CGAL_profile_timer_tmp);
|
||||
#else
|
||||
# define CGAL_TIME_PROFILER(NAME)
|
||||
#endif
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
#endif // CGAL_PROFILE_TIMER_H
|
||||
Loading…
Reference in New Issue