20 #include <boost/algorithm/string.hpp>
21 #include <boost/bind.hpp>
22 #include <google/malloc_extension.h>
23 #include <gutil/strings/substitute.h>
33 using namespace google;
34 using namespace impala;
35 using namespace rapidjson;
36 using namespace strings;
40 "The maximum number of bytes to display on the debug webserver's log page");
47 Value log_path(logfile.c_str(), document->GetAllocator());
48 document->AddMember(
"logfile", log_path, document->GetAllocator());
50 struct stat file_stat;
51 if (stat(logfile.c_str(), &file_stat) == 0) {
52 long size = file_stat.st_size;
53 long seekpos = size < FLAGS_web_log_bytes ? 0L : size - FLAGS_web_log_bytes;
54 ifstream log(logfile.c_str(), ios::in);
59 document->AddMember(
"num_bytes", FLAGS_web_log_bytes, document->GetAllocator());
62 Value log_json(ss.str().c_str(), document->GetAllocator());
63 document->AddMember(
"log", log_json, document->GetAllocator());
65 Value error(Substitute(
"Couldn't open INFO log file: $0", logfile).c_str(),
66 document->GetAllocator());
67 document->AddMember(
"error", error, document->GetAllocator());
74 Value title(
"Command-line Flags", document->GetAllocator());
75 document->AddMember(
"title", title, document->GetAllocator());
76 Value flags(CommandlineFlagsIntoString().c_str(), document->GetAllocator());
77 document->AddMember(
"contents", flags, document->GetAllocator());
83 DCHECK(mem_tracker != NULL);
84 Value mem_limit(PrettyPrinter::Print(mem_tracker->
limit(), TUnit::BYTES).c_str(),
85 document->GetAllocator());
86 document->AddMember(
"mem_limit", mem_limit, document->GetAllocator());
88 PrettyPrinter::Print(mem_tracker->
consumption(), TUnit::BYTES).c_str(),
89 document->GetAllocator());
90 document->AddMember(
"consumption", consumption, document->GetAllocator());
93 #ifdef ADDRESS_SANITIZER
94 ss <<
"Memory tracking is not available with address sanitizer builds.";
97 MallocExtension::instance()->GetStats(buf, 2048);
101 Value overview(ss.str().c_str(), document->GetAllocator());
102 document->AddMember(
"overview", overview, document->GetAllocator());
104 if (args.find(
"detailed") != args.end()) {
106 Value detailed(mem_tracker->
LogUsage().c_str(), document->GetAllocator());
107 document->AddMember(
"detailed", detailed, document->GetAllocator());
115 if (process_mem_tracker != NULL) {
120 #ifndef ADDRESS_SANITIZER
122 if (!FLAGS_enable_process_lifetime_heap_profiling) {
int64_t consumption() const
Returns the memory consumed in bytes.
void MemUsageHandler(MemTracker *mem_tracker, const Webserver::ArgumentMap &args, Document *document)
void AddDefaultUrlCallbacks(Webserver *webserver, MemTracker *process_mem_tracker=NULL)
void FlagsHandler(const Webserver::ArgumentMap &args, Document *document)
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 GetFullLogFilename(google::LogSeverity severity, std::string *filename)
DECLARE_bool(enable_process_lifetime_heap_profiling)
void AddPprofUrlCallbacks(Webserver *webserver)
Adds set of path handlers to support pprof profiling of a remote server.
This class is thread-safe.
DEFINE_int64(web_log_bytes, 1024 *1024,"The maximum number of bytes to display on the debug webserver's log page")
void LogsHandler(const Webserver::ArgumentMap &args, Document *document)
std::string LogUsage(const std::string &prefix="") const
Logs the usage of this tracker and all of its children (recursively).