[Bf-blender-cvs] [13d8671] master: Cycles: Add support of Glog logging

Sergey Sharybin noreply at git.blender.org
Thu Sep 25 13:16:57 CEST 2014


Commit: 13d8671a1a71e77ca3c6b1ce3d13d200ddd778d1
Author: Sergey Sharybin
Date:   Mon Sep 8 18:01:24 2014 +0600
Branches: master
https://developer.blender.org/rB13d8671a1a71e77ca3c6b1ce3d13d200ddd778d1

Cycles: Add support of Glog logging

This commit makes it possible to use Glog library for the debug logging.
For now only possible when using CMake and in order to use the logging
the WITH_CYCLES_LOGGING configuration variable is to be enabled.

When this option is not enabled or when using Scons there's no difference
in Cycles behavior at all, when using logging and no output to the console
impact is gonna to be minimal.

This is done in order to make it possible to have debug logging persistent
in code (without need to add it when troubleshooting some bug and removing
it afterwards).

For now actual logging is not placed yet, only all the functions needed for
the logging are written and so.

===================================================================

M	CMakeLists.txt
M	extern/libmv/CMakeLists.txt
M	intern/cycles/CMakeLists.txt
M	intern/cycles/blender/CCL_api.h
M	intern/cycles/blender/CMakeLists.txt
A	intern/cycles/blender/blender_logging.cpp
M	intern/cycles/util/CMakeLists.txt
A	intern/cycles/util/util_logging.cpp
A	intern/cycles/util/util_logging.h
M	source/creator/CMakeLists.txt
M	source/creator/creator.c

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1dd9721..2cabeb6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -280,6 +280,7 @@ option(WITH_CYCLES_CUDA_BINARIES	"Build cycles CUDA binaries" OFF)
 set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 sm_50 CACHE STRING "CUDA architectures to build binaries for")
 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
 unset(PLATFORM_DEFAULT)
+option(WITH_CYCLES_LOGGING	"Build cycles with logging support" OFF)
 
 # LLVM
 option(WITH_LLVM					"Use LLVM" OFF)
diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt
index d482819..6a4a61e 100644
--- a/extern/libmv/CMakeLists.txt
+++ b/extern/libmv/CMakeLists.txt
@@ -240,7 +240,7 @@ if(WITH_LIBMV)
 endif()
 
 # make GLog a separate target, so it can be used for gtest as well.
