allow burning DVDs with multiple titles where playback automatically jumps to the...
[enigma2.git] / lib / python / Tools / Profile.py
1 # the implementation here is a bit crappy.
2 import time
3 from Directories import resolveFilename, SCOPE_CONFIG
4
5 PERCENTAGE_START = 50
6 PERCENTAGE_END = 100
7
8 profile_start = time.time()
9
10 profile_data = {}
11 total_time = 1
12
13 try:
14         profile_old = open(resolveFilename(SCOPE_CONFIG, "profile"), "r").readlines()
15
16         t = None
17         for line in profile_old:
18                 (t, id) = line[:-1].split('\t')
19                 t = float(t)
20                 total_time = t
21                 profile_data[id] = t
22 except:
23         print "no profile data available"
24
25 profile_file = open(resolveFilename(SCOPE_CONFIG, "profile"), "w")
26
27 def profile(id):
28         now = time.time() - profile_start
29         if profile_file:
30                 profile_file.write("%.2f\t%s\n" % (now, id))
31
32                 if id in profile_data:
33                         t = profile_data[id]
34                         perc = t * (PERCENTAGE_END - PERCENTAGE_START) / total_time + PERCENTAGE_START
35                         try:
36                                 open("/proc/progress", "w").write("%d \n" % perc)
37                         except IOError:
38                                 pass
39
40 def profile_final():
41         global profile_file
42         if profile_file is not None:
43                 profile_file.close()
44                 profile_file = None