CrOS: Add Discard Tab command link to about:discards

Work in process on discarding a tab (for low memory conditions on CrOS).  Also clean up the strings we use to describe system memory, and eliminate memory as an input for "interestingness" of tabs, since the OOM killer already includes memory as an input.

BUG=none
TEST=Open "about:discards".  Click the "Discard Tab Now" link - the tab at the bottom of the list should close.

Review URL: http://codereview.chromium.org/7983042

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102397 0039d316-1c4b-4281-b951-d872f2087c98
parent e7ea0c62
......@@ -676,8 +676,13 @@ std::string AboutCryptohome(const std::string& query) {
return GetCryptohomeHtmlInfo(refresh);
}
std::string AboutDiscards() {
std::string AboutDiscards(const std::string& path) {
std::string output;
const std::string kRunCommand("run");
if (path == kRunCommand) {
output.append(WrapWithTag("p", "Discarding a tab..."));
g_browser_process->oom_priority_manager()->DiscardTab();
}
AppendHeader(&output, 0, "About discards");
AppendBody(&output);
output.append("<h3>About discards</h3>");
......@@ -698,28 +703,30 @@ std::string AboutDiscards() {
} else {
output.append("<p>None found. Wait 10 seconds, then refresh.</p>");
}
output.append(
"<a href='chrome://discards/" + kRunCommand + "'>Discard tab now</a>");
base::SystemMemoryInfoKB meminfo;
base::GetSystemMemoryInfo(&meminfo);
output.append("<h3>System memory information in MB</h3>");
output.append("<table>");
output.append(AddStringRow(
"Total Memory", base::IntToString(meminfo.total / 1024)));
"Total", base::IntToString(meminfo.total / 1024)));
output.append(AddStringRow(
"Free Memory", base::IntToString(meminfo.free / 1024)));
"Free", base::IntToString(meminfo.free / 1024)));
output.append(AddStringRow(
"Buffered Memory", base::IntToString(meminfo.buffers / 1024)));
"Buffered", base::IntToString(meminfo.buffers / 1024)));
output.append(AddStringRow(
"Cached Memory", base::IntToString(meminfo.cached / 1024)));
"Cached", base::IntToString(meminfo.cached / 1024)));
output.append(AddStringRow(
"Committed Memory", base::IntToString(
"Committed", base::IntToString(
(meminfo.total - meminfo.free - meminfo.buffers - meminfo.cached) / 1024)));
output.append(AddStringRow(
"Active Anon Memory", base::IntToString(meminfo.active_anon / 1024)));
"Active Anon", base::IntToString(meminfo.active_anon / 1024)));
output.append(AddStringRow(
"Inactive Anon Memory", base::IntToString(meminfo.inactive_anon / 1024)));
"Inactive Anon", base::IntToString(meminfo.inactive_anon / 1024)));
output.append(AddStringRow(
"Shared Memory", base::IntToString(meminfo.shmem / 1024)));
"Shared", base::IntToString(meminfo.shmem / 1024)));
output.append("</table>");
AppendFooter(&output);
......@@ -1406,7 +1413,7 @@ void AboutSource::StartDataRequest(const std::string& path,
} else if (host == chrome::kChromeUICryptohomeHost) {
response = AboutCryptohome(path);
} else if (host == chrome::kChromeUIDiscardsHost) {
response = AboutDiscards();
response = AboutDiscards(path);
#endif
} else if (host == chrome::kChromeUIDNSHost) {
AboutDnsHandler::Start(this, request_id);
......
This diff is collapsed.
......@@ -17,6 +17,8 @@
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
class TabContents;
namespace browser {
// The OomPriorityManager periodically checks (see
......@@ -26,11 +28,8 @@ namespace browser {
// algorithm embedded here for priority in being killed upon OOM
// conditions.
//
// The algorithm used favors killing tabs that are not pinned, have
// been idle for longest, and take up the most memory, in that order
// of priority. We round the idle times to the nearest few minutes
// (see BUCKET_INTERVAL_MINUTES in the source) so that we can bucket
// them, as no two tabs will have exactly the same idle time.
// The algorithm used favors killing tabs that are not selected, not pinned,
// and have been idle for longest, in that order of priority.
class OomPriorityManager : public NotificationObserver {
public:
OomPriorityManager();
......@@ -43,35 +42,38 @@ class OomPriorityManager : public NotificationObserver {
// to least interesting (OK to kill).
std::vector<string16> GetTabTitles();
// Discards a tab to free the memory occupied by its renderer.
// Tab still exists in the tab-strip; clicking on it will reload it.
void DiscardTab();
private:
struct RendererStats {
RendererStats();
~RendererStats();
struct TabStats {
TabStats();
~TabStats();
bool is_pinned;
bool is_selected;
base::TimeTicks last_selected;
size_t memory_used;
base::ProcessHandle renderer_handle;
string16 title;
int64 tab_contents_id; // unique ID per TabContents
};
typedef std::vector<RendererStats> StatsList;
typedef base::hash_map<base::ProcessHandle, int> ProcessScoreMap;
typedef std::vector<TabStats> TabStatsList;
// Posts DoAdjustOomPriorities task to the file thread. Called when
// the timer fires.
TabStatsList GetTabStatsOnUIThread();
// Called when the timer fires, sets oom_adjust_score for all renderers.
void AdjustOomPriorities();
// Called by AdjustOomPriorities.
void AdjustOomPrioritiesOnFileThread(TabStatsList stats_list);
// Posts AdjustFocusedTabScore task to the file thread.
void OnFocusTabScoreAdjustmentTimeout();
// Called by AdjustOomPriorities. Runs on the file thread.
void DoAdjustOomPriorities();
// Sets the score of the focused tab to the least value.
void AdjustFocusedTabScoreOnFileThread();
// Called when a tab comes into focus. Runs on the file thread.
// Sets the score of only the currently focused tab to the least value.
void AdjustFocusedTabScore();
static bool CompareRendererStats(RendererStats first, RendererStats second);
static bool CompareTabStats(TabStats first, TabStats second);
virtual void Observe(int type,
const NotificationSource& source,
......@@ -79,14 +81,13 @@ class OomPriorityManager : public NotificationObserver {
base::RepeatingTimer<OomPriorityManager> timer_;
base::OneShotTimer<OomPriorityManager> focus_tab_score_adjust_timer_;
// renderer_stats_ is used on both UI and file threads.
base::Lock renderer_stats_lock_;
StatsList renderer_stats_;
NotificationRegistrar registrar_;
// This lock is for pid_to_oom_score_ and focus_tab_pid_.
base::Lock pid_to_oom_score_lock_;
// map maintaining the process - oom_score mapping.
typedef base::hash_map<base::ProcessHandle, int> ProcessScoreMap;
ProcessScoreMap pid_to_oom_score_;
NotificationRegistrar registrar_;
base::ProcessHandle focused_tab_pid_;
DISALLOW_COPY_AND_ASSIGN(OomPriorityManager);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment