tizen 2.3.1 release
[framework/web/mobile/wrt.git] / src / profiling / script / ranges.py
1 #!/usr/bin/python
2 # Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 #
4 #    Licensed under the Apache License, Version 2.0 (the "License");
5 #    you may not use this file except in compliance with the License.
6 #    You may obtain a copy of the License at
7 #
8 #        http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS,
12 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #    See the License for the specific language governing permissions and
14 #    limitations under the License.
15 #
16
17 import os,sys
18
19 def main():
20   if sys.version[0] != "2":
21     exit(1)
22
23   f = open('ranges', 'r')
24   # Array of ranges.
25   ranges = []
26   for line in f:
27     r = line.rstrip().split(':')
28     r.append(0)
29     r.append(0)
30     r.append(0)
31     ranges.append(r)
32   f.close()
33
34   # find directories with results
35   for root, dirs, files in os.walk('OUTPUT'):
36     path = root.rsplit('/',1)
37     if path[len(path)-1] not in ['cold','warm','preload']:
38       continue
39
40     # open file with measurements
41     print '\n' + root
42     output = open(root + '/outpucik-points', 'r')
43
44     # find matching points
45     for r in ranges:
46       output.seek(0)
47       for l in output:
48         if r[1] in l:
49           r[3] = l.split(',')[1]
50         if r[2] in l:
51           r[4] = l.split(',')[1]
52
53     output.close()
54
55     # calculate the difference
56     for r in ranges:
57       r[5] = int(r[4]) - int(r[3])
58
59     # save calculations
60     results = open(root + '/outpucik-results','w')
61     for r in ranges:
62       print " " + r[0] + ": " + str(float(r[5])/1000) + "ms"
63       results.write(r[0] + ": " + str(float(r[5])/1000) + "ms\n")
64     results.close()
65
66 if __name__ == "__main__":
67   main()
68