You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by na...@apache.org on 2016/06/12 22:13:22 UTC
incubator-quickstep git commit: Add option to enable Google Profiler.
[Forced Update!]
Repository: incubator-quickstep
Updated Branches:
refs/heads/google_profiler 7acd6434d -> f3baf67eb (forced update)
Add option to enable Google Profiler.
Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/f3baf67e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/f3baf67e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/f3baf67e
Branch: refs/heads/google_profiler
Commit: f3baf67eb1979bf9b4f678552396970decf5de03
Parents: 659967a
Author: Navneet Potti <na...@apache.org>
Authored: Sun Jun 12 15:57:39 2016 -0500
Committer: Navneet Potti <na...@apache.org>
Committed: Sun Jun 12 17:12:43 2016 -0500
----------------------------------------------------------------------
CMakeLists.txt | 26 ++++++++++++++++++++++++++
cli/CMakeLists.txt | 6 +++++-
cli/CliConfig.h.in | 1 +
cli/QuickstepCli.cpp | 31 ++++++++++++++++++++++++++++++-
4 files changed, 62 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/f3baf67e/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 207f313..9891e50 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -159,6 +159,32 @@ else()
)
endif()
+# Include Google Perftools CPU Profiler. You probably want to
+# use this option with CMAKE_BUILD_TYPE=RelWithDebInfo.
+# Pass profiler_file_name to quickstep_cli_shell to actually
+# run the profiler. The profiler only starts collecting
+# samples after the first query, so that it runs against a
+# warm buffer pool and caches. If you want to profile everything,
+# including the first query run, set the environment variable
+# CPUPROFILE instead of passing the flag profile_file_name
+# Use google-pprof on the output file to convert it into a useful
+# format like graphviz (dot).
+option(ENABLE_GOOGLE_PROFILER "Include Google Perftools CPU Profiler." OFF)
+
+if (ENABLE_GOOGLE_PROFILER)
+ set_property(
+ DIRECTORY
+ APPEND PROPERTY COMPILE_DEFINITIONS QUICKSTEP_ENABLE_PROFILER
+ )
+
+ # TODO(navsan) Add a FindGperftools.cmake module and use that here.
+ check_include_files("gperftools/profiler.h" HAVE_GPERFTOOLS_PROFILER)
+ if (NOT HAVE_GPERFTOOLS_PROFILER)
+ message(FATAL_ERROR "Could not find gperftools. Ensure that it is installed.")
+ endif()
+ set(LIBS ${LIBS} profiler)
+endif()
+
# Link against the system's threading library.
find_package(Threads REQUIRED)
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/f3baf67e/cli/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt
index faf5040..44ec223 100644
--- a/cli/CMakeLists.txt
+++ b/cli/CMakeLists.txt
@@ -36,6 +36,10 @@ else()
set(GFLAGS_LIB_NAME gflags_nothreads-static)
endif()
+if (ENABLE_GOOGLE_PROFILER)
+ set(QUICKSTEP_ENABLE_GOOGLE_PROFILER TRUE)
+endif()
+
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/CliConfig.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/CliConfig.h"
@@ -106,7 +110,7 @@ target_link_libraries(quickstep_cli_DefaultsConfigurator
if(QUICKSTEP_HAVE_LIBNUMA)
target_link_libraries(quickstep_cli_DefaultsConfigurator
${LIBNUMA_LIBRARY})
-endif()
+endif()
target_link_libraries(quickstep_cli_InputParserUtil
glog
quickstep_utility_Macros
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/f3baf67e/cli/CliConfig.h.in
----------------------------------------------------------------------
diff --git a/cli/CliConfig.h.in b/cli/CliConfig.h.in
index b44dfb7..69f4d8a 100644
--- a/cli/CliConfig.h.in
+++ b/cli/CliConfig.h.in
@@ -17,3 +17,4 @@
#cmakedefine QUICKSTEP_USE_LINENOISE
#cmakedefine QUICKSTEP_OS_WINDOWS
+#cmakedefine QUICKSTEP_ENABLE_GOOGLE_PROFILER
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/f3baf67e/cli/QuickstepCli.cpp
----------------------------------------------------------------------
diff --git a/cli/QuickstepCli.cpp b/cli/QuickstepCli.cpp
index 558d6eb..e2e31ec 100644
--- a/cli/QuickstepCli.cpp
+++ b/cli/QuickstepCli.cpp
@@ -36,7 +36,7 @@
#include <stdlib.h>
#endif
-#include "cli/CliConfig.h" // For QUICKSTEP_USE_LINENOISE.
+#include "cli/CliConfig.h" // For QUICKSTEP_USE_LINENOISE, QUICKSTEP_ENABLE_GOOGLE_PROFILER.
#include "cli/CommandExecutor.hpp"
#include "cli/DropRelation.hpp"
@@ -48,6 +48,10 @@ typedef quickstep::LineReaderLineNoise LineReaderImpl;
typedef quickstep::LineReaderDumb LineReaderImpl;
#endif
+#ifdef QUICKSTEP_ENABLE_GOOGLE_PROFILER
+#include <gperftools/profiler.h>
+#endif
+
#include "cli/DefaultsConfigurator.hpp"
#include "cli/InputParserUtil.hpp"
#include "cli/PrintToScreen.hpp"
@@ -150,6 +154,14 @@ DEFINE_bool(initialize_db, false, "If true, initialize a database.");
DEFINE_bool(print_query, false,
"Print each input query statement. This is useful when running a "
"large number of queries in a batch.");
+DEFINE_string(profile_file_name, "",
+ "If nonempty, enable profiling using GOOGLE CPU Profiler, and write "
+ "its output to the given file name. This flag has no effect if "
+ "ENABLE_GOOGLE_PROFILER CMake flag was not set during build. "
+ "The profiler only starts collecting samples after the first query, "
+ "so that it runs against a warm buffer pool and caches. If you want to profile "
+ "everything, including the first query run, set the "
+ "environment variable CPUPROFILE instead of passing this flag.");
} // namespace quickstep
@@ -335,6 +347,9 @@ int main(int argc, char* argv[]) {
std::unique_ptr<SqlParserWrapper> parser_wrapper(new SqlParserWrapper());
std::chrono::time_point<std::chrono::steady_clock> start, end;
+#ifdef QUICKSTEP_ENABLE_GOOGLE_PROFILER
+ unsigned int query_num = 0;
+#endif
for (;;) {
string *command_string = new string();
*command_string = line_reader.getNextCommand();
@@ -430,6 +445,13 @@ int main(int argc, char* argv[]) {
reset_parser = true;
break;
}
+#ifdef QUICKSTEP_ENABLE_GOOGLE_PROFILER
+ // Profile only if profile_file_name flag is set
+ if (!query_num && !quickstep::FLAGS_profile_file_name.empty()) {
+ ProfilerStart(quickstep::FLAGS_profile_file_name.c_str());
+ }
+ ++query_num;
+#endif
}
if (quitting) {
@@ -440,6 +462,13 @@ int main(int argc, char* argv[]) {
}
}
+#ifdef QUICKSTEP_ENABLE_GOOGLE_PROFILER
+ if (!quickstep::FLAGS_profile_file_name.empty()) {
+ ProfilerStop();
+ ProfilerFlush();
+ }
+#endif
+
// Terminate all workers before exiting.
// The main thread broadcasts poison message to the workers. Each worker dies
// after receiving poison message. The order of workers' death is irrelavant.