tools/perf/cli_tools/pinpoint_traces.py
def ExtractEvents(regex, working_dir, csv_path):
  """Extracts all matching events and outputs them into a CSV file.

  Finds the trace files by scanning the working directory.

  Args:
    regex: A regular expression. Selects an event if its name matches.
    working_dir: (str) Path to a working directory with structure as explained
        in ExtractFromOneTraceThrowing().
    csv_path: (str) Name of the output file.
  """
  compiled_regex = re.compile(regex)
  tasks = []
  for run_label in os.listdir(working_dir):
    full_dir = os.path.join(working_dir, run_label)
    if not os.path.isdir(full_dir):
      continue
    trace_index = -1  # ID of the html trace, several json files merge into it.
    for html in os.listdir(full_dir):
      html_trace = os.path.join(full_dir, html)
      if not os.path.isfile(html_trace) or not html_trace.endswith('.html'):
        continue
      trace_index += 1
      json_cache = os.path.join(full_dir, 'json_cache')
      json_dir = os.path.join(json_cache, html.rstrip('.html'))
      tasks.append(
          (run_label, trace_index, html_trace, json_dir, compiled_regex))
  # Since multiprocessing accumulates all data in memory until the last task in
  # the pool has terminated, run it in batches to avoid swapping.
  batch_size = multiprocessing.cpu_count()
  if sys.platform == 'win32':
    # TODO(crbug.com/1190269) - we can't use more than 56
    # cores on Windows or Python3 may hang.
    batch_size = min(batch_size, 56)

  pool = multiprocessing.Pool(batch_size)
  with open(csv_path, 'w') as csv_file:
    writer = csv.writer(csv_file)
    writer.writerow(
        ['label', 'trace_index', 'name', 'ts', 'duration', 'thread_duration'])
    while tasks:
      batch = tasks[:batch_size]
      tasks = tasks[batch_size:]
      OutputCsv(pool.map(ExtractFromOneTrace, batch), writer)
Extracts all matching events and outputs them into a CSV file.

  Finds the trace files by scanning the working directory.

  Args:
    regex: A regular expression. Selects an event if its name matches.
    working_dir: (str) Path to a working directory with structure as explained
        in ExtractFromOneTraceThrowing().
    csv_path: (str) Name of the output file.
  
Extracts all matching events and outputs them into a CSV file.
Finds the trace files by scanning the working directory.
Extracts all matching events and outputs them into a CSV file . Finds the trace files by scanning the working directory .
def ExtractEvents(regex, working_dir, csv_path):
  compiled_regex = re.compile(regex)
  tasks = []
  for run_label in os.listdir(working_dir):
    full_dir = os.path.join(working_dir, run_label)
    if not os.path.isdir(full_dir):
      continue
    trace_index = -1  
    for html in os.listdir(full_dir):
      html_trace = os.path.join(full_dir, html)
      if not os.path.isfile(html_trace) or not html_trace.endswith('.html'):
        continue
      trace_index += 1
      json_cache = os.path.join(full_dir, 'json_cache')
      json_dir = os.path.join(json_cache, html.rstrip('.html'))
      tasks.append(
          (run_label, trace_index, html_trace, json_dir, compiled_regex))
  batch_size = multiprocessing.cpu_count()
  if sys.platform == 'win32':
    batch_size = min(batch_size, 56)
  pool = multiprocessing.Pool(batch_size)
  with open(csv_path, 'w') as csv_file:
    writer = csv.writer(csv_file)
    writer.writerow(
        ['label', 'trace_index', 'name', 'ts', 'duration', 'thread_duration'])
    while tasks:
      batch = tasks[:batch_size]
      tasks = tasks[batch_size:]
      OutputCsv(pool.map(ExtractFromOneTrace, batch), writer)
def ExtractEvents ( regex , working_dir , csv_path ) : compiled_regex = re . compile ( regex ) tasks = [ ] for run_label in os . listdir ( working_dir ) : full_dir = os . path . join ( working_dir , run_label ) if not os . path . isdir ( full_dir ) : continue trace_index = - 1 for html in os . listdir ( full_dir ) : html_trace = os . path . join ( full_dir , html ) if not os . path . isfile ( html_trace ) or not html_trace . endswith ( '.html' ) : continue trace_index += 1 json_cache = os . path . join ( full_dir , 'json_cache' ) json_dir = os . path . join ( json_cache , html . rstrip ( '.html' ) ) tasks . append ( ( run_label , trace_index , html_trace , json_dir , compiled_regex ) ) batch_size = multiprocessing . cpu_count ( ) if sys . platform == 'win32' : batch_size = min ( batch_size , 56 ) pool = multiprocessing . Pool ( batch_size ) with open ( csv_path , 'w' ) as csv_file : writer = csv . writer ( csv_file ) writer . writerow ( [ 'label' , 'trace_index' , 'name' , 'ts' , 'duration' , 'thread_duration' ] ) while tasks : batch = tasks [ : batch_size ] tasks = tasks [ batch_size : ] OutputCsv ( pool . map ( ExtractFromOneTrace , batch ) , writer )
Extracts all matching events and outputs them into a CSV file.
Extracts all matching events and outputs them into a CSV file .
"""Extracts all matching events and outputs them into a CSV file.

  Finds the trace files by scanning the working directory.

  Args:
    regex: A regular expression. Selects an event if its name matches.
    working_dir: (str) Path to a working directory with structure as explained
        in ExtractFromOneTraceThrowing().
    csv_path: (str) Name of the output file.
  """ # ID of the html trace, several json files merge into it. # Since multiprocessing accumulates all data in memory until the last task in # the pool has terminated, run it in batches to avoid swapping. # TODO(crbug.com/1190269) - we can't use more than 56 # cores on Windows or Python3 may hang.
regex
A regular expression. Selects an event if its name matches.
A regular expression . Selects an event if its name matches .
working_dir
(str) Path to a working directory with structure as explained
in ExtractFromOneTraceThrowing().
( str ) Path to a working directory with structure as explained in ExtractFromOneTraceThrowing () .
csv_path
(str) Name of the output file.
( str ) Name of the output file .