Skip to content

Commit

Permalink
Use less CPU during ptop
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Mar 19, 2020
1 parent 5b95e7a commit c457b81
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions px/px_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
CPUTIME_LINUX_DAYS = re.compile("^([0-9]+)-([0-9][0-9]):([0-9][0-9]):([0-9][0-9])$")


TIMEZONE = dateutil.tz.tzlocal()


uid_to_username_cache = {} # type: Dict[int, Text]


Expand All @@ -59,7 +62,7 @@ def __init__(self,
self.lowercase_command = self.command.lower() # type: text_type

time = datetime.datetime.strptime(start_time_string.strip(), "%c")
self.start_time = time.replace(tzinfo=dateutil.tz.tzlocal()) # type: datetime.datetime
self.start_time = time.replace(tzinfo=TIMEZONE) # type: datetime.datetime
self.age_seconds = (now - self.start_time).total_seconds() # type: float
assert self.age_seconds >= 0
self.age_s = seconds_to_str(self.age_seconds) # type: text_type
Expand Down Expand Up @@ -350,7 +353,7 @@ def get_all():
# type: () -> List[PxProcess]
processes = {}
ps_lines = call_ps()
now = datetime.datetime.now().replace(tzinfo=dateutil.tz.tzlocal())
now = datetime.datetime.now().replace(tzinfo=TIMEZONE)
for ps_line in ps_lines:
process = ps_line_to_process(ps_line, now)
processes[process.pid] = process
Expand Down

0 comments on commit c457b81

Please sign in to comment.