Exemple #1
0
def start_tracer():

    try:
        parse_cmd_line_args()
        if not DEV_NAME:
            raise TracerException(
                "Missing device name, please provide device name. Check help [--help]"
            )
        global MST_DEVICE
        global CMDIFDEV
        MST_DEVICE = mtcr.MstDevice(DEV_NAME)
        devInfo = get_device_info(MST_DEVICE)
        CMDIFDEV = cmdif.CmdIf(MST_DEVICE)

        if FwTraceUtilities.is_driver_mem_mode_supported():
            try:
                check_secure_fw_args(devInfo)
                secure_fw_tracer = SecureFwTrace(MST_DEVICE, DEV_NAME,
                                                 IGNORE_OLD_EVENTS, REAL_TS)
                open_mst_dev()
                apply_mask(devInfo, MST_DEVICE, CMDIFDEV)
                secure_fw_tracer.parse_driver_mem()
            except Exception as exp:
                print("-E- %s" % exp)
        else:
            raise TracerException("Driver mem mode is not supported")

    except Exception as exp:
        print("-E- %s" % exp)
        return 1

    return 0
    def _prepare_and_print_event(self, event): 
        """
        The method responsible for adjusting the event according
        the given flags (real_ts and future formating and flags)
        """
        # if real time stamp is needed
        if self._real_ts:
            event_suffix = event.split("]", 1)[1]
            event_prefix = FwTraceUtilities.ts_to_real_ts(self._MAX_TIME_STAMP, self._device_freq)
            event = "[{0}]{1}".format(event_prefix, event_suffix)

        print(event)
    def parse_driver_mem(self):
        """
        The method responsible for parsing the events file that
        filled by the mellanox driver
        """
        self._MAX_TIME_STAMP = 0
        first_run = True
        second_run = False
        print_event = True

        if os.path.exists(self._TRACER_FILE):
            bdf = FwTraceUtilities.get_dev_dbdf(self._device_name)
            try:
                while True:
                    # first run is the first time we open the file.
                    # in that case we need to print that we read old event and
                    # apply the logic of the ignore old event if needed
                    if first_run:
                        first_run = False
                        second_run = True
                        if self._ignore_old_events:
                            print_event = False
                        else:
                            print_event = True
                            print("Read old events:")
                    # we need to print 'read new event' only one time and only
                    # at the second time we open the file (new events arrive)
                    elif second_run:
                        print_event = True
                        second_run = False
                        print("Read new events:")

                    fd = open(self._TRACER_FILE, "rb")
                    # go over all the file lines on each iteration
                    # in order to overcome a case that the file has some
                    # corruptions while being written
                    for line in fd:
                        self._parse_driver_mem_line_to_event(
                            line, bdf, print_event)

                    fd.close()
                    time.sleep(self.OPEN_CLOSE_FILE_DELAY_SEC)
            except KeyboardInterrupt:
                print("\nStopping... ")
        else:
            print("no trace file to parse")
 def __init__(self,
              mst_device,
              device_name,
              ignore_old_events=False,
              real_ts=False):
     self._mst_device = mst_device
     self._device_name = device_name
     self._ignore_old_events = ignore_old_events
     self._real_ts = real_ts
     self._MAX_TIME_STAMP = 0
     self._TRACER_FILE = ""
     self._device_freq = 0
     
     if os.name == "nt":
         # future capability - windows
         # self._TRACER_FILE = self.WINDOWS_TRACER_FILE
         pass
     else:    
         self._TRACER_FILE = self.LINUX_TRACER_FILE
     
     if real_ts:
         self._device_freq = FwTraceUtilities.get_device_frequency(device_name)