17 #include <boost/bind.hpp>
20 #include <google/profiler.h>
21 #include <google/heap-profiler.h>
22 #include <google/malloc_extension.h>
29 using namespace google;
30 using namespace impala;
31 using namespace rapidjson;
37 typedef boost::function<void
46 Value output(ss.str().c_str(), document->GetAllocator());
47 document->AddMember(
"contents", output, document->GetAllocator());
53 ifstream cmd_line_file(
"/proc/self/cmdline", ios::in);
54 if (!cmd_line_file.is_open()) {
55 (*output) <<
"Unable to open file: /proc/self/cmdline";
58 (*output) << cmd_line_file.rdbuf();
59 cmd_line_file.close();
67 #ifdef ADDRESS_SANITIZER
68 (*output) <<
"Heap profiling is not available with address sanitizer builds.";
70 Webserver::ArgumentMap::const_iterator it = args.find(
"seconds");
72 if (it != args.end()) {
73 seconds = atoi(it->second.c_str());
76 HeapProfilerStart(FLAGS_heap_profile_dir.c_str());
79 const char* profile = GetHeapProfile();
90 #ifdef ADDRESS_SANITIZER
91 (*output) <<
"CPU profiling is not available with address sanitizer builds.";
93 Webserver::ArgumentMap::const_iterator it = args.find(
"seconds");
95 if (it != args.end()) {
96 seconds = atoi(it->second.c_str());
98 ostringstream tmp_prof_file_name;
100 tmp_prof_file_name <<
"/tmp/impala_cpu_profile." << getpid() <<
"." << rand();
101 ProfilerStart(tmp_prof_file_name.str().c_str());
104 ifstream prof_file(tmp_prof_file_name.str().c_str(), ios::in);
105 if (!prof_file.is_open()) {
106 (*output) <<
"Unable to open cpu profile: " << tmp_prof_file_name;
109 (*output) << prof_file.rdbuf();
118 #ifdef ADDRESS_SANITIZER
119 (*output) <<
"Growth profiling is not available with address sanitizer builds.";
121 string heap_growth_stack;
122 MallocExtension::instance()->GetHeapGrowthStacks(&heap_growth_stack);
123 (*output) << heap_growth_stack;
147 (*output) <<
"num_symbols: 0";
void PprofCpuProfileHandler(const Webserver::ArgumentMap &args, stringstream *output)
void PprofHeapHandler(const Webserver::ArgumentMap &args, stringstream *output)
void PprofGrowthHandler(const Webserver::ArgumentMap &args, stringstream *output)
boost::function< void(const Webserver::ArgumentMap &args, std::stringstream *output)> PprofCallback
void RegisterUrlCallback(const std::string &path, const std::string &template_filename, const UrlCallback &callback, bool is_on_nav_bar=true)
Only one callback may be registered per URL.
std::map< std::string, std::string > ArgumentMap
void PprofCmdLineHandler(const Webserver::ArgumentMap &args, stringstream *output)
const int PPROF_DEFAULT_SAMPLE_SECS
void AddPprofUrlCallbacks(Webserver *webserver)
Adds set of path handlers to support pprof profiling of a remote server.
void PprofSymbolHandler(const Webserver::ArgumentMap &args, stringstream *output)
DECLARE_string(heap_profile_dir)
void PprofJsonHandler(const PprofCallback &callback, const Webserver::ArgumentMap &args, Document *document)