summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorpetrcermak <petrcermak@chromium.org>2015-01-14 10:02:39 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-14 18:03:25 +0000
commit2ddff339b83714e75c8da7d0be99dbc3b4c3213b (patch)
tree3a35dc1260505d3db82a3494d65b80f7b73d40d8 /tools
parent2dd23c37a08ad705c9cb48ededb18cce29609aa5 (diff)
downloadchromium_src-2ddff339b83714e75c8da7d0be99dbc3b4c3213b.zip
chromium_src-2ddff339b83714e75c8da7d0be99dbc3b4c3213b.tar.gz
chromium_src-2ddff339b83714e75c8da7d0be99dbc3b4c3213b.tar.bz2
Remove dependency on dateutil in memory_inspector
This patch is part of an ongoing process to unbundle memory_inspector and make it a chrome app. It removes the dependency of www_server.py on the dateutil module, which is not part of the Python Standard Library. BUG=448399 Review URL: https://codereview.chromium.org/850033002 Cr-Commit-Position: refs/heads/master@{#311507}
Diffstat (limited to 'tools')
-rw-r--r--tools/memory_inspector/memory_inspector/data/file_storage.py16
-rw-r--r--tools/memory_inspector/memory_inspector/frontends/www_server.py12
2 files changed, 16 insertions, 12 deletions
diff --git a/tools/memory_inspector/memory_inspector/data/file_storage.py b/tools/memory_inspector/memory_inspector/data/file_storage.py
index 55656f5..71ccd23 100644
--- a/tools/memory_inspector/memory_inspector/data/file_storage.py
+++ b/tools/memory_inspector/memory_inspector/data/file_storage.py
@@ -108,7 +108,7 @@ class Archive(object):
def StartNewSnapshot(self):
"""Creates a 2014-01-01_02:03:04.snapshot marker (an empty file)."""
- self._cur_snapshot = Archive._TimestampToStr(datetime.datetime.now())
+ self._cur_snapshot = Archive.TimestampToStr(datetime.datetime.now())
file_path = os.path.join(self._path,
self._cur_snapshot + Archive._SNAP_EXT)
assert(not os.path.exists(file_path))
@@ -136,7 +136,7 @@ class Archive(object):
def LoadMemMaps(self, timestamp):
assert(self.HasMemMaps(timestamp))
- snapshot_name = Archive._TimestampToStr(timestamp)
+ snapshot_name = Archive.TimestampToStr(timestamp)
file_path = os.path.join(self._path, snapshot_name + Archive._MMAP_EXT)
with open(file_path) as f:
return json.load(f, cls=serialization.MmapDecoder)
@@ -154,15 +154,19 @@ class Archive(object):
def LoadNativeHeap(self, timestamp):
assert(self.HasNativeHeap(timestamp))
- snapshot_name = Archive._TimestampToStr(timestamp)
+ snapshot_name = Archive.TimestampToStr(timestamp)
file_path = os.path.join(self._path, snapshot_name + Archive._NHEAP_EXT)
with open(file_path) as f:
return json.load(f, cls=serialization.NativeHeapDecoder)
def _HasSnapshotFile(self, timestamp, ext):
- name = Archive._TimestampToStr(timestamp)
+ name = Archive.TimestampToStr(timestamp)
return os.path.exists(os.path.join(self._path, name + ext))
@staticmethod
- def _TimestampToStr(timestamp):
- return timestamp.strftime(Archive._TIME_FMT) \ No newline at end of file
+ def TimestampToStr(timestamp):
+ return timestamp.strftime(Archive._TIME_FMT)
+
+ @staticmethod
+ def StrToTimestamp(timestr):
+ return datetime.datetime.strptime(timestr, Archive._TIME_FMT)
diff --git a/tools/memory_inspector/memory_inspector/frontends/www_server.py b/tools/memory_inspector/memory_inspector/frontends/www_server.py
index b5f8efc..c79112f 100644
--- a/tools/memory_inspector/memory_inspector/frontends/www_server.py
+++ b/tools/memory_inspector/memory_inspector/frontends/www_server.py
@@ -21,7 +21,6 @@ The following HTTP status code are returned by the server:
import cgi
import collections
import datetime
-import dateutil.parser
import glob
import json
import memory_inspector
@@ -187,7 +186,7 @@ def _CreateProfile(args, req_vars): # pylint: disable=W0613
return _HTTP_GONE, [], 'Cannot open archive %s' % req_vars['archive']
first_timestamp = None
for timestamp_str in req_vars['snapshots']:
- timestamp = dateutil.parser.parse(timestamp_str)
+ timestamp = file_storage.Archive.StrToTimestamp(timestamp_str)
first_timestamp = first_timestamp or timestamp
time_delta = int((timestamp - first_timestamp).total_seconds())
if req_vars['type'] == 'mmap':
@@ -545,7 +544,8 @@ def _ListStorage(args, req_vars): # pylint: disable=W0613
time_delta = '%d s.' % (timestamp - first_timestamp).total_seconds()
resp['rows'] += [{'c': [
{'v': archive_name, 'f': None},
- {'v': timestamp.isoformat(), 'f': time_delta},
+ {'v': file_storage.Archive.TimestampToStr(timestamp),
+ 'f': time_delta},
{'v': archive.HasMemMaps(timestamp), 'f': None},
{'v': archive.HasNativeHeap(timestamp), 'f': None},
]}]
@@ -558,7 +558,7 @@ def _LoadMmapsFromStorage(args, req_vars): # pylint: disable=W0613
if not archive:
return _HTTP_GONE, [], 'Cannot open archive %s' % req_vars['archive']
- timestamp = dateutil.parser.parse(args[1])
+ timestamp = file_storage.Archive.StrToTimestamp(args[1])
if not archive.HasMemMaps(timestamp):
return _HTTP_GONE, [], 'No mmaps for snapshot %s' % timestamp
mmap = archive.LoadMemMaps(timestamp)
@@ -572,7 +572,7 @@ def _LoadNheapFromStorage(args, req_vars):
if not archive:
return _HTTP_GONE, [], 'Cannot open archive %s' % req_vars['archive']
- timestamp = dateutil.parser.parse(args[1])
+ timestamp = file_storage.Archive.StrToTimestamp(args[1])
if not archive.HasNativeHeap(timestamp):
return _HTTP_GONE, [], 'No native heap dump for snapshot %s' % timestamp
@@ -758,4 +758,4 @@ def Start(http_port):
httpd.serve_forever()
except KeyboardInterrupt:
pass # Don't print useless stack traces when the user hits CTRL-C.
- background_tasks.TerminateAll() \ No newline at end of file
+ background_tasks.TerminateAll()