code: def assign_entries_to_threads(entries):
      # first sort the entries' keys by end timestamp
      sorted_keys = sorted(
          list(entries.keys()),
          key=lambda k: entries[k][1],
          reverse=True,
      )
  
      # build the chart data by assigning entries to threads
      results = {}
      threads = []
      for name in sorted_keys:
          entry = entries[name]
  
          # assign this entry by finding the first available thread identified
          # by the thread's current start time greater than the entry's end time
          tid = -1
          for t in range(len(threads)):
              if threads[t] >= entry[1]:
                  threads[t] = entry[0]
                  tid = t
                  break
  
          # if no current thread found, create a new one with this entry
          if tid < 0:
              threads.append(entry[0])
              tid = len(threads) - 1
  
          # add entry name to the array associated with this tid
          if tid not in results.keys():
              results[tid] = []
          results[tid].append(name)
  
      # first entry has the last end time
      end_time = entries[sorted_keys[0]][1]
  
      # return the threaded entries and the last end time
      return (results, end_time)
  
file_path: cudf/cpp/scripts/sort_ninja_log.py
imports: import argparse
  import os
  import sys
  import xml.etree.ElementTree
  from pathlib import Path
  from xml.dom import minidom
label_desc: Use image node_id 4 for calling a global function with example usage: assign_entries_to_threads(entries) and returns: results,  end_time