OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 try: | 5 try: |
6 import resource # pylint: disable=F0401 | 6 import resource # pylint: disable=F0401 |
7 except ImportError: | 7 except ImportError: |
8 resource = None # Not available on all platforms | 8 resource = None # Not available on all platforms |
9 | 9 |
10 from telemetry.core import exceptions | 10 from telemetry.core import exceptions |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 return results | 46 return results |
47 stats = stats.split() | 47 stats = stats.split() |
48 utime = float(stats[13]) | 48 utime = float(stats[13]) |
49 stime = float(stats[14]) | 49 stime = float(stats[14]) |
50 cpu_process_jiffies = utime + stime | 50 cpu_process_jiffies = utime + stime |
51 clock_ticks = self.GetClockTicks() | 51 clock_ticks = self.GetClockTicks() |
52 results.update({'CpuProcessTime': cpu_process_jiffies / clock_ticks}) | 52 results.update({'CpuProcessTime': cpu_process_jiffies / clock_ticks}) |
53 return results | 53 return results |
54 | 54 |
55 def GetCpuTimestamp(self): | 55 def GetCpuTimestamp(self): |
56 timer_list = self.GetFileContents('/proc/timer_list') | 56 total_jiffies = self._GetProcJiffies() |
57 total_jiffies = float(self._GetProcJiffies(timer_list)) | |
58 clock_ticks = self.GetClockTicks() | 57 clock_ticks = self.GetClockTicks() |
59 return {'TotalTime': total_jiffies / clock_ticks} | 58 return {'TotalTime': total_jiffies / clock_ticks} |
60 | 59 |
61 def GetMemoryStats(self, pid): | 60 def GetMemoryStats(self, pid): |
62 status_contents = self._GetProcFileForPid(pid, 'status') | 61 status_contents = self._GetProcFileForPid(pid, 'status') |
63 stats = self._GetProcFileForPid(pid, 'stat').split() | 62 stats = self._GetProcFileForPid(pid, 'stat').split() |
64 status = self._GetProcFileDict(status_contents) | 63 status = self._GetProcFileDict(status_contents) |
65 if not status or not stats or 'Z' in status['State']: | 64 if not status or not stats or 'Z' in status['State']: |
66 return {} | 65 return {} |
67 vm = int(stats[22]) | 66 vm = int(stats[22]) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 def _ConvertKbToByte(self, value): | 138 def _ConvertKbToByte(self, value): |
140 return int(value.replace('kB', '')) * 1024 | 139 return int(value.replace('kB', '')) * 1024 |
141 | 140 |
142 def _GetProcFileDict(self, contents): | 141 def _GetProcFileDict(self, contents): |
143 retval = {} | 142 retval = {} |
144 for line in contents.splitlines(): | 143 for line in contents.splitlines(): |
145 key, value = line.split(':') | 144 key, value = line.split(':') |
146 retval[key.strip()] = value.strip() | 145 retval[key.strip()] = value.strip() |
147 return retval | 146 return retval |
148 | 147 |
149 def _GetProcJiffies(self, timer_list): | 148 def _GetProcJiffies(self): |
150 """Parse '/proc/timer_list' output and returns the first jiffies attribute. | 149 """Parse '/proc/timer_list' output and returns the first jiffies attribute. |
151 | 150 |
152 Multi-CPU machines will have multiple 'jiffies:' lines, all of which will be | 151 Multi-CPU machines will have multiple 'jiffies:' lines, all of which will be |
153 essentially the same. Return the first one.""" | 152 essentially the same. Return the first one.""" |
154 if isinstance(timer_list, str): | 153 first_jiffies_timer_line = self.RunCommand( |
155 timer_list = timer_list.splitlines() | 154 ['grep', '-m', '1', 'jiffies:','/proc/timer_list']) |
aiolos (Not reviewing)
2015/04/24 23:55:15
I'm a little wary of this change because it makes
jbudorick
2015/04/24 23:56:56
Agreed, this seems like too much of an optimizatio
aiolos (Not reviewing)
2015/04/25 00:53:55
I'm much happier with that idea.
nednguyen
2015/04/25 02:02:07
Good call, done. I use regex so the parsing is mo
| |
156 for line in timer_list: | 155 if not first_jiffies_timer_line: |
157 if line.startswith('jiffies:'): | 156 raise Exception('Unable to find jiffies from /proc/timer_list') |
158 _, value = line.split(':') | 157 # The line should look something like 'jiffies: 4315883489'. |
159 return value | 158 _, value = first_jiffies_timer_line.split(':') |
160 raise Exception('Unable to find jiffies from /proc/timer_list') | 159 return float(value) |
OLD | NEW |