Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py

Issue 1106043003: [Telemetry] Improve _GetProcJiffies operation with using grep. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update unittest to better match actual /proc/timer_list file Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/telemetry/telemetry/core/platform/linux_based_platform_backend_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import re
11
10 from telemetry.core import exceptions 12 from telemetry.core import exceptions
11 from telemetry.core.platform import platform_backend 13 from telemetry.core.platform import platform_backend
12 from telemetry import decorators 14 from telemetry import decorators
13 15
14 16
15 class LinuxBasedPlatformBackend(platform_backend.PlatformBackend): 17 class LinuxBasedPlatformBackend(platform_backend.PlatformBackend):
16 18
17 """Abstract platform containing functionality shared by all Linux based OSes. 19 """Abstract platform containing functionality shared by all Linux based OSes.
18 20
19 This includes Android and ChromeOS. 21 This includes Android and ChromeOS.
(...skipping 26 matching lines...) Expand all
46 return results 48 return results
47 stats = stats.split() 49 stats = stats.split()
48 utime = float(stats[13]) 50 utime = float(stats[13])
49 stime = float(stats[14]) 51 stime = float(stats[14])
50 cpu_process_jiffies = utime + stime 52 cpu_process_jiffies = utime + stime
51 clock_ticks = self.GetClockTicks() 53 clock_ticks = self.GetClockTicks()
52 results.update({'CpuProcessTime': cpu_process_jiffies / clock_ticks}) 54 results.update({'CpuProcessTime': cpu_process_jiffies / clock_ticks})
53 return results 55 return results
54 56
55 def GetCpuTimestamp(self): 57 def GetCpuTimestamp(self):
56 timer_list = self.GetFileContents('/proc/timer_list') 58 total_jiffies = self._GetProcJiffies()
57 total_jiffies = float(self._GetProcJiffies(timer_list))
58 clock_ticks = self.GetClockTicks() 59 clock_ticks = self.GetClockTicks()
59 return {'TotalTime': total_jiffies / clock_ticks} 60 return {'TotalTime': total_jiffies / clock_ticks}
60 61
61 def GetMemoryStats(self, pid): 62 def GetMemoryStats(self, pid):
62 status_contents = self._GetProcFileForPid(pid, 'status') 63 status_contents = self._GetProcFileForPid(pid, 'status')
63 stats = self._GetProcFileForPid(pid, 'stat').split() 64 stats = self._GetProcFileForPid(pid, 'stat').split()
64 status = self._GetProcFileDict(status_contents) 65 status = self._GetProcFileDict(status_contents)
65 if not status or not stats or 'Z' in status['State']: 66 if not status or not stats or 'Z' in status['State']:
66 return {} 67 return {}
67 vm = int(stats[22]) 68 vm = int(stats[22])
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 def _ConvertKbToByte(self, value): 140 def _ConvertKbToByte(self, value):
140 return int(value.replace('kB', '')) * 1024 141 return int(value.replace('kB', '')) * 1024
141 142
142 def _GetProcFileDict(self, contents): 143 def _GetProcFileDict(self, contents):
143 retval = {} 144 retval = {}
144 for line in contents.splitlines(): 145 for line in contents.splitlines():
145 key, value = line.split(':') 146 key, value = line.split(':')
146 retval[key.strip()] = value.strip() 147 retval[key.strip()] = value.strip()
147 return retval 148 return retval
148 149
149 def _GetProcJiffies(self, timer_list): 150 def _GetProcJiffies(self):
150 """Parse '/proc/timer_list' output and returns the first jiffies attribute. 151 """Parse '/proc/timer_list' output and returns the first jiffies attribute.
151 152
152 Multi-CPU machines will have multiple 'jiffies:' lines, all of which will be 153 Multi-CPU machines will have multiple 'jiffies:' lines, all of which will be
153 essentially the same. Return the first one.""" 154 essentially the same. Return the first one."""
154 if isinstance(timer_list, str): 155 jiffies_timer_lines = self.RunCommand(
155 timer_list = timer_list.splitlines() 156 ['grep', 'jiffies','/proc/timer_list'])
156 for line in timer_list: 157 if not jiffies_timer_lines:
157 if line.startswith('jiffies:'): 158 raise Exception('Unable to find jiffies from /proc/timer_list')
158 _, value = line.split(':') 159 jiffies_timer_list = jiffies_timer_lines.splitlines()
159 return value 160 # Each line should look something like 'jiffies: 4315883489'.
160 raise Exception('Unable to find jiffies from /proc/timer_list') 161 for line in jiffies_timer_list:
162 print repr(line)
163 match = re.match('\s*jiffies\s*:\s*(\d+)', line)
164 if match:
165 value = match.group(1)
166 return float(value)
167 raise Exception('Unable to parse jiffies attribute: %s' %
168 repr(jiffies_timer_lines))
OLDNEW
« no previous file with comments | « no previous file | tools/telemetry/telemetry/core/platform/linux_based_platform_backend_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698