Return number of jiffies elapsed. Return number of jiffies (1/100ths of a second) that this process has been scheduled in user mode. See man 5 proc.
(_proc_pid_stat=f'/proc/{os.getpid()}/stat', _load_time=[])
| 147 | |
| 148 | if sys.platform[:5] == 'linux': |
| 149 | def jiffies(_proc_pid_stat=f'/proc/{os.getpid()}/stat', _load_time=[]): |
| 150 | """ |
| 151 | Return number of jiffies elapsed. |
| 152 | |
| 153 | Return number of jiffies (1/100ths of a second) that this |
| 154 | process has been scheduled in user mode. See man 5 proc. |
| 155 | |
| 156 | """ |
| 157 | import time |
| 158 | if not _load_time: |
| 159 | _load_time.append(time.time()) |
| 160 | try: |
| 161 | with open(_proc_pid_stat) as f: |
| 162 | l = f.readline().split(' ') |
| 163 | return int(l[13]) |
| 164 | except Exception: |
| 165 | return int(100*(time.time()-_load_time[0])) |
| 166 | else: |
| 167 | # os.getpid is not in all platforms available. |
| 168 | # Using time is safe but inaccurate, especially when process |