parameters: (self)
return_statement: return job_id
docstring: Get profiling job id, which was generated by ada service.
  
          Returns:
              str, profiling job id.
docstring_summary: Get profiling job id, which was generated by ada service.
docstring_tokens: Get profiling job id which was generated by ada service .
function: def _get_profiling_job_id(self):
          """Get profiling job id, which was generated by ada service.
  
          Returns:
              str, profiling job id.
          """
  
          if self._is_offline_parser():
              # The self._ascend_job_id directory like "/../PROF***" or "/../JOB***".
              job_id = self._ascend_job_id.rstrip('/').split('/')[-1]
              if job_id.startswith('PROF'):
                  device_dir = [dir for dir in os.listdir(self._ascend_job_id) if dir.startswith('device')]
                  return os.path.join(job_id, device_dir[0])
              return job_id
  
          job_id = ""
          job_dirs = filter(lambda item: item.startswith('JOB') or item.startswith('PROF') and \
                                         os.path.isdir(os.path.join(self._output_path, item)),
                            os.listdir(self._output_path))
          sorted_job_dirs = sorted(job_dirs, key=lambda x: os.path.getmtime(os.path.join(self._output_path, x)),
                                   reverse=True)
  
          for dir_name in sorted_job_dirs:
              if dir_name.startswith('PROF'):
                  prof_dir = os.path.join(self._output_path, dir_name)
                  device_dir = [dir for dir in os.listdir(prof_dir) \
                                if dir.startswith('device') and os.path.isdir(os.path.join(prof_dir, dir))]
                  job_dir = os.path.join(self._output_path, dir_name, device_dir[0])
              else:
                  job_dir = os.path.join(self._output_path, dir_name)
  
              host_start_file_path = get_file_path(job_dir, "host_start.log")
              if host_start_file_path is None:
                  logger.warning("Find profiling job path %s, but host_start.log not exist, "
                                 "profiler will ignore this job dir.", job_dir)
                  continue
  
              training_device_id = host_start_file_path.split('.')[-1]
              if self._dev_id != training_device_id:
                  logger.warning("Find profiling find job path %s, but not current training device id. "
                                 "Current training device id %s, but job path device id: %s, "
                                 "profiler will ignore this job dir.", job_dir, self._dev_id, training_device_id)
                  continue
  
              if not os.listdir(os.path.join(job_dir, 'data')):
                  continue
  
              job_start_time = self._parse_host_start_log(host_start_file_path)
              if not job_start_time:
                  logger.warning("Find profiling job path %s, but fail to get job start info, "
                                 "profiler will ignore this job dir.", job_start_time)
                  continue
  
              if int(job_start_time) < self._start_time:
                  logger.warning("Find profiling job path %s, but start_time(%d) is earlier than this training "
                                 "start_time(%d), profiler will ignore this job dir.",
                                 job_dir, int(job_start_time), self._start_time)
                  continue
  
              if dir_name.startswith('PROF'):
                  job_id = os.path.join(dir_name, device_dir[0])
              else:
                  job_id = dir_name
              break
  
          if not job_id:
              msg = "Fail to get profiling job, output path is {}, " \
                    "please check whether job dir or prof dir(name startswith JOB or PROF) in output path " \
                    "was generated, or may be the device id from job dir dismatch the " \
                    "device_id in current process.".format(self._output_path)
              raise RuntimeError(msg)
  
          return job_id
function_tokens: def _get_profiling_job_id ( self ) : if self . _is_offline_parser ( ) : # The self._ascend_job_id directory like "/../PROF***" or "/../JOB***". job_id = self . _ascend_job_id . rstrip ( '/' ) . split ( '/' ) [ - 1 ] if job_id . startswith ( 'PROF' ) : device_dir = [ dir for dir in os . listdir ( self . _ascend_job_id ) if dir . startswith ( 'device' ) ] return os . path . join ( job_id , device_dir [ 0 ] ) return job_id job_id = "" job_dirs = filter ( lambda item : item . startswith ( 'JOB' ) or item . startswith ( 'PROF' ) and os . path . isdir ( os . path . join ( self . _output_path , item ) ) , os . listdir ( self . _output_path ) ) sorted_job_dirs = sorted ( job_dirs , key = lambda x : os . path . getmtime ( os . path . join ( self . _output_path , x ) ) , reverse = True ) for dir_name in sorted_job_dirs : if dir_name . startswith ( 'PROF' ) : prof_dir = os . path . join ( self . _output_path , dir_name ) device_dir = [ dir for dir in os . listdir ( prof_dir ) if dir . startswith ( 'device' ) and os . path . isdir ( os . path . join ( prof_dir , dir ) ) ] job_dir = os . path . join ( self . _output_path , dir_name , device_dir [ 0 ] ) else : job_dir = os . path . join ( self . _output_path , dir_name ) host_start_file_path = get_file_path ( job_dir , "host_start.log" ) if host_start_file_path is None : logger . warning ( "Find profiling job path %s, but host_start.log not exist, " "profiler will ignore this job dir." , job_dir ) continue training_device_id = host_start_file_path . split ( '.' ) [ - 1 ] if self . _dev_id != training_device_id : logger . warning ( "Find profiling find job path %s, but not current training device id. " "Current training device id %s, but job path device id: %s, " "profiler will ignore this job dir." , job_dir , self . _dev_id , training_device_id ) continue if not os . listdir ( os . path . join ( job_dir , 'data' ) ) : continue job_start_time = self . _parse_host_start_log ( host_start_file_path ) if not job_start_time : logger . warning ( "Find profiling job path %s, but fail to get job start info, " "profiler will ignore this job dir." , job_start_time ) continue if int ( job_start_time ) < self . _start_time : logger . warning ( "Find profiling job path %s, but start_time(%d) is earlier than this training " "start_time(%d), profiler will ignore this job dir." , job_dir , int ( job_start_time ) , self . _start_time ) continue if dir_name . startswith ( 'PROF' ) : job_id = os . path . join ( dir_name , device_dir [ 0 ] ) else : job_id = dir_name break if not job_id : msg = "Fail to get profiling job, output path is {}, " "please check whether job dir or prof dir(name startswith JOB or PROF) in output path " "was generated, or may be the device id from job dir dismatch the " "device_id in current process." . format ( self . _output_path ) raise RuntimeError ( msg ) return job_id