parameters: (pid, infile)
return_statement: return out
docstring: Returns chrometrace json format for |infile| strace output.
docstring_summary: Returns chrometrace json format for |infile| strace output.
docstring_tokens: Returns chrometrace json format for |infile| strace output .
function: def _StraceToChromeTrace(pid, infile):
    """Returns chrometrace json format for |infile| strace output."""
    # Map of fd:file_name for open file descriptors. Useful for displaying
    # file name instead of the descriptor number.
    fd_map = {}
  
    # Map of tid:interrupted_call for the interrupted call on each thread. It is
    # possible to context switch during a system call. In this case we must
    # match up the lines.
    interrupted_call_map = {}
  
    out = []
    with open(infile, 'r') as f:
      for line in f.readlines():
        # Ignore kill lines for now.
        m = _KILLED_LINE_RE.match(line)
        if m:
          continue
  
        # If this line is interrupted, then remember it and continue.
        m = _UNFINISHED_LINE_RE.match(line)
        if m:
          assert m.group('tid') not in interrupted_call_map
          interrupted_call_map[m.group('tid')] = line
          continue
  
        # If this is a resume of a previous line, stitch it together.
        interrupted = False
        m = _RESUMED_LINE_RE.match(line)
        if m:
          interrupted = True
          assert m.group('tid') in interrupted_call_map
          line = interrupted_call_map[m.group('tid')].replace(
              '<unfinished ...>', m.group('line'))
          del interrupted_call_map[m.group('tid')]
  
        # At this point we can do a normal match.
        m = _STRACE_LINE_RE.match(line)
        if not m:
          if ('exit' not in line and
              'Profiling timer expired' not in line and
              '<unavailable>' not in line):
            logging.warn('Failed to parse line: %s' % line)
          continue
  
        ts_begin = int(1000000 * (int(m.group('ts')) + float(m.group('micro'))))
        ts_end = ts_begin + int(1000000 * float(m.group('dur')))
        tid = int(m.group('tid'))
        function_name = unicode(m.group('func'), errors='ignore')
        function_args = unicode(m.group('args'), errors='ignore')
        ret = unicode(m.group('ret'), errors='ignore')
        cat = 'strace'
  
        possible_fd_arg = None
        first_arg = function_args.split(',')[0]
        if first_arg and first_arg.strip().isdigit():
          possible_fd_arg = first_arg.strip()
  
        if function_name == 'open' and ret.isdigit():
          # 1918  1311606151.649379 open("/foo/bar.so", O_RDONLY) = 7 <0.000088>
          fd_map[ret] = first_arg
  
        args = {
            'args': function_args,
            'ret': ret,
            }
        if interrupted:
          args['interrupted'] = True
        if possible_fd_arg and possible_fd_arg in fd_map:
          args['fd%s' % first_arg] = fd_map[possible_fd_arg]
  
        out.append({
            'cat': cat,
            'pid': pid,
            'tid': tid,
            'ts': ts_begin,
            'ph': 'B',  # Begin
            'name': function_name,
            })
        out.append({
            'cat': cat,
            'pid': pid,
            'tid': tid,
            'ts': ts_end,
            'ph': 'E',  # End
            'name': function_name,
            'args': args,
            })
  
    return out
function_tokens: def _StraceToChromeTrace ( pid , infile ) : # Map of fd:file_name for open file descriptors. Useful for displaying # file name instead of the descriptor number. fd_map = { } # Map of tid:interrupted_call for the interrupted call on each thread. It is # possible to context switch during a system call. In this case we must # match up the lines. interrupted_call_map = { } out = [ ] with open ( infile , 'r' ) as f : for line in f . readlines ( ) : # Ignore kill lines for now. m = _KILLED_LINE_RE . match ( line ) if m : continue # If this line is interrupted, then remember it and continue. m = _UNFINISHED_LINE_RE . match ( line ) if m : assert m . group ( 'tid' ) not in interrupted_call_map interrupted_call_map [ m . group ( 'tid' ) ] = line continue # If this is a resume of a previous line, stitch it together. interrupted = False m = _RESUMED_LINE_RE . match ( line ) if m : interrupted = True assert m . group ( 'tid' ) in interrupted_call_map line = interrupted_call_map [ m . group ( 'tid' ) ] . replace ( '<unfinished ...>' , m . group ( 'line' ) ) del interrupted_call_map [ m . group ( 'tid' ) ] # At this point we can do a normal match. m = _STRACE_LINE_RE . match ( line ) if not m : if ( 'exit' not in line and 'Profiling timer expired' not in line and '<unavailable>' not in line ) : logging . warn ( 'Failed to parse line: %s' % line ) continue ts_begin = int ( 1000000 * ( int ( m . group ( 'ts' ) ) + float ( m . group ( 'micro' ) ) ) ) ts_end = ts_begin + int ( 1000000 * float ( m . group ( 'dur' ) ) ) tid = int ( m . group ( 'tid' ) ) function_name = unicode ( m . group ( 'func' ) , errors = 'ignore' ) function_args = unicode ( m . group ( 'args' ) , errors = 'ignore' ) ret = unicode ( m . group ( 'ret' ) , errors = 'ignore' ) cat = 'strace' possible_fd_arg = None first_arg = function_args . split ( ',' ) [ 0 ] if first_arg and first_arg . strip ( ) . isdigit ( ) : possible_fd_arg = first_arg . strip ( ) if function_name == 'open' and ret . isdigit ( ) : # 1918  1311606151.649379 open("/foo/bar.so", O_RDONLY) = 7 <0.000088> fd_map [ ret ] = first_arg args = { 'args' : function_args , 'ret' : ret , } if interrupted : args [ 'interrupted' ] = True if possible_fd_arg and possible_fd_arg in fd_map : args [ 'fd%s' % first_arg ] = fd_map [ possible_fd_arg ] out . append ( { 'cat' : cat , 'pid' : pid , 'tid' : tid , 'ts' : ts_begin , 'ph' : 'B' , # Begin 'name' : function_name , } ) out . append ( { 'cat' : cat , 'pid' : pid , 'tid' : tid , 'ts' : ts_end , 'ph' : 'E' , # End 'name' : function_name , 'args' : args , } ) return out