-if(WITH_LIBMV OR WITH_GTESTS)
+if(WITH_LIBMV OR WITH_GTESTS OR WITH_CYCLES_LOGGING)
 	# We compile GLog together with GFlag so we don't worry about
 	# adding extra lib to linker.
 	set(GLOG_SRC
diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt
index ccf6aac..bfd29dc 100644
--- a/intern/cycles/CMakeLists.txt
+++ b/intern/cycles/CMakeLists.txt
@@ -128,6 +128,24 @@ add_definitions(
 	-DWITH_MULTI
 )
 
+if(WITH_CYCLES_LOGGING)
+	add_definitions(-DWITH_CYCLES_LOGGING)
+	add_definitions(-DGOOGLE_GLOG_DLL_DECL=)
+	if(WIN32)
+		include_directories(
+			SYSTEM
+			../../extern/libmv/third_party/glog/src/windows
+			../../extern/libmv/third_party/gflags
+		)
+	else()
+		include_directories(
+			SYSTEM
+			../../extern/libmv/third_party/glog/src
+			../../extern/libmv/third_party/gflags
+		)
+	endif()
+endif()
+
 include_directories(
 	SYSTEM
 	${BOOST_INCLUDE_DIR}
diff --git a/intern/cycles/blender/CCL_api.h b/intern/cycles/blender/CCL_api.h
index 2772b9a..cfd0c3e 100644
--- a/intern/cycles/blender/CCL_api.h
+++ b/intern/cycles/blender/CCL_api.h
@@ -36,6 +36,10 @@ CCLDeviceInfo *CCL_compute_device_list(int device_type);
 
 void *CCL_python_module_init(void);
 
+void CCL_init_logging(const char *argv0);
+void CCL_start_debug_logging(void);
+void CCL_logging_verbosity_set(int verbosity);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/intern/cycles/blender/CMakeLists.txt b/intern/cycles/blender/CMakeLists.txt
index 548aac8..13ac0be 100644
--- a/intern/cycles/blender/CMakeLists.txt
+++ b/intern/cycles/blender/CMakeLists.txt
@@ -25,6 +25,7 @@ set(SRC
 	blender_object.cpp
 	blender_particles.cpp
 	blender_curves.cpp
+	blender_logging.cpp
 	blender_python.cpp
 	blender_session.cpp
 	blender_shader.cpp
diff --git a/intern/cycles/blender/blender_logging.cpp b/intern/cycles/blender/blender_logging.cpp
new file mode 100644
index 0000000..d3f1acc
--- /dev/null
+++ b/intern/cycles/blender/blender_logging.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2011-2014 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#include "CCL_api.h"
+
+#include <stdio.h>
+
+#include "util_logging.h"
+
+#ifdef _MSC_VER
+#  define snprintf _snprintf
+#endif
+
+void CCL_init_logging(const char *argv0)
+{
+#ifdef WITH_CYCLES_LOGGING
+	/* Make it so FATAL messages are always print into console. */
+	char severity_fatal[32];
+	snprintf(severity_fatal, sizeof(severity_fatal), "%d",
+	         google::GLOG_FATAL);
+
+	google::InitGoogleLogging(argv0);
+	google::SetCommandLineOption("logtostderr", "1");
+	google::SetCommandLineOption("v", "0");
+	google::SetCommandLineOption("stderrthreshold", severity_fatal);
+	google::SetCommandLineOption("minloglevel", severity_fatal);
+#else
+	(void) argv0;
+#endif
+}
+
+void CCL_start_debug_logging(void)
+{
+#ifdef WITH_CYCLES_LOGGING
+	google::SetCommandLineOption("logtostderr", "1");
+	google::SetCommandLineOption("v", "2");
+	google::SetCommandLineOption("stderrthreshold", "1");
+	google::SetCommandLineOption("minloglevel", "0");
+#endif
+}
+
+void CCL_logging_verbosity_set(int verbosity)
+{
+#ifdef WITH_CYCLES_LOGGING
+	char val[10];
+	snprintf(val, sizeof(val), "%d", verbosity);
+
+	google::SetCommandLineOption("v", val);
+#else
+	(void) verbosity;
+#endif
+}
diff --git a/intern/cycles/util/CMakeLists.txt b/intern/cycles/util/CMakeLists.txt
index d9b97a7..6120e7e 100644
--- a/intern/cycles/util/CMakeLists.txt
+++ b/intern/cycles/util/CMakeLists.txt
@@ -11,6 +11,7 @@ set(INC_SYS
 set(SRC
 	util_cache.cpp
 	util_dynlib.cpp
+	util_logging.cpp
 	util_md5.cpp
 	util_path.cpp
 	util_string.cpp
@@ -40,6 +41,7 @@ set(SRC_HEADERS
 	util_hash.h
 	util_image.h
 	util_list.h
+	util_logging.h
 	util_map.h
 	util_math.h
 	util_md5.h
diff --git a/intern/cycles/blender/CCL_api.h b/intern/cycles/util/util_logging.cpp
similarity index 51%
copy from intern/cycles/blender/CCL_api.h
copy to intern/cycles/util/util_logging.cpp
index 2772b9a..0722f16 100644
--- a/intern/cycles/blender/CCL_api.h
+++ b/intern/cycles/util/util_logging.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011-2013 Blender Foundation
+ * Copyright 2011-2014 Blender Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,30 +14,20 @@
  * limitations under the License
  */
 
-#ifndef __CCL_API_H__
-#define __CCL_API_H__
+#include <util_logging.h>
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "util_math.h"
 
-/* returns a list of devices for selection, array is empty identifier
- * terminated and must not be freed */
+CCL_NAMESPACE_BEGIN
 
-typedef struct CCLDeviceInfo {
-	char identifier[128];
-	char name[512];
-	int value;
-} CCLDeviceInfo;
-
-CCLDeviceInfo *CCL_compute_device_list(int device_type);
-
-/* create python module _cycles used by addon */
-
-void *CCL_python_module_init(void);
-
-#ifdef __cplusplus
+std::ostream& operator <<(std::ostream &os,
+                          const float3 &value)
+{
+	os << "(" << value.x
+	   << ", " << value.y
+	   << ", " << value.z
+	   << ")";
+	return os;
 }
-#endif
 
-#endif /* __CCL_API_H__ */
+CCL_NAMESPACE_END
diff --git a/intern/cycles/util/util_logging.h b/intern/cycles/util/util_logging.h
new file mode 100644
index 0000000..2bd0fac
--- /dev/null
+++ b/intern/cycles/util/util_logging.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2011-2014 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#ifndef __UTIL_LOGGING_H__
+#define __UTIL_LOGGING_H__
+
+#if defined(WITH_CYCLES_LOGGING) && !defined(__KERNEL_GPU__)
+#  include <glog/logging.h>
+#else
+#  include <iostream>
+#endif
+
+CCL_NAMESPACE_BEGIN
+
+#if !defined(WITH_CYCLES_LOGGING) || defined(__KERNEL_GPU__)
+class StubStream : public std::ostream {
+ public:
+	StubStream () { }
+};
+
+class LogMessageVoidify {
+public:
+	LogMessageVoidify() { }
+	void operator&(::std::ostream&) { }
+};
+
+#  define LOG_SUPPRESS() (true) ? (void) 0 : LogMessageVoidify() & StubStream()
+#  define LOG(severity) LOG_SUPPRESS()
+#  define VLOG(severity) LOG_SUPPRESS()
+
+#endif
+
+class float3;
+
+std::ostream& operator <<(std::ostream &os,
+                          const float3 &value);
+
+CCL_NAMESPACE_END
+
+#endif /* __UTIL_LOGGING_H__ */
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt
index 6ed87f6..35cbff3 100644
--- a/source/creator/CMakeLists.txt
+++ b/source/creator/CMakeLists.txt
@@ -48,6 +48,11 @@ if(WITH_LIBMV)
 	add_definitions(-DWITH_LIBMV)
 endif()
 
+if(WITH_CYCLES AND WITH_CYCLES_LOGGING)
+	blender_include_dirs(../../intern/cycles/blender)
+	add_definitions(-DWITH_CYCLES_LOGGING)
+endif()
+
 if(WITH_CODEC_FFMPEG)
 	add_definitions(-DWITH_FFMPEG)
 endif()
diff --git a/source/creator/creator.c b/source/creator/creator.c
index 3937ae1..3511c9d 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -149,6 +149,10 @@
 #  include "libmv-capi.h"
 #endif
 
+#ifdef WITH_CYCLES_LOGGING
+#  include "CCL_api.h"
+#endif
+
 /* from buildinfo.c */
 #ifdef BUILD_DATE
 extern char build_date[];
@@ -309,6 +313,9 @@ static int print_help(int UNUSED(argc), const char **UNUSED(argv), void *data)
 #ifdef WITH_LIBMV
 	BLI_argsPrintArgDoc(ba, "--debug-libmv");
 #endif
+#ifdef WITH_CYCLES_LOGGING
+	BLI_argsPrintArgDoc(ba, "--debug-cycles");
+#endif
 	BLI_argsPrintArgDoc(ba, "--debug-memory");
 	BLI_argsPrintArgDoc(ba, "--debug-jobs");
 	BLI_argsPrintArgDoc(ba, "--debug-python");
@@ -450,6 +457,15 @@ static int debug_mode_libmv(int UNUSED(argc), const char **UNUSED(argv), void *U
 }
 #endif
 
+#ifdef WITH_CYCLES_LOGGING
+static int debug_mode_cycles(int UNUSED(argc), const char **UNUSED(argv),
+                             void *UNUSED(data))
+{
+	CCL_start_debug_logging();
+	return 0;
+}
+#endif
+
 static int debug_mode_memory(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
 {
 	MEM_set_memory_debug();
@@ -887,6 +903,8 @@ static int set_verbosity(int argc, const char **argv, void *UNUSED(data))
 
 #ifdef WITH_LIBMV
 		libmv_setLoggingVerbosity(level);
+#elif defined(WITH_CYCLES_LOGGING)
+		CCL_logging_verbosity_set(level);
 #else
 		(void)level;
 #endif
@@ -1419,6 +1437,9 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
 #ifdef WITH_LIBMV
 	BLI_argsAdd(ba, 1, NULL, "--debug-libmv", "\n\tEnable debug messages from libmv library", debug_mode_libmv, NULL);
 #endif
+#ifdef WITH_CYCLES_LOGGING
+	BL

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list