From 0994e7f96fd7b98ba3967ca44b93b93fa1c31920 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 3 Sep 2013 21:22:43 +0000 Subject: move timeit macros into their own include, since they are only used for testing and unrelated to PIL_time.h typical use. --- source/blender/blenlib/CMakeLists.txt | 1 + source/blender/blenlib/PIL_time.h | 58 +------------ source/blender/blenlib/PIL_time_utildefines.h | 95 ++++++++++++++++++++++ source/blender/bmesh/operators/bmo_beautify.c | 1 + source/blender/editors/space_view3d/drawvolume.c | 1 + source/blender/modifiers/intern/MOD_decimate.c | 1 + .../modifiers/intern/MOD_weightvgproximity.c | 21 ++--- 7 files changed, 111 insertions(+), 67 deletions(-) create mode 100644 source/blender/blenlib/PIL_time_utildefines.h (limited to 'source') diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 70665521ca8..9ca56d60593 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -162,6 +162,7 @@ set(SRC BLI_voxel.h BLI_winstuff.h PIL_time.h + PIL_time_utildefines.h ) if(WITH_BINRELOC) diff --git a/source/blender/blenlib/PIL_time.h b/source/blender/blenlib/PIL_time.h index 3983b5099ff..158559fa3d9 100644 --- a/source/blender/blenlib/PIL_time.h +++ b/source/blender/blenlib/PIL_time.h @@ -51,64 +51,8 @@ double PIL_check_seconds_timer(void); */ void PIL_sleep_ms(int ms); -/** Utility defines for timing. - * requires BLI_utildefines.h for 'AT' - * TIMEIT_VALUE returns the time since TIMEIT_START was called. - */ -#define TIMEIT_START(var) \ - { \ - double _timeit_##var = PIL_check_seconds_timer(); \ - printf("time start (" #var "): " AT "\n"); \ - fflush(stdout); \ - { (void)0 - -#define TIMEIT_VALUE(var) (float)(PIL_check_seconds_timer() - _timeit_##var) - -#define TIMEIT_VALUE_PRINT(var) \ - { \ - printf("time update(" #var "): %.6f" " " AT "\n", TIMEIT_VALUE(var));\ - fflush(stdout); \ - } (void)0 - -#define TIMEIT_END(var) \ - } \ - printf("time end (" #var "): %.6f" " " AT "\n", TIMEIT_VALUE(var)); \ - fflush(stdout); \ -} (void)0 - -/** - * Given some function/expression: - * TIMEIT_BENCH(some_function(), some_unique_description); - */ -#define TIMEIT_BENCH(expr, id) \ - { \ - TIMEIT_START(id); \ - (expr); \ - TIMEIT_END(id); \ - } (void)0 - -#define TIMEIT_BLOCK_INIT(what) \ - double _timeit_var_##what = 0; \ - (void) 0 - -#define TIMEIT_BLOCK_BEGIN(what) \ - { \ - double _timeit_block_start_##what = PIL_check_seconds_timer(); \ - { (void)0 - -#define TIMEIT_BLOCK_END(what) \ - } \ - _timeit_var_##what += PIL_check_seconds_timer() - _timeit_block_start_##what; \ - } (void)0 - -#define TIMEIT_BLOCK_STATS(what) \ - { \ - printf("%s time (in seconds): %f\n", #what, _timeit_var_##what); \ - fflush(stdout); \ - } (void)0 - #ifdef __cplusplus } #endif -#endif /* !__PIL_TIME_H__ */ +#endif /* __PIL_TIME_H__ */ diff --git a/source/blender/blenlib/PIL_time_utildefines.h b/source/blender/blenlib/PIL_time_utildefines.h new file mode 100644 index 00000000000..c253aba875f --- /dev/null +++ b/source/blender/blenlib/PIL_time_utildefines.h @@ -0,0 +1,95 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Campbell Barton + * Sergey Sharybin + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenlib/PIL_time_utildefines.h + * \ingroup bli + * \brief Utility defines for timing/benchmarks. + * + * \note requires BLI_utildefines.h for 'AT'. + */ + +#ifndef __PIL_TIME_UTILDEFINES_H__ +#define __PIL_TIME_UTILDEFINES_H__ + +#define TIMEIT_START(var) \ + { \ + double _timeit_##var = PIL_check_seconds_timer(); \ + printf("time start (" #var "): " AT "\n"); \ + fflush(stdout); \ + { (void)0 + +/** + * \return the time since TIMEIT_START was called. + */ +#define TIMEIT_VALUE(var) (float)(PIL_check_seconds_timer() - _timeit_##var) + +#define TIMEIT_VALUE_PRINT(var) \ + { \ + printf("time update(" #var "): %.6f" " " AT "\n", TIMEIT_VALUE(var));\ + fflush(stdout); \ + } (void)0 + +#define TIMEIT_END(var) \ + } \ + printf("time end (" #var "): %.6f" " " AT "\n", TIMEIT_VALUE(var)); \ + fflush(stdout); \ +} (void)0 + +/** + * Given some function/expression: + * TIMEIT_BENCH(some_function(), some_unique_description); + */ +#define TIMEIT_BENCH(expr, id) \ + { \ + TIMEIT_START(id); \ + (expr); \ + TIMEIT_END(id); \ + } (void)0 + +#define TIMEIT_BLOCK_INIT(id) \ + double _timeit_var_##id = 0; \ + (void) 0 + +#define TIMEIT_BLOCK_START(id) \ + { \ + double _timeit_block_start_##id = PIL_check_seconds_timer(); \ + { (void)0 + +#define TIMEIT_BLOCK_END(id) \ + } \ + _timeit_var_##id += (PIL_check_seconds_timer() - \ + _timeit_block_start_##id); \ + } (void)0 + +#define TIMEIT_BLOCK_STATS(id) \ + { \ + printf("%s time (in seconds): %f\n", #id, _timeit_var_##id); \ + fflush(stdout); \ + } (void)0 + +#endif /* __PIL_TIME_UTILDEFINES_H__ */ diff --git a/source/blender/bmesh/operators/bmo_beautify.c b/source/blender/bmesh/operators/bmo_beautify.c index 3dbdb3ddc52..a6d781c2066 100644 --- a/source/blender/bmesh/operators/bmo_beautify.c +++ b/source/blender/bmesh/operators/bmo_beautify.c @@ -47,6 +47,7 @@ #ifdef DEBUG_TIME # include "PIL_time.h" +# include "PIL_time_utildefines.h" #endif enum { diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c index 542ed7af0e6..a7940faa47d 100644 --- a/source/blender/editors/space_view3d/drawvolume.c +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -83,6 +83,7 @@ struct GPUTexture; #ifdef DEBUG_DRAW_TIME # include "PIL_time.h" +# include "PIL_time_utildefines.h" #endif static int intersect_edges(float *points, float a, float b, float c, float d, float edges[12][2][3]) diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c index 69988f32da9..a3569cbde68 100644 --- a/source/blender/modifiers/intern/MOD_decimate.c +++ b/source/blender/modifiers/intern/MOD_decimate.c @@ -55,6 +55,7 @@ #ifdef USE_TIMEIT # include "PIL_time.h" +# include "PIL_time_utildefines.h" #endif #include "MOD_util.h" diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index 63267538528..67168e52949 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -28,18 +28,12 @@ * \ingroup modifiers */ -#define DO_PROFILE 0 - #include "BLI_utildefines.h" #include "BLI_ghash.h" #include "BLI_math.h" #include "BLI_string.h" #include "BLI_rand.h" -#if DO_PROFILE - #include "PIL_time.h" -#endif - #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_modifier_types.h" @@ -58,6 +52,13 @@ #include "MOD_util.h" #include "MOD_weightvg_util.h" +// #define USE_TIMEIT + +#ifdef USE_TIMEIT +# include "PIL_time.h" +# include "PIL_time_utildefines.h" +#endif + /************************************** * Util functions. * **************************************/ @@ -382,8 +383,8 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der int do_prev = (wmd->modifier.mode & eModifierMode_DoWeightPreview); #endif -#if DO_PROFILE - TIMEIT_START(perf) +#ifdef USE_TIMEIT + TIMEIT_START(perf); #endif /* Get number of verts. */ @@ -548,8 +549,8 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der MEM_freeN(indices); MEM_freeN(v_cos); -#if DO_PROFILE - TIMEIT_END(perf) +#ifdef USE_TIMEIT + TIMEIT_END(perf); #endif /* Return the vgroup-modified mesh. */ -- cgit v1.2.3