[Bf-blender-cvs] [3ff45ef] openvdb: A simple utility class to time functions.
Kévin Dietrich
noreply at git.blender.org
Fri Jul 17 20:21:32 CEST 2015
Commit: 3ff45ef48f89d470c086fc47d67cdfc56076f7c1
Author: Kévin Dietrich
Date: Fri Jul 17 19:24:25 2015 +0200
Branches: openvdb
https://developer.blender.org/rB3ff45ef48f89d470c086fc47d67cdfc56076f7c1
A simple utility class to time functions.
===================================================================
M intern/openvdb/openvdb_capi.cpp
M intern/openvdb/openvdb_util.cpp
M intern/openvdb/openvdb_util.h
===================================================================
diff --git a/intern/openvdb/openvdb_capi.cpp b/intern/openvdb/openvdb_capi.cpp
index f91b2d3..0e604d1 100644
--- a/intern/openvdb/openvdb_capi.cpp
+++ b/intern/openvdb/openvdb_capi.cpp
@@ -40,6 +40,8 @@ int OpenVDB_getVersionHex()
void OpenVDB_get_grid_info(const char *filename, OpenVDBGridInfoCallback cb, void *userdata)
{
+ Timer(__func__);
+
int ret = OPENVDB_NO_ERROR;
initialize();
@@ -72,6 +74,8 @@ OpenVDBFloatGrid *OpenVDB_export_grid_fl(OpenVDBWriter *writer,
const int res[3], float matrix[4][4],
OpenVDBFloatGrid *mask)
{
+ Timer(__func__);
+
OpenVDBFloatGrid *grid =
(OpenVDBFloatGrid *)internal::OpenVDB_export_grid<FloatGrid>(writer, name, data, res, matrix, (FloatGrid *)mask);
return grid;
@@ -82,6 +86,8 @@ OpenVDBIntGrid *OpenVDB_export_grid_ch(OpenVDBWriter *writer,
const int res[3], float matrix[4][4],
OpenVDBFloatGrid *mask)
{
+ Timer(__func__);
+
OpenVDBIntGrid *grid =
(OpenVDBIntGrid *)internal::OpenVDB_export_grid<Int32Grid>(writer, name, data, res, matrix, (FloatGrid *)mask);
return grid;
@@ -93,6 +99,8 @@ OpenVDBVectorGrid *OpenVDB_export_grid_vec(struct OpenVDBWriter *writer,
const int res[3], float matrix[4][4], short vec_type,
const bool is_color, OpenVDBFloatGrid *mask)
{
+ Timer(__func__);
+
OpenVDBVectorGrid *grid =
(OpenVDBVectorGrid *)internal::OpenVDB_export_vector_grid(writer, name,
data_x, data_y, data_z, res, matrix,
@@ -105,6 +113,8 @@ void OpenVDB_import_grid_fl(OpenVDBReader *reader,
const char *name, float **data,
const int res[3])
{
+ Timer(__func__);
+
internal::OpenVDB_import_grid<FloatGrid>(reader, name, data, res);
}
@@ -120,6 +130,8 @@ void OpenVDB_import_grid_vec(struct OpenVDBReader *reader,
float **data_x, float **data_y, float **data_z,
const int res[3])
{
+ Timer(__func__);
+
internal::OpenVDB_import_grid_vector(reader, name, data_x, data_y, data_z, res);
}
diff --git a/intern/openvdb/openvdb_util.cpp b/intern/openvdb/openvdb_util.cpp
index 4caa62c..f9ea180 100644
--- a/intern/openvdb/openvdb_util.cpp
+++ b/intern/openvdb/openvdb_util.cpp
@@ -78,3 +78,31 @@ void catch_exception(int &ret)
ret = OPENVDB_UNKNOWN_ERROR;
}
}
+
+#ifdef _WIN32
+
+#include <windows.h>
+
+double time_dt()
+{
+ __int64 frequency, counter;
+
+ QueryPerformanceFrequency((LARGE_INTEGER*)&frequency);
+ QueryPerformanceCounter((LARGE_INTEGER*)&counter);
+
+ return (double)counter/(double)frequency;
+}
+
+#else
+
+#include <sys/time.h>
+
+double time_dt()
+{
+ struct timeval now;
+ gettimeofday(&now, NULL);
+
+ return now.tv_sec + now.tv_usec*1e-6;
+}
+
+#endif
diff --git a/intern/openvdb/openvdb_util.h b/intern/openvdb/openvdb_util.h
index 56ed9ce..ad83dbb 100644
--- a/intern/openvdb/openvdb_util.h
+++ b/intern/openvdb/openvdb_util.h
@@ -26,6 +26,37 @@
#ifndef __OPENVDB_UTIL_H__
#define __OPENVDB_UTIL_H__
+#include <cstdio>
+#include <string>
+
void catch_exception(int &ret);
+double time_dt();
+
+/* A utility class which prints the time elapsed during its lifetime, useful for
+ * e.g. timing the overall execution time of a function */
+class ScopeTimer {
+ double m_start;
+ std::string m_message;
+
+public:
+ ScopeTimer(const std::string &message)
+ : m_message(message)
+ {
+ m_start = time_dt();
+ }
+
+ ~ScopeTimer()
+ {
+ printf("%s: %fs\n", m_message.c_str(), time_dt() - m_start);
+ }
+};
+
+#ifndef NDEBUG
+# define Timer(x) \
+ ScopeTimer func(x);
+#else
+# define Timer(x)
+#endif
+
#endif /* __OPENVDB_UTIL_H__ */
More information about the Bf-blender-cvs
mailing list