]> git.mxchange.org Git - flightgear.git/commitdiff
Optional profiling commands using gperftools
authorThomas Geymayer <tomgey@gmail.com>
Thu, 15 Nov 2012 10:55:25 +0000 (11:55 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Thu, 15 Nov 2012 10:55:37 +0000 (11:55 +0100)
CMakeLists.txt
src/Main/CMakeLists.txt
src/Main/fg_commands.cxx

index 3013e9566a512ef8b3f6bee293ea86e721371037..fe0af050040536ad4e72d5704ebb7d7726f6eb90 100644 (file)
@@ -223,6 +223,9 @@ check_include_file(unistd.h   HAVE_UNISTD_H)
 check_include_file(sys/time.h HAVE_SYS_TIME_H)
 check_include_file(windows.h  HAVE_WINDOWS_H)
 
+# check optionally supported dependencies
+find_package(GooglePerfTools)
+
 if(ENABLE_RTI)
     find_package(RTI)
     if(RTI_FOUND)
index 6ea3419e487d6ebee81a4fb96c086a4265d47c7b..72ed8634a6697df5324ac0745bdd633423cd24c7 100644 (file)
@@ -90,6 +90,10 @@ if(ENABLE_JSBSIM)
     target_link_libraries(fgfs JSBSim)
 endif()
 
+if(GOOGLE_PERFTOOLS_FOUND)
+    target_link_libraries(fgfs profiler)
+endif()
+
 target_link_libraries(fgfs
        ${SQLITE3_LIBRARY}
        ${SIMGEAR_LIBRARIES}
index 75a5e2fbfd862c5865f23054d1deb758608ea876..1e32ef6b2b1efd810d974846322218b7185d37ab 100644 (file)
 
 #include <boost/scoped_array.hpp>
 
+#if GOOGLE_PERFTOOLS_FOUND == YES
+# include <google/profiler.h>
+#endif
+
 using std::string;
 using std::ifstream;
 using std::ofstream;
 
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // Static helper functions.
 ////////////////////////////////////////////////////////////////////////
@@ -1446,7 +1449,48 @@ do_release_cockpit_button (const SGPropertyNode *arg)
 
   return true;
 }
-  
+
+// Optional profiling commands using gperftools:
+// http://code.google.com/p/gperftools/
+
+#if GOOGLE_PERFTOOLS_FOUND != YES
+static void
+no_profiling_support()
+{
+  SG_LOG
+  (
+    SG_GENERAL,
+    SG_WARN,
+    "No profiling support! Install gperftools and reconfigure/rebuild fgfs."
+  );
+}
+#endif
+
+static bool
+do_profiler_start(const SGPropertyNode *arg)
+{
+#if GOOGLE_PERFTOOLS_FOUND == YES
+  const char *filename = arg->getStringValue("filename", "fgfs.profile");
+  ProfilerStart(filename);
+  return true;
+#else
+  no_profiling_support();
+  return false;
+#endif
+}
+
+static bool
+do_profiler_stop(const SGPropertyNode *arg)
+{
+#if GOOGLE_PERFTOOLS_FOUND == YES
+  ProfilerStop();
+  return true;
+#else
+  no_profiling_support();
+  return false;
+#endif
+}
+
 ////////////////////////////////////////////////////////////////////////
 // Command setup.
 ////////////////////////////////////////////////////////////////////////
@@ -1521,6 +1565,11 @@ static struct {
     { "reload-shaders", do_reload_shaders },
     { "reload-materials", do_materials_reload },
 
+#if GOOGLE_PERFTOOLS_FOUND == YES
+    { "profiler-start", do_profiler_start },
+    { "profiler-stop",  do_profiler_stop },
+#endif
+
     { 0, 0 }                   // zero-terminated
 };