def strace_gather(self, testid, strace_config):
    delay = float(strace_config['delay'])
    duration = strace_config['duration']
    process = strace_config['process']
    sys_logger.debug("Starting STRACE for Test " + str(testid) + " in " + str(delay) + " secs")
    time.sleep(delay)
    test = action.get_test(testid)
    strace_output_file = test.statsdir + "strace_output.txt"
    sys_logger.debug("Setting up STRACE for process : " + process)
    grep1 = ["grep", process]
    p1 = subprocess.Popen(get_pid, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    p2 = subprocess.Popen(grep1, stdin=p1.stdout, stdout=subprocess.PIPE)
    p3 = subprocess.Popen(grep2, stdin=p2.stdout, stdout=subprocess.PIPE)
    p4 = subprocess.Popen(awk, stdin=p3.stdout, stdout=subprocess.PIPE)
    pid = p4.communicate()[0].strip()
    if not pid:
        msg = "No active PID found for given process : " + process
        sys_logger.debug(msg)
        if test.status == "RUNNING":
            with open(strace_output_file, 'w') as fh:
                fh.write(msg + "\n")
    else:
        sys_logger.debug("PID selected for process " + process + " : " + pid)
        strace_cmd = ["timeout", duration, "strace", "-p", pid, "-c", "-S", "time", "-o", strace_output_file]
        sys_logger.debug("Executing Strace for test " + str(testid))
        sys_logger.debug("Strace command : " + str(strace_cmd))
        p5 = subprocess.Popen(strace_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        p5.wait()
        sys_logger.debug("Appending PID information in output file")
        perl_cmd = ['perl', '-pi', '-e',
                    'print "Strace Process : ' + process + ' | PID : ' + pid + ' \\n\\n" if $. == 1',
                    strace_output_file]
        subprocess.Popen(perl_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    sys_logger.debug("Strace complete for test : " + str(testid))
Example #2
0
    def execute(self, command, paramcsv, actionID):
        #based on SYNCFLAG release from here
        #send actionID for currently being executed action based on this we can stream resp
        #keep exec details over time in a buffer with actionID mapped
        #send actionID NULL and hold return till exec is complete
        module = self.conf.actionMap[command.strip()].split(".")[0]
        function = self.conf.actionMap[command.strip()].split(".")[1]
        sync = self.conf.actionMap[command.strip()].split(".")[2]

        t2 = testobj.testDefn()
        try:
            param = int(paramcsv)
            current_test = action.get_test(param)
            if current_test:
                t2 = current_test.tobj
        except Exception as e:
            pass

        m = __import__(module)
        f = getattr(m, function)
        if sync == "T":  #wait for func to complete and return the ret
            self.lctx.debug("Executing SYNC ACTION for " + command.strip() +
                            " : " + self.conf.actionMap[command.strip()] +
                            ":" + str(actionID))
            ret = f(self, self, command, paramcsv, actionID, sync)
            self.lctx.debug("ACTION completed for " + command.strip() + " : " +
                            self.conf.actionMap[command.strip()] + ":" +
                            str(actionID))
            if command == "DAYTONA_CLI":
                return "actionID=" + str(
                    actionID) + "%" + ret + "%" + "SYNC EXEC"
            else:
                return "actionID=" + str(
                    actionID) + "," + ret + "," + "SYNC EXEC"
        else:
            #callback will be called after completion
            #actionID = uuid.uuid4()
            self.lctx.debug("Executing ASYNC ACTION for " + command.strip() +
                            " : " + self.conf.actionMap[command.strip()] +
                            ":" + str(actionID))
            t1 = common.FuncThread(f, True, self, command, paramcsv, actionID,
                                   sync)
            x = (t1, actionID, t2, time.time())
            self.lock.acquire()
            self.async_actions.append(x)
            self.lctx.debug("async_actions size :" +
                            str(len(self.async_actions)))
            self.lock.release()
            t1.start()
            self.lctx.debug("Executing ACTION for " + command.strip() + " : " +
                            self.conf.actionMap[command.strip()] + ":" +
                            str(actionID))
            return "actionID=" + str(
                actionID) + "," + "SUCCESS," + "ASYNC EXEC"
def perf_gather(self, testid, perf_config):
    delay = float(perf_config['delay'])
    duration = perf_config['duration']
    sys_logger.debug("Starting PERF for Test " + str(testid) + " in " + str(delay) + " secs")
    time.sleep(delay)
    test = action.get_test(testid)
    perf_output_file = test.statsdir + "perf_output.txt"
    perf_system_wide_cmd = ['perf', 'stat', '-e',
                            'cycles,instructions,LLC-load-misses,LLC-prefetch-misses,LLC-store-misses', '-a', '-o',
                            perf_output_file, "sleep", duration]
    if test.status == "RUNNING":
        sys_logger.debug("Executing system-wide PERF")
        sys_logger.debug("PERF command : " + str(perf_system_wide_cmd))
        p = subprocess.Popen(perf_system_wide_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        p.wait()
        sys_logger.debug("Finished system-wide PERF")
        error = p.communicate()[1].strip()
        if error:
            sys_logger.debug(error)
            with open(perf_output_file, 'w') as fh:
                fh.write(error + "\n")
            return
        if "process" in perf_config:
            process = perf_config['process']
            sys_logger.debug("Setting up PERF for process : " + process)
            grep1 = ["grep", process]
            p1 = subprocess.Popen(get_pid, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            p2 = subprocess.Popen(grep1, stdin=p1.stdout, stdout=subprocess.PIPE)
            p3 = subprocess.Popen(grep2, stdin=p2.stdout, stdout=subprocess.PIPE)
            p4 = subprocess.Popen(awk, stdin=p3.stdout, stdout=subprocess.PIPE)
            pid = p4.communicate()[0].strip()
            if not pid:
                msg = "No active PID found for given process : " + process
                sys_logger.debug(msg)
                if os.path.isfile(perf_output_file):
                    with open(perf_output_file, 'a') as fh:
                        fh.write(msg + "\n")
            else:
                msg = "PID selected for process " + process + " : " + pid
                sys_logger.debug(msg)
                perf_process_cmd = ['perf', 'stat', '-e', 'cycles:u,instructions:u', '-a', '-p', pid, '-o',
                                    perf_output_file, '--append', 'sleep', duration]
                sys_logger.debug("Executing PERF for process " + process)
                sys_logger.debug("PERF command : " + str(perf_process_cmd))
                p5 = subprocess.Popen(perf_process_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                p5.wait()
                error = p5.communicate()[1].strip()
                if error:
                    sys_logger.debug(error)
                sys_logger.debug("Finished PERF on process")

        sys_logger.debug("PERF complete for test : " + str(testid))
Example #4
0
    def execute(self, command, paramcsv, actionID):
        """
        This function maps daytona command with actual procedure which need to executed upon receiving a
        particular message. This mapping is saved in action.map file and procedures are implemented in action.py
        Upon mapping with actual procedure this routine spawns a new thread for executing that procedure seperately

        Below are some other action performed in this procedure :
        # based on SYNCFLAG release from here
        # send actionID for currently being executed action based on this we can stream resp
        # keep exec details over time in a buffer with actionID mapped
        # send actionID NULL and hold return till exec is complete

        """
        module = self.conf.actionMap[command.strip()].split(".")[0]
        function = self.conf.actionMap[command.strip()].split(".")[1]
        sync = self.conf.actionMap[command.strip()].split(".")[2]

        t2 = testobj.testDefn()
        hosttype = None
        if command == "DAYTONA_START_TEST":
            testid = int(paramcsv.split(",")[0])
            hosttype = paramcsv.split(",")[1]
            current_test = action.get_test(testid)
            if current_test:
                t2 = current_test.tobj

        m = __import__(module)
        f = getattr(m, function)
        if sync == "T":  # wait for func to complete and return the ret
            self.lctx.debug("Executing SYNC ACTION for " + command.strip() +
                            " : " + self.conf.actionMap[command.strip()] +
                            ":" + str(actionID))
            ret = f(self, self, command, paramcsv, actionID, sync)
            self.lctx.debug("ACTION completed for " + command.strip() + " : " +
                            self.conf.actionMap[command.strip()] + ":" +
                            str(actionID))
            if command == "DAYTONA_CLI":
                return "actionID=" + str(
                    actionID) + "%" + ret + "%" + "SYNC EXEC"
            else:
                return "actionID=" + str(
                    actionID) + "," + ret + "," + "SYNC EXEC"
        else:
            self.lctx.debug("Executing ASYNC ACTION for " + command.strip() +
                            " : " + self.conf.actionMap[command.strip()] +
                            ":" + str(actionID))
            t1 = common.FuncThread(f, True, self, command, paramcsv, actionID,
                                   sync)
            if hosttype == "EXEC":
                x = (t1, actionID, t2, time.time())
                self.lock.acquire()
                self.async_actions.append(x)
                self.lctx.debug("async_actions size :" +
                                str(len(self.async_actions)))
                self.lock.release()
            t1.start()
            self.lctx.debug("Executing ACTION for " + command.strip() + " : " +
                            self.conf.actionMap[command.strip()] + ":" +
                            str(actionID))
            return "actionID=" + str(
                actionID) + "," + "SUCCESS," + "ASYNC EXEC"