コード例 #1
0
ファイル: utils.py プロジェクト: teuben/admit
 def end(self):
     t0 = self.init
     t1 = self.time()
     dt = t1 - t0
     if self.report:
         logging.timing("%s END " % self.label + str(dt))
     return dt
コード例 #2
0
 def end(self):
     t0 = self.init
     t1 = self.time()
     dt = t1 - t0
     if self.report:
         logging.timing("%s END " % self.label + str(dt))
     return dt
コード例 #3
0
ファイル: utils.py プロジェクト: teuben/admit
    def get_mem(self):
        """ Read memory usage info from /proc/pid/status
            Return Virtual and Resident memory size in MBytes.
        """
        global ostype
        
        if ostype == None:
            ostype = os.uname()[0].lower()
            logging.info("OSTYPE: %s" % ostype)
            
        scale = {'MB': 1024.0}
        lines = []
        try:
            if ostype == 'linux':
                proc_status = '/proc/%d/status' % os.getpid()          # linux only
                # open pseudo file  /proc/<pid>/status
                t = open(proc_status)
                # get value from line e.g. 'VmRSS:  9999  kB\n'
                for it in t.readlines():
                    if 'VmSize' in it or 'VmRSS' in it :
                        lines.append(it)
                t.close()
            else:
                proc = subprocess.Popen(['ps','-o', 'rss', '-o', 'vsz', '-o','pid', '-p',str(os.getpid())],stdout=subprocess.PIPE)
                proc_output = proc.communicate()[0].split('\n') 
                proc_output_memory = proc_output[1]
                proc_output_memory = proc_output_memory.split()
                
                phys_mem = int(proc_output_memory[0])/1204 # to MB 
                virtual_mem = int(proc_output_memory[1])/1024 
                
        except (IOError, OSError):
            if self.report:
                logging.timing(self.label + " Error: cannot read memory usage information.")

            return np.array([])

        # parse the two lines
    
        mem = {}
        if(ostype != 'darwin'):
            for line in lines:
                words = line.strip().split()
            #print words[0], '===', words[1], '===', words[2]
                
            # get rid of the tailing ':'
                key = words[0][:-1]

            # convert from KB to MB
                scaled = float(words[1]) / scale['MB']
                mem[key] = scaled
        else:
            mem['VmSize'] = virtual_mem
            mem['VmRSS']  = phys_mem


        return np.array([mem['VmSize'], mem['VmRSS']])
コード例 #4
0
ファイル: utils.py プロジェクト: teuben/admit
 def __init__(self, label=".", report=True):
     self.start = self.time()
     self.init = self.start
     self.label = label
     self.report = report
     self.dtimes = []
     dt = self.init - self.init
     if self.report:
         logging.timing("%s ADMIT " % self.label + str(self.start))
         logging.timing("%s BEGIN " % self.label + str(dt))
コード例 #5
0
 def __init__(self, label=".", report=True):
     self.start = self.time()
     self.init = self.start
     self.label = label
     self.report = report
     self.dtimes = []
     dt = self.init - self.init
     if self.report:
         logging.timing("%s ADMIT " % self.label + str(self.start))
         logging.timing("%s BEGIN " % self.label + str(dt))
コード例 #6
0
ファイル: utils.py プロジェクト: teuben/admit
    def tag(self, mytag):

        t0 = self.start
        t1 = self.time()
        dt = t1 - t0

        # get memory usage (Virtual and Resident) info
        mem = self.get_mem()
        if mem.size != 0 :
            dt = np.append(dt, mem)

        self.dtimes.append((mytag, dt))
        self.start = t1
        if self.report:
            logging.timing("%s " % self.label + mytag + "  " + str(dt))
        return dt
コード例 #7
0
ファイル: unittest_AdmitLogging.py プロジェクト: teuben/admit
    def test_timing(self):
        msg = "unit_test_timing_message"
        Alogging.timing(msg)
 
        found = False
        r = open(self.logfile, 'r')
        for line in r.readlines():
            if msg in line:
                if(self.verbose):
                    print "\nFound message > ", found
  
                found = True
                r.close()
                break
  
        self.assertTrue(found)
コード例 #8
0
    def tag(self, mytag):

        t0 = self.start
        t1 = self.time()
        dt = t1 - t0

        # get memory usage (Virtual and Resident) info
        mem = self.get_mem()
        if mem.size != 0:
            dt = np.append(dt, mem)

        self.dtimes.append((mytag, dt))
        self.start = t1
        if self.report:
            logging.timing("%s " % self.label + mytag + "  " + str(dt))
        return dt
コード例 #9
0
ファイル: utils.py プロジェクト: teuben/admit
 def show(self):
     if self.report:
         for r in self.dtimes:
             logging.timing("%s " % self.label + str(r[0]) + "  " + str(r[1]))
     return self.dtimes
コード例 #10
0
    def get_mem(self):
        """ Read memory usage info from /proc/pid/status
            Return Virtual and Resident memory size in MBytes.
        """
        global ostype

        if ostype == None:
            ostype = os.uname()[0].lower()
            logging.info("OSTYPE: %s" % ostype)

        scale = {'MB': 1024.0}
        lines = []
        try:
            if ostype == 'linux':
                proc_status = '/proc/%d/status' % os.getpid()  # linux only
                # open pseudo file  /proc/<pid>/status
                t = open(proc_status)
                # get value from line e.g. 'VmRSS:  9999  kB\n'
                for it in t.readlines():
                    if 'VmSize' in it or 'VmRSS' in it:
                        lines.append(it)
                t.close()
            else:
                proc = subprocess.Popen([
                    'ps', '-o', 'rss', '-o', 'vsz', '-o', 'pid', '-p',
                    str(os.getpid())
                ],
                                        stdout=subprocess.PIPE)
                proc_output = proc.communicate()[0].split('\n')
                proc_output_memory = proc_output[1]
                proc_output_memory = proc_output_memory.split()

                phys_mem = int(proc_output_memory[0]) / 1204  # to MB
                virtual_mem = int(proc_output_memory[1]) / 1024

        except (IOError, OSError):
            if self.report:
                logging.timing(self.label +
                               " Error: cannot read memory usage information.")

            return np.array([])

        # parse the two lines

        mem = {}
        if (ostype != 'darwin'):
            for line in lines:
                words = line.strip().split()
                #print words[0], '===', words[1], '===', words[2]

                # get rid of the tailing ':'
                key = words[0][:-1]

                # convert from KB to MB
                scaled = float(words[1]) / scale['MB']
                mem[key] = scaled
        else:
            mem['VmSize'] = virtual_mem
            mem['VmRSS'] = phys_mem

        return np.array([mem['VmSize'], mem['VmRSS']])
コード例 #11
0
 def show(self):
     if self.report:
         for r in self.dtimes:
             logging.timing("%s " % self.label + str(r[0]) + "  " +
                            str(r[1]))
     return self.dtimes