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

Side by Side Diff: tools/profile_chrome/trace_packager.py

Issue 1068693003: Fixing crash on chrome profiler on generating html trace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import codecs
5 import gzip 6 import gzip
6 import json 7 import json
7 import os 8 import os
8 import shutil 9 import shutil
9 import sys 10 import sys
10 import zipfile 11 import zipfile
11 12
12 from profile_chrome import util 13 from profile_chrome import util
13 14
14 from pylib import constants 15 from pylib import constants
15 16
16 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 17 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT,
17 'third_party', 18 'third_party',
18 'trace-viewer')) 19 'trace-viewer'))
19 # pylint: disable=F0401 20 # pylint: disable=F0401
20 from trace_viewer.build import trace2html 21 from trace_viewer.build import trace2html
21 22
22 23
23 def _PackageTracesAsHtml(trace_files, html_file): 24 def _PackageTracesAsHtml(trace_files, html_file):
24 with open(html_file, 'w') as f: 25 with codecs.open(html_file, mode='w', encoding='utf-8') as f:
25 trace2html.WriteHTMLForTracesToFile(trace_files, f) 26 trace2html.WriteHTMLForTracesToFile(trace_files, f)
26 for trace_file in trace_files: 27 for trace_file in trace_files:
27 os.unlink(trace_file) 28 os.unlink(trace_file)
28 29
29 30
30 def _CompressFile(host_file, output): 31 def _CompressFile(host_file, output):
31 with gzip.open(output, 'wb') as out, \ 32 with gzip.open(output, 'wb') as out, \
32 open(host_file, 'rb') as input_file: 33 open(host_file, 'rb') as input_file:
33 out.write(input_file.read()) 34 out.write(input_file.read())
34 os.unlink(host_file) 35 os.unlink(host_file)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 _CompressFile(trace_files[0], result) 86 _CompressFile(trace_files[0], result)
86 elif len(trace_files) > 1: 87 elif len(trace_files) > 1:
87 result = output or 'chrome-combined-trace-%s.zip' % util.GetTraceTimestamp() 88 result = output or 'chrome-combined-trace-%s.zip' % util.GetTraceTimestamp()
88 _ArchiveFiles(trace_files, result) 89 _ArchiveFiles(trace_files, result)
89 elif output: 90 elif output:
90 result = output 91 result = output
91 shutil.move(trace_files[0], result) 92 shutil.move(trace_files[0], result)
92 else: 93 else:
93 result = trace_files[0] 94 result = trace_files[0]
94 return result 95 return result
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698