X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=blobdiff_plain;f=lib%2Fpython%2FTools%2FProfile.py;h=4d8dd9012841311f2ef3e64a8137e6fcbe69af77;hp=1c44bc84578e611999db4ab5e88fd019e5bf51eb;hb=36cca1d3f31265929ef3443999ab7fd242b4dae5;hpb=dd0d9dfcca6d9c0d7babba263c7d476c97f1f7ba diff --git a/lib/python/Tools/Profile.py b/lib/python/Tools/Profile.py index 1c44bc8..4d8dd90 100644 --- a/lib/python/Tools/Profile.py +++ b/lib/python/Tools/Profile.py @@ -1,5 +1,6 @@ +# the implementation here is a bit crappy. import time -from Directories import resolveFilename, SCOPE_SYSETC +from Directories import resolveFilename, SCOPE_CONFIG PERCENTAGE_START = 50 PERCENTAGE_END = 100 @@ -8,9 +9,10 @@ profile_start = time.time() profile_data = {} total_time = 1 +profile_file = None try: - profile_old = open(resolveFilename(SCOPE_SYSETC, "profile"), "r").readlines() + profile_old = open(resolveFilename(SCOPE_CONFIG, "profile"), "r").readlines() t = None for line in profile_old: @@ -21,19 +23,23 @@ try: except: print "no profile data available" -profile_file = open(resolveFilename(SCOPE_SYSETC, "profile"), "w") +try: + profile_file = open(resolveFilename(SCOPE_CONFIG, "profile"), "w") +except IOError: + print "WARNING: couldn't open profile file!" def profile(id): now = time.time() - profile_start if profile_file: profile_file.write("%.2f\t%s\n" % (now, id)) - if id in profile_data: - t = profile_data[id] - perc = t * (PERCENTAGE_END - PERCENTAGE_START) / total_time + PERCENTAGE_START - try: - open("/proc/progress", "w").write("%d \n" % perc) - except IOError: - pass + + if id in profile_data: + t = profile_data[id] + perc = t * (PERCENTAGE_END - PERCENTAGE_START) / total_time + PERCENTAGE_START + try: + open("/proc/progress", "w").write("%d \n" % perc) + except IOError: + pass def profile_final(): global profile_file