summaryrefslogtreecommitdiffstats
path: root/kprofilemethod
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbd9e6617827818fd043452c08c606f07b78014a0 (patch)
tree425bb4c3168f9c02f10150f235d2cb998dcc6108 /kprofilemethod
downloadtdesdk-bd9e6617827818fd043452c08c606f07b78014a0.tar.gz
tdesdk-bd9e6617827818fd043452c08c606f07b78014a0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdesdk@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kprofilemethod')
-rw-r--r--kprofilemethod/Makefile.am2
-rw-r--r--kprofilemethod/README21
-rw-r--r--kprofilemethod/kprofilemethod.h51
3 files changed, 74 insertions, 0 deletions
diff --git a/kprofilemethod/Makefile.am b/kprofilemethod/Makefile.am
new file mode 100644
index 00000000..0d2aa3f6
--- /dev/null
+++ b/kprofilemethod/Makefile.am
@@ -0,0 +1,2 @@
+include_HEADERS = kprofilemethod.h
+
diff --git a/kprofilemethod/README b/kprofilemethod/README
new file mode 100644
index 00000000..543e841c
--- /dev/null
+++ b/kprofilemethod/README
@@ -0,0 +1,21 @@
+As the docu in kprofilemethod.h says:
+
+ 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.
+
+WARNING:
+
+ Please do not commit code that uses kprofilemethod.h
+ Since not everyone has kdesdk installed, it won't build for everyone.
+ This is a tool to be used for a one-time profiling, and then you need
+ to remove all its traces before committing.
+
+TODO:
+
+ KDevelop, XEmacs and vi shortcuts to insert begin/end macros around a block
+ of code (e.g. after selecting it) - this macro would also insert the
+ int variable, and another shortcut for inserting the print macro.
+
diff --git a/kprofilemethod/kprofilemethod.h b/kprofilemethod/kprofilemethod.h
new file mode 100644
index 00000000..fc5ecbe1
--- /dev/null
+++ b/kprofilemethod/kprofilemethod.h
@@ -0,0 +1,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., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, 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