当前位置: 首页>>代码示例>>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;未经允许,请勿转载。