Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: chrome/browser/chromeos/system/syslogs_provider.cc

Issue 7562001: Add memory usage info to SyslogsProvider, and clean up bug report screenshot data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/system/syslogs_provider.cc
diff --git a/chrome/browser/chromeos/system/syslogs_provider.cc b/chrome/browser/chromeos/system/syslogs_provider.cc
index 57c76cfeb9dd5cdb4dce8cc5ca775b1d8d1059bf..b26624c6d67bc21189c87e81d1ba9304a3dfdb6d 100644
--- a/chrome/browser/chromeos/system/syslogs_provider.cc
+++ b/chrome/browser/chromeos/system/syslogs_provider.cc
@@ -4,6 +4,9 @@
#include "chrome/browser/chromeos/system/syslogs_provider.h"
+#include <functional>
+#include <set>
+
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
@@ -11,6 +14,8 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/memory_details.h"
#include "chrome/common/chrome_switches.h"
#include "content/browser/browser_thread.h"
@@ -219,6 +224,78 @@ CancelableRequestProvider::Handle SyslogsProviderImpl::RequestSyslogs(
return request->handle();
}
stevenjb 2011/08/03 01:55:20 Actual new code.
+// Derived class from memoryDetails converts the results into a single string
+// and adds a "mem_usage" entry to the logs, then forwards the result.
+// Format of entry is (one process per line, reverse-sorted by size):
+// Tab [Title1|Title2]: 50 MB
+// Browser: 30 MB
+// Tab [Title]: 20 MB
+// Extension [Title]: 10 MB
+// ...
+class SyslogsMemoryHandler : public MemoryDetails {
+ public:
+ typedef SyslogsProvider::ReadCompleteCallback ReadCompleteCallback;
+
+ // |logs| is modified (see comment above) and passed to |request|.
+ // |zip_content| is passed to |request|.
+ SyslogsMemoryHandler(
+ scoped_refptr<CancelableRequest<ReadCompleteCallback> > request,
+ LogDictionaryType* logs,
+ std::string* zip_content)
+ : request_(request),
+ logs_(logs),
+ zip_content_(zip_content) {
+ }
+
+ virtual void OnDetailsAvailable() OVERRIDE {
+ const ProcessData& chrome = processes()[0]; // Chrome is the first entry.
+ // Process info, sorted by memory used (highest to lowest).
+ typedef std::pair<size_t, std::string> ProcInfo;
+ typedef std::set<ProcInfo, std::greater<ProcInfo> > ProcInfoSet;
+ ProcInfoSet process_info;
+ for (ProcessMemoryInformationList::const_iterator iter1 =
+ chrome.processes.begin();
+ iter1 != chrome.processes.end(); ++iter1) {
+ std::string process_string(
+ ChildProcessInfo::GetFullTypeNameInEnglish(
+ iter1->type, iter1->renderer_type));
+ if (!iter1->titles.empty()) {
+ std::string titles(" [");
+ for (std::vector<string16>::const_iterator iter2 =
+ iter1->titles.begin();
+ iter2 != iter1->titles.end(); ++iter2) {
+ if (iter2 != iter1->titles.begin())
+ titles += "|";
+ titles += UTF16ToUTF8(*iter2);
+ }
+ titles += "]";
+ process_string += titles;
+ }
+ // Use private working set for memory used calculation.
+ size_t ws_bytes = iter1->working_set.priv / 1024;
James Cook 2011/08/03 17:06:49 If you're dividing by 1024, this isn't bytes. ws_
stevenjb 2011/08/03 19:11:39 Done.
+ process_info.insert(std::make_pair(ws_bytes, process_string));
+ }
+ // Add one line for each reverse-sorted entry.
+ std::string mem_string;
+ for (ProcInfoSet::iterator iter = process_info.begin();
+ iter != process_info.end(); ++iter) {
+ mem_string += iter->second + StringPrintf(": %u MB", iter->first) + "\n";
+ }
+ (*logs_)["mem_usage"] = mem_string;
+ // This will call the callback on the calling thread.
+ request_->ForwardResult(
+ Tuple2<LogDictionaryType*, std::string*>(logs_, zip_content_));
+ }
+
+ private:
+ virtual ~SyslogsMemoryHandler() {}
+
+ scoped_refptr<CancelableRequest<ReadCompleteCallback> > request_;
+ LogDictionaryType* logs_;
+ std::string* zip_content_;
+ DISALLOW_COPY_AND_ASSIGN(SyslogsMemoryHandler);
+};
+
// Called from FILE thread.
void SyslogsProviderImpl::ReadSyslogs(
scoped_refptr<CancelableRequest<ReadCompleteCallback> > request,
@@ -253,12 +330,14 @@ void SyslogsProviderImpl::ReadSyslogs(
file_util::Delete(zip_file, false);
}
- // Will call the callback on the calling thread.
- request->ForwardResult(Tuple2<LogDictionaryType*,
- std::string*>(logs, zip_content));
+ // SyslogsMemoryHandler will clean itself up.
+ // SyslogsMemoryHandler::OnDetailsAvailable() will modify |logs| and call
+ // request->ForwardResult(logs, zip_content).
+ scoped_refptr<SyslogsMemoryHandler>
+ handler(new SyslogsMemoryHandler(request, logs, zip_content));
+ handler->StartFetch();
}
-
void SyslogsProviderImpl::LoadCompressedLogs(const FilePath& zip_file,
std::string* zip_content) {
DCHECK(zip_content);

Powered by Google App Engine
This is Rietveld 408576698