summaryrefslogtreecommitdiffstats
path: root/kprofilemethod/kprofilemethod.h
blob: e4a9eeddc720aa05b878a7b0c8b5c96a721c5b38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* This file is part of the KDE project
   Copyright (C) 2002 David Faure <faure@kde.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2, as published by the Free Software Foundation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef KPROFILE_METHOD_H
#define KPROFILE_METHOD_H

#include <qdatetime.h>
#include <kdebug.h>

/**
 * Those macros help profiling using QTime.
 * They allow to sum up the time taken by a given bit of code
 * in a method called several times.
 * This way one can find out which low-level method used by a high-level
 * method is taking most of its time
 *
 *
 *  Declare the var somewhere, out of any method:
 *   int pr_theMethod = 0;
 *  (the name pr_* helps finding and removing all of this before committing)
 *
 *  Then in the method, around the code to be timed:
 *   PROFILE_METHOD_BEGIN( pr_theMethod );
 *   ...
 *   PROFILE_METHOD_END( pr_theMethod );
 *
 *  And finally, to see the result, put this call in a method
 *  called after all that (destructor, program exit...)
 *   PROFILE_METHOD_PRINT( pr_theMethod, "theMethod" );
 *
 */
#define PROFILE_METHOD_BEGIN(sym) extern int sym; QTime profile_dt##sym; profile_dt##sym.start();
#define PROFILE_METHOD_END(sym) extern int sym; sym += profile_dt##sym.elapsed();
#define PROFILE_METHOD_PRINT(sym, name) extern int sym; kdDebug() << name << " took " << sym << " milliseconds" << endl;

#endif // KPROFILE_METHOD_H