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

Unified Diff: mojo/devtools/common/android_stack_parser/stack

Issue 1306603002: Improve android stack parser (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 4 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: mojo/devtools/common/android_stack_parser/stack
diff --git a/mojo/devtools/common/android_stack_parser/stack b/mojo/devtools/common/android_stack_parser/stack
index 97913ab84191ed7e8d87219a50b702b28762815b..f75d097e7bf14894b8739c555c5095ecab36d05e 100755
--- a/mojo/devtools/common/android_stack_parser/stack
+++ b/mojo/devtools/common/android_stack_parser/stack
@@ -17,11 +17,11 @@
"""stack symbolizes native crash dumps."""
import getopt
-import glob
import os
-import re
+import os.path
import sys
+import stack_utils
import stack_core
import subprocess
import symbol
@@ -71,102 +71,6 @@ def PrintUsage():
# pylint: enable-msg=C6310
sys.exit(1)
-def UnzipSymbols(symbolfile, symdir=None):
- """Unzips a file to _DEFAULT_SYMROOT and returns the unzipped location.
-
- Args:
- symbolfile: The .zip file to unzip
- symdir: Optional temporary directory to use for extraction
-
- Returns:
- A tuple containing (the directory into which the zip file was unzipped,
- the path to the "symbols" directory in the unzipped file). To clean
- up, the caller can delete the first element of the tuple.
-
- Raises:
- SymbolDownloadException: When the unzip fails.
- """
- if not symdir:
- symdir = "%s/%s" % (_DEFAULT_SYMROOT, hash(symbolfile))
- if not os.path.exists(symdir):
- os.makedirs(symdir)
-
- print "extracting %s..." % symbolfile
- saveddir = os.getcwd()
- os.chdir(symdir)
- try:
- unzipcode = subprocess.call(["unzip", "-qq", "-o", symbolfile])
- if unzipcode > 0:
- os.remove(symbolfile)
- raise SymbolDownloadException("failed to extract symbol files (%s)."
- % symbolfile)
- finally:
- os.chdir(saveddir)
-
- android_symbols = glob.glob("%s/out/target/product/*/symbols" % symdir)
- if android_symbols:
- return (symdir, android_symbols[0])
- else:
- # This is a zip of Chrome symbols, so symbol.CHROME_SYMBOLS_DIR needs to be
- # updated to point here.
- symbol.CHROME_SYMBOLS_DIR = symdir
- return (symdir, symdir)
-
-
-def GetBasenameFromMojoApp(url):
- """Used by GetSymbolMapping() to extract the basename from the location the
- mojo app was downloaded from. The location is a URL, e.g.
- http://foo/bar/x.so."""
- index = url.rfind('/')
- return url[(index + 1):] if index != -1 else url
-
-
-def GetSymboledNameForMojoApp(path):
- """Used by GetSymbolMapping to get the non-stripped library name for an
- installed mojo app."""
- # e.g. tracing.mojo -> libtracing_library.so
- name, ext = os.path.splitext(path)
- if ext != '.mojo':
- return path
- return 'lib%s_library.so' % name
-
-
-def GetSymbolMapping(lines):
- """Returns a mapping (dictionary) from download file to .so."""
- regex = re.compile('Caching mojo app (\S+) at (\S+)')
- mappings = {}
- for line in lines:
- result = regex.search(line)
- if result:
- url = GetBasenameFromMojoApp(result.group(1))
- mappings[result.group(2)] = GetSymboledNameForMojoApp(url)
- return mappings
-
-
-def _LowestAncestorContainingRelpath(dir_path, relpath):
- """Returns the lowest ancestor dir of |dir_path| that contains |relpath|.
- """
- cur_dir_path = os.path.abspath(dir_path)
- while True:
- if os.path.exists(os.path.join(cur_dir_path, relpath)):
- return cur_dir_path
-
- next_dir_path = os.path.dirname(cur_dir_path)
- if next_dir_path != cur_dir_path:
- cur_dir_path = next_dir_path
- else:
- return None
-
-
-def _GuessDir(relpath):
- """Returns absolute path to location |relpath| in the lowest ancestor of this
- file that contains it."""
- lowest_ancestor = _LowestAncestorContainingRelpath(
- os.path.dirname(__file__), relpath)
- if not lowest_ancestor:
- return None
- return os.path.join(lowest_ancestor, relpath)
-
def main():
@@ -204,7 +108,7 @@ def main():
more_info = False
if not symbol.BUILD_DIR:
- guess = _GuessDir(_DEFAULT_BUILD_DIR)
+ guess = stack_utils.GuessDir(_DEFAULT_BUILD_DIR)
if not guess:
print "Couldn't find the build directory, please pass --build-dir."
return 1
@@ -212,7 +116,7 @@ def main():
symbol.BUILD_DIR = guess
if not symbol.NDK_DIR:
- guess = _GuessDir(_DEFAULT_NDK_DIR)
+ guess = stack_utils.GuessDir(_DEFAULT_NDK_DIR)
if not guess:
print "Couldn't find the Android NDK, please pass --ndk-dir."
return 1
@@ -235,13 +139,13 @@ def main():
rootdir = None
if zip_arg:
- rootdir, symbol.SYMBOLS_DIR = UnzipSymbols(zip_arg)
+ rootdir, symbol.SYMBOLS_DIR = stack_utils.UnzipSymbols(zip_arg)
if symbol.SYMBOLS_DIR:
print "Reading Android symbols from", symbol.SYMBOLS_DIR
print "Reading Mojo symbols from", symbol.BUILD_DIR
- stack_core.ConvertTrace(lines, more_info, GetSymbolMapping(lines))
+ stack_core.ConvertTrace(lines, more_info, stack_utils.GetSymbolMapping(lines))
if rootdir:
# be a good citizen and clean up...os.rmdir and os.removedirs() don't work

Powered by Google App Engine
This is Rietveld 408576698