code: def print_traced_files(
      glob_mask, lines_per_tid=5, stream=sys.stdout, specify_pids=None
  ):
      """
      Collect trace lines from files (glob mask), sort by pid/tid and print ordered by time
  
      :param glob_mask: file list to process ('*.txt')
      :param lines_per_tid: number of lines per pid/tid to print
      :param stream: output file stream, can accept file stream or filename(str). default is sys.stdout
      :param specify_pids: optional list of pids to include
      """
      from glob import glob
  
      def hash_line(a_line):
          return hash(":".join(a_line.split(":")[1:]))
  
      pids = {}
      orphan_calls = set()
      print_orphans = False
      for fname in glob(glob_mask, recursive=False):
          with open(fname, "rt") as fd:
              lines = fd.readlines()
          for line in lines:
              # noinspection PyBroadException
              try:
                  _, pid, tid = line.split(":")[:3]
                  pid = int(pid)
              except Exception:
                  continue
              if specify_pids and pid not in specify_pids:
                  continue
  
              if line.startswith("-"):
                  print_orphans = True
                  line = line[1:]
                  h = hash_line(line)
                  if h in orphan_calls:
                      orphan_calls.remove(h)
                      continue
              else:
                  h = hash_line(line)
                  orphan_calls.add(h)
  
              tids = pids.get(pid) if pid in pids else {}
              tids[tid] = (tids.get(tid, []) + [line])[-lines_per_tid:]
              pids[pid] = tids
  
      # sort by time stamp
      by_time = {}
      for p, tids in pids.items():
          for t, lines in tids.items():
              ts = float(
                  lines[-1].split(":")[0].strip()
              ) + 0.000001 * len(by_time)
              if print_orphans:
                  for i, line in enumerate(lines):
                      if i > 0 and hash_line(line) in orphan_calls:
                          lines[i] = " ### Orphan ### {}".format(line)
              by_time[ts] = "".join(lines) + "\n"
  
      out_stream = (
          open(stream, "w") if isinstance(stream, str) else stream
      )
      for k in sorted(by_time.keys()):
          out_stream.write(by_time[k] + "\n")
      if isinstance(stream, str):
          out_stream.close()
  
file_path: clearml/clearml/debugging/trace.py
imports: import os
  import sys
  import threading
  import inspect
  import time
  import zipfile
label_desc: Use image node_id 11 for calling a global function with example usage: print_traced_files(glob_mask, lines_per_tid, stream, specify_pids) and returns: hash