當前位置: 首頁>>代碼示例>>Python>>正文


Python os.times方法代碼示例

本文整理匯總了Python中os.times方法的典型用法代碼示例。如果您正苦於以下問題:Python os.times方法的具體用法?Python os.times怎麽用?Python os.times使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.times方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _EncodeFile

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def _EncodeFile(self, parameters, bitrate, videofile, encodedfile):
    commandline = self.EncodeCommandLine(
      parameters, bitrate, videofile, encodedfile)

    print commandline
    with open(os.path.devnull, 'r') as nullinput:
      times_start = os.times()
      returncode = subprocess.call(commandline, shell=True, stdin=nullinput)
      times_end = os.times()
      subprocess_cpu = times_end[2] - times_start[2]
      elapsed_clock = times_end[4] - times_start[4]
      print "Encode took %f CPU seconds %f clock seconds" % (
          subprocess_cpu, elapsed_clock)
      if returncode:
        raise Exception("Encode failed with returncode %d" % returncode)
      return (subprocess_cpu, elapsed_clock) 
開發者ID:google,項目名稱:compare-codecs,代碼行數:18,代碼來源:file_codec.py

示例2: summarise_usage

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def summarise_usage():
    wall_time = humanize.naturaldelta(time.time() - __before)
    user_time = humanize.naturaldelta(os.times().user)
    sys_time = os.times().system
    if resource is None:
        # Don't report max memory on Windows. We could do this using the psutil lib, via
        # psutil.Process(os.getpid()).get_ext_memory_info().peak_wset if demand exists
        maxmem_str = ""
    else:
        max_mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
        if sys.platform != "darwin":
            max_mem *= 1024  # Linux and other OSs (e.g. freeBSD) report maxrss in kb
        maxmem_str = "; max memory={}".format(
            humanize.naturalsize(max_mem, binary=True)
        )
    logger.info("wall time = {}".format(wall_time))
    logger.info("rusage: user={}; sys={:.2f}s".format(user_time, sys_time) + maxmem_str) 
開發者ID:tskit-dev,項目名稱:tsinfer,代碼行數:19,代碼來源:cli.py

示例3: jsbeautify

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def jsbeautify(self,host):
      filename = str(os.times()[4])+"-"+host+".js"
      cmd = subprocess.Popen("js-beautify "+PATH_TMP_FILE,shell=True,stdin=subprocess.PIPE,stderr=subprocess.PIPE,stdout=subprocess.PIPE)
      error_output = cmd.stderr.read()
      if "js-beautify: command not found" in error_output or "js-beautify: not found" in error_output:
          print 'In order to jsbeautifier feature work properly, install jsbeatifier on your system with the following commands:\n'
          print 'sudo apt-get install jsbeautifier && pip install jsbeautifier'
          print "Please check if you can run it on the terminal first"
          return
      try:
              self.save_to_file(filename,cmd.stdout.read())
              print "A version of this js file has been beautified and saved at\n "+os.getcwd()+"db/files-beatified/"+filename
      except:
              print "Error in writing to file at "+os.getcwd()+"db/files-beatified/"+filename
              print "Please check the write permissions of the folder/user"
      return 
開發者ID:Lopseg,項目名稱:Jsdir,代碼行數:18,代碼來源:jsdir_linux.py

示例4: unique_id

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def unique_id(self, for_object=None):
        """
        Generates an opaque, identifier string that is practically
        guaranteed to be unique.  If an object is passed, then its
        id() is incorporated into the generation.  Relies on md5 and
        returns a 32 character long string.
        """
        r = [time.time(), random.random()]
        if hasattr(os, 'times'):
            r.append(os.times())
        if for_object is not None:
            r.append(id(for_object))
        md5_hash = md5(str(r))
        try:
            return md5_hash.hexdigest()
        except AttributeError:
            # Older versions of Python didn't have hexdigest, so we'll
            # do it manually
            hexdigest = []
            for char in md5_hash.digest():
                hexdigest.append('%02x' % ord(char))
            return ''.join(hexdigest) 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:24,代碼來源:session.py

示例5: _cpu_tot_time

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def _cpu_tot_time(times):
    """Given a cpu_time() ntuple calculates the total CPU time
    (including idle time).
    """
    tot = sum(times)
    if LINUX:
        # On Linux guest times are already accounted in "user" or
        # "nice" times, so we subtract them from total.
        # Htop does the same. References:
        # https://github.com/giampaolo/psutil/pull/940
        # http://unix.stackexchange.com/questions/178045
        # https://github.com/torvalds/linux/blob/
        #     447976ef4fd09b1be88b316d1a81553f1aa7cd07/kernel/sched/
        #     cputime.c#L158
        tot -= getattr(times, "guest", 0)  # Linux 2.6.24+
        tot -= getattr(times, "guest_nice", 0)  # Linux 3.2.0+
    return tot 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:19,代碼來源:__init__.py

示例6: test_cmdline

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def test_cmdline(self):
        cmdline = [PYTHON_EXE, "-c", "import time; time.sleep(60)"]
        sproc = get_test_subprocess(cmdline)
        try:
            self.assertEqual(' '.join(psutil.Process(sproc.pid).cmdline()),
                             ' '.join(cmdline))
        except AssertionError:
            # XXX - most of the times the underlying sysctl() call on Net
            # and Open BSD returns a truncated string.
            # Also /proc/pid/cmdline behaves the same so it looks
            # like this is a kernel bug.
            # XXX - AIX truncates long arguments in /proc/pid/cmdline
            if NETBSD or OPENBSD or AIX:
                self.assertEqual(
                    psutil.Process(sproc.pid).cmdline()[0], PYTHON_EXE)
            else:
                raise 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:19,代碼來源:test_process.py

