ROCm / roctracer

ROCm Tracer Callback/Activity Library for Performance tracing AMD GPUs
https://rocm.docs.amd.com/projects/roctracer/en/latest/
Other
64 stars 30 forks source link

parsing for clang lambda names for SYCL is broken in tblextr.py #71

Open lfmeadow opened 2 years ago

lfmeadow commented 2 years ago

The code in tblextr.py uses regular expressions that do not account for the universe of clang-produced demangled names. I argue that the right fix for this is to use mangled names everywhere until the final reports. However, the following patch does work around the problem for SYCL at least, and fixes another problem in ROCM 4.5.0

$ diff -c /opt/rocm-4.5.0/rocprofiler/bin/tblextr.py python/tblextr.py 
*** /opt/rocm-4.5.0/rocprofiler/bin/tblextr.py  2021-10-05 14:09:14.000000000 -0400
--- python/tblextr.py   2022-02-02 12:54:33.489606000 -0500
***************
*** 318,332 ****
  #############################################################
  # arguments manipulation routines
  def get_field(args, field):
    ptrn1_field = re.compile(r'^.* ' + field + '\(');
!   ptrn2_field = re.compile(r'\) .*$');
!   ptrn3_field = re.compile(r'\)\)$');
!   (field_name, n) = ptrn1_field.subn('', args, count=1);
!   if n != 0:
!     (field_name, n) = ptrn2_field.subn('', field_name, count=1)
!     if n == 0:
!       (field_name, n) = ptrn3_field.subn('', field_name, count=1)
!   return (field_name, n)

  def set_field(args, field, val):
    return re.subn(field + '\(\w+\)([ \)])', field + '(' + str(val) + ')\\1', args, count=1)
--- 318,337 ----
  #############################################################
  # arguments manipulation routines
  def get_field(args, field):
+   # rewrite code to handle nested parens properly
+   # this is probably slow
    ptrn1_field = re.compile(r'^.* ' + field + '\(');
!   o = ptrn1_field.match(args)
!   if o == None:
!     return ('',  0)
!   np = 1
!   valstart = o.end(0)
!   for i in range(valstart,len(args)):
!     if args[i] == '(': np += 1
!     if args[i] == ')': np -= 1
!     if np == 0:
!       break
!   return (args[valstart:i-1], 1)

  def set_field(args, field, val):
    return re.subn(field + '\(\w+\)([ \)])', field + '(' + str(val) + ')\\1', args, count=1)
***************
*** 428,433 ****
--- 433,440 ----
          record_id_dict[proc_id] += 1
          record_id = record_id_dict[proc_id]

+         if not proc_id in dep_dict: dep_dict[proc_id] = {}
+ 
          # setting correlationid to record id if correlation id is not defined
          if corr_id == 0: corr_id = record_id