From c2028b5519fd3bf95c864e6e0c12b1c946b7220f Mon Sep 17 00:00:00 2001 From: "primiano@chromium.org" Date: Wed, 12 Mar 2014 21:13:34 +0000 Subject: Add HTML frontend to memory_inspector. This adds the basic infrastructure for the web based ui: - A python-based www server. - The HTML/JS client. At the current state, the only functionality available is listing processes/device stats. BUG=340294 NOTRY=true Review URL: https://codereview.chromium.org/190853010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256646 0039d316-1c4b-4281-b951-d872f2087c98 --- .../memory_inspector/core/backends.py | 5 + .../memory_inspector/data/file_storage.py | 3 +- .../memory_inspector/frontends/__init__.py | 0 .../frontends/www_content/index.html | 159 +++++++++++ .../frontends/www_content/js/devices.js | 79 ++++++ .../frontends/www_content/js/processes.js | 183 ++++++++++++ .../frontends/www_content/js/rootUi.js | 41 +++ .../frontends/www_content/js/timers.js | 38 +++ .../frontends/www_content/js/webservice.js | 30 ++ .../frontends/www_content/rootUi.css | 143 ++++++++++ .../memory_inspector/frontends/www_server.py | 311 +++++++++++++++++++++ tools/memory_inspector/start_web_ui | 17 ++ 12 files changed, 1008 insertions(+), 1 deletion(-) create mode 100644 tools/memory_inspector/memory_inspector/frontends/__init__.py create mode 100644 tools/memory_inspector/memory_inspector/frontends/www_content/index.html create mode 100644 tools/memory_inspector/memory_inspector/frontends/www_content/js/devices.js create mode 100644 tools/memory_inspector/memory_inspector/frontends/www_content/js/processes.js create mode 100644 tools/memory_inspector/memory_inspector/frontends/www_content/js/rootUi.js create mode 100644 tools/memory_inspector/memory_inspector/frontends/www_content/js/timers.js create mode 100644 tools/memory_inspector/memory_inspector/frontends/www_content/js/webservice.js create mode 100644 tools/memory_inspector/memory_inspector/frontends/www_content/rootUi.css create mode 100644 tools/memory_inspector/memory_inspector/frontends/www_server.py create mode 100755 tools/memory_inspector/start_web_ui (limited to 'tools') diff --git a/tools/memory_inspector/memory_inspector/core/backends.py b/tools/memory_inspector/memory_inspector/core/backends.py index 747875a..aa4c6c6 100644 --- a/tools/memory_inspector/memory_inspector/core/backends.py +++ b/tools/memory_inspector/memory_inspector/core/backends.py @@ -11,6 +11,11 @@ def Register(backend): _backends[backend.name] = backend +def ListBackends(): + """Enumerates all the backends.""" + return _backends.itervalues() + + def ListDevices(): """Enumerates all the devices from all the registered backends.""" for backend in _backends.itervalues(): diff --git a/tools/memory_inspector/memory_inspector/data/file_storage.py b/tools/memory_inspector/memory_inspector/data/file_storage.py index 407076f..ff888ba 100644 --- a/tools/memory_inspector/memory_inspector/data/file_storage.py +++ b/tools/memory_inspector/memory_inspector/data/file_storage.py @@ -48,7 +48,8 @@ class Storage(object): assert(isinstance(settings, dict)) file_path = os.path.join(self._root, Storage._SETTINGS_FILE % name) if not settings: - os.unlink(file_path) + if os.path.exists(file_path): + os.unlink(file_path) return with open(file_path, 'w') as f: return json.dump(settings, f) diff --git a/tools/memory_inspector/memory_inspector/frontends/__init__.py b/tools/memory_inspector/memory_inspector/frontends/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/memory_inspector/memory_inspector/frontends/www_content/index.html b/tools/memory_inspector/memory_inspector/frontends/www_content/index.html new file mode 100644 index 0000000..eaf8a3f --- /dev/null +++ b/tools/memory_inspector/memory_inspector/frontends/www_content/index.html @@ -0,0 +1,159 @@ + + + + + + Memory Inspector + + + + + + + + + + + + + + +
+

Memory Inspector

+
+ + +
+
+ Device: + + +
+
+ +
+
+
+
+
+
+
+
+
+ +
+ + +
+
+
+ +
+
+ + Current metric: + + + + Current snapshot: + of + +
+

Hierarchical view of selected snapshot

+
+ +
+ +
+ +
+ +
+
+
+ Filters: + + Prot. flags: + File name: + +
+
+ Totals: + Priv dirty (Kb): 0 + Priv clean (Kb): 0 + Shared dirty (Kb): 0 + Shared clean (Kb): 0 +
+
+ Note: totals from this filtered table might not match the totals in the treemap, as table filtering is not hierarchical. +
+
+
+
+ +
+
+ + Current metric: + + + + Current snapshot: + of + +
+

Hierarchical view of selected snapshot

+
+
+
+
+
+
+ +
+ + + +
+
+
+ +
+
+ + +
+
+
+
+
+
+ +
+
+
Progress...
+
+ +
+ Loading JavaScript content. If you see this message something has probably gone wrong. Check JS console. +
+ + + \ No newline at end of file diff --git a/tools/memory_inspector/memory_inspector/frontends/www_content/js/devices.js b/tools/memory_inspector/memory_inspector/frontends/www_content/js/devices.js new file mode 100644 index 0000000..b4c4ce2 --- /dev/null +++ b/tools/memory_inspector/memory_inspector/frontends/www_content/js/devices.js @@ -0,0 +1,79 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +devices = new (function() { + +this.backends_ = []; // ['Android', 'Linux'] +this.devices_ = {}; // 'Android/a1b2' -> {.backend, .name, .id} +this.selDeviceUri_ = null; + +this.onDomReady_ = function() { + $('#refresh-devices').on('click', this.refresh.bind(this)); + $('#devices').on('change', this.onDeviceSelectionChange_.bind(this)); + this.refresh(); +}; + +this.getSelectedURI = function() { + return this.selDeviceUri_; +}; + +this.getAllBackends = function() { + // Returns a list of the registered backends, e.g., ['Android', 'Linux']. + return this.backends_; +}; + +this.getAllDevices = function() { + // Returns a list of devices [{backend:'Android', name:'N7', id:'1234'}]. + return Object.keys(this.devices_).map(function(k) { + return this.devices_[k]; + }, this); +}; + +this.refresh = function() { + webservice.ajaxRequest('/devices', this.onDevicesAjaxResponse_.bind(this)); + webservice.ajaxRequest('/backends', this.onBackendsAjaxResponse_.bind(this)); +}; + +this.onBackendsAjaxResponse_ = function(data) { + if (!data || !data.length) + { + rootUi.ShowDialog('No backends detected! Memory Inspector looks terribly' + + ' broken. Please file a bug'); + } + this.backends_ = data; +}; + +this.onDevicesAjaxResponse_ = function(data) { + var devList = $('#devices'); + devList.empty(); + this.devices_ = {}; + data.forEach(function(device) { + var deviceUri = device.backend + '/' + device.id; + var deviceFullTime = device.backend + ' : ' + + device.name + ' [' + device.id + ']'; + devList.append($('