示例7: cpu_times

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def cpu_times(percpu=False):
    """Return system-wide CPU times as a namedtuple.
    Every CPU time represents the seconds the CPU has spent in the given mode.
    The namedtuple's fields availability varies depending on the platform:
     - user
     - system
     - idle
     - nice (UNIX)
     - iowait (Linux)
     - irq (Linux, FreeBSD)
     - softirq (Linux)
     - steal (Linux >= 2.6.11)
     - guest (Linux >= 2.6.24)
     - guest_nice (Linux >= 3.2.0)

    When percpu is True return a list of namedtuples for each CPU.
    First element of the list refers to first CPU, second element
    to second CPU and so on.
    The order of the list is consistent across calls.
    """
    if not percpu:
        return _psplatform.cpu_times()
    else:
        return _psplatform.per_cpu_times() 
開發者ID:krintoxi,項目名稱:NoobSec-Toolkit,代碼行數:26,代碼來源:__init__.py

示例8: _monotonic_time

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def _monotonic_time():
    return os.times()[4] 
開發者ID:rhtyd,項目名稱:ipmisim,代碼行數:4,代碼來源:fakesession.py

示例9: _DecodeFile

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def _DecodeFile(self, videofile, encodedfile, workdir):
    tempyuvfile = os.path.join(workdir,
                               videofile.basename + 'tempyuvfile.yuv')
    if os.path.isfile(tempyuvfile):
      print "Removing tempfile before decode:", tempyuvfile
      os.unlink(tempyuvfile)
    commandline = self.DecodeCommandLine(videofile, encodedfile, tempyuvfile)
    print commandline
    with open(os.path.devnull, 'r') as nullinput:
      subprocess_cpu_start = os.times()[2]
      returncode = subprocess.call(commandline, shell=True,
                                stdin=nullinput)
      if returncode:
        raise Exception('Decode failed with returncode %d' % returncode)
      subprocess_cpu = os.times()[2] - subprocess_cpu_start
      print "Decode took %f seconds" % subprocess_cpu
      commandline = encoder.Tool("psnr") + " %s %s %d %d 9999" % (
        videofile.filename, tempyuvfile, videofile.width,
        videofile.height)
      print commandline
      psnr = subprocess.check_output(commandline, shell=True, stdin=nullinput)
      commandline = ['md5sum', tempyuvfile]
      md5 = subprocess.check_output(commandline, shell=False)
      yuv_md5 = md5.split(' ')[0]
    os.unlink(tempyuvfile)
    return psnr, subprocess_cpu, yuv_md5 
開發者ID:google,項目名稱:compare-codecs,代碼行數:28,代碼來源:file_codec.py

示例10: time

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def time():
    t = os.times()
    return t[0] + t[1] 
開發者ID:probcomp,項目名稱:bayeslite,代碼行數:5,代碼來源:speedtest.py

示例11: _get_time_times

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def _get_time_times(timer=os.times):
        t = timer()
        return t[0] + t[1]

# Using getrusage(3) is better than clock(3) if available:
# on some systems (e.g. FreeBSD), getrusage has a higher resolution
# Furthermore, on a POSIX system, returns microseconds, which
# wrap around after 36min. 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:10,代碼來源:profile.py

示例12: threads

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def threads(self):
            """Return threads opened by process as a list of
            (id, user_time, system_time) namedtuples representing
            thread id and thread CPU times (user/system).
            On OpenBSD this method requires root access.
            """
            return self._proc.threads() 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:9,代碼來源:__init__.py

示例13: cpu_times

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def cpu_times(self):
        """Return a (user, system, children_user, children_system)
        namedtuple representing the accumulated process time, in
        seconds.
        This is similar to os.times() but per-process.
        On OSX and Windows children_user and children_system are
        always set to 0.
        """
        return self._proc.cpu_times() 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:11,代碼來源:__init__.py

示例14: _cpu_busy_time

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def _cpu_busy_time(times):
    """Given a cpu_time() ntuple calculates the busy CPU time.
    We do so by subtracting all idle CPU times.
    """
    busy = _cpu_tot_time(times)
    busy -= times.idle
    # Linux: "iowait" is time during which the CPU does not do anything
    # (waits for IO to complete). On Linux IO wait is *not* accounted
    # in "idle" time so we subtract it. Htop does the same.
    # References:
    # https://github.com/torvalds/linux/blob/
    #     447976ef4fd09b1be88b316d1a81553f1aa7cd07/kernel/sched/cputime.c#L244
    busy -= getattr(times, "iowait", 0)
    return busy 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:16,代碼來源:__init__.py

示例15: test_cpu_times

# 需要導入模塊: import os [as 別名]
# 或者: from os import times [as 別名]
def test_cpu_times(self):
        times = psutil.Process().cpu_times()
        assert (times.user > 0.0) or (times.system > 0.0), times
        assert (times.children_user >= 0.0), times
        assert (times.children_system >= 0.0), times
        # make sure returned values can be pretty printed with strftime
        for name in times._fields:
            time.strftime("%H:%M:%S", time.localtime(getattr(times, name))) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:10,代碼來源:test_process.py


注:本文中的os.times方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。