Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
Does iowait time counted while psutil.cpu_percent are called?

I want to know if iowait time are counted in psutil.cpu_percent(), so write a code as below to test

#cat test.py
import os
import psutil
import time


p = psutil.Process(os.getpid())


start = time.time()
times_before_workload = p.cpu_times()
# this function return cpu_percent between two call. so we have to call it once before workload
percent_before_workload = p.cpu_percent()  


# I call f open/close many times and read from the file 
# hoping cpu will spent time on both user system and iowait

c = 1000
while c:
    f = open('/tmp/big_text')
    content = f.read(10240)
    f.close()
    c -= 1

end = time.time()
percent_after_workload = p.cpu_percent()


times_after_workload = p.cpu_times()
user_seconds = times_after_workload.user - times_before_workload.user
system_seconds = times_after_workload.system - times_before_workload.system
iowait_seconds = times_after_workload.iowait - times_before_workload.iowait

# if cpu percent == user_percent + system_percent + iowait_percent then it means yes. iowait are counted

print 'user_percent %s' % round(user_seconds / (end - start) * 100, 2)
print 'system_percent %s' % round(system_seconds / (end - start) * 100, 2)
print 'iowait_percent %s' % round(iowait_seconds / (end - start) * 100, 2)
print 'percent %s' % percent_after_workload

here is this output

#python test.py
user_percent 67.06
system_percent 67.06
iowait_percent 0.0
percent 134.8

The iowait is 0 so still can not verify. So question are

  1. does iowait counted in cpu percent?
  2. how to make iowait happen?(no zero)
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

  1. No, iowait is not counted in cpu percent.
  2. Run vmtouch to evict pages from memory at the start of each iteration of the loop.

You may need to install vmtouch:

apt update
apt install vmtouch

Run vmtouch in Python:

import subprocess

subprocess.run(['vmtouch', '-e', '/tmp/big_text'], stdout=subprocess.DEVNULL)

Reference: Why iowait of reading file is zero?

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda