import re
line = ('2011/09/27 07:07:05 545 1322 I KERNEL : [15111.908075] Bluetooth:'
' SCO socket layer initialized')
found_date_time = re.search(r'\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}', line)
if found_date_time:
print found_date_time.group()
2011/09/27 07:07:05
import time
s = '2011/09/27 07:07:05 545 1322 I KERNEL : [15111.908075] Bluetooth: SCO socket layer initialized'
s = s.split()
t = time.strptime(s[0]+s[1],"%Y/%m/%d%H:%M:%S")
print(t)
time.struct_time(tm_year=2011, tm_mon=9, tm_mday=27, tm_hour=7, tm_min=7, tm_sec=5, tm_wday=1, tm_yday=270, tm_isdst=-1)

KERNEL_TIME_STAMP =\
re.compile('^(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})\.(\d{3}) (.*)')
def time_and_body(line):
print line
n = KERNEL_TIME_STAMP.match(line)
if n is None:
return (None,None)
k_time = n.groups()[2]+'.'+n.groups()[3]+'.'+n.groups()[4]+'.'+n.groups()[5]
print k_time
return (k_time,n.groups()[6])line = ('2011/09/27 07:07:05 545 1322 I KERNEL : [15111.908075] Bluetooth:'
' SCO socket layer initialized')(None, None)line = ('2011/09/27 07:07:05 545 1322 I KERNEL : [15111.908075] Bluetooth:'
' SCO socket layer initialized')
KERNEL_TIME_STAMP = re.compile(r'(\d{2}:\d{2}:\d{2}) (\d{3})')
def time_and_body2(line):
result = KERNEL_TIME_STAMP.search(line)
return result.groups() if result else (None, None)
print time_and_body2(line)('07:07:05', '545')
cur_state['kernel_time_stamp'] = ' ' as string
#This is where its defining current time from log,
def __current_time(c):
return int(c['kernel_time_stamp'])
----------------------------------------------------------------
current time is called here,
def roll(fobj_in, fobj_out):
cur_state = __init_cur()
live_sessions = dict()
live_sessions['full'] = None
live_sessions['discharge'] = None
live_sessions['charge'] = None
live_sessions['active'] = None
live_sessions['suspend'] = None
live_sessions['wakeup'] = None # started from wakeup_wakelock, ended
live_sessions['last_active'] = None
try:
l = fobj_in.readline()
while (len(l)):
t,b = time_and_body(l)
if t is not None:
cur_state['kernel_time_stamp'] = t
if not live_sessions['full']:
live_sessions['full'] = FullLogSession(
start = t,
start_time = __current_time(cur_state))
live_sessions['discharge'] = DischargeSession(
start = t,
start_time = __current_time(cur_state))
for k in REGEX.keys():
r,f = REGEX[k]
m = r.match(b)
if m is not None:
if f in globals().keys():
hook = globals()[f]
hook(live_sessions, cur_state, m)
l = fobj_in.readline()
# close all live sessions
__close_sessions(live_sessions, cur_state)
live_sessions['full'].end = cur_state['kernel_time_stamp']
live_sessions['full'].end_time = __current_time(cur_state)
live_sessions['full'].duration = __duration(live_sessions['full'])\
+ live_sessions['full'].rtc_only
except:
__debug_print_all(live_sessions, cur_state)
raise
if not TECH and not VERBOSE:
if cur_state['cpu1_on'] > 0:
live_sessions['full'].cpu1_time += __current_time(cur_state) - cur_state['cpu1_on']
if cur_state['charging_start'] > 0:
live_sessions['full'].usb_time += __current_time(cur_state) - cur_state['charging_start']
return live_sessions['full']
line = ('2011/09/27 07:07:05 545 1322 I KERNEL : [15111.908075] Bluetooth:'
' SCO socket layer initialized')
KERNEL_TIME_STAMP = re.compile(r'(\d{2}):(\d{2}):(\d{2}) (\d{3}) (.*)')
def time_and_body3(line):
result = KERNEL_TIME_STAMP.search(line)
if result:
groups = result.groups()
return '{}.{}.{}.{}'.format(*groups[:4]), groups[4]
return (None, None)
print time_and_body3(line)
('07.07.05.545', '1322 I KERNEL : [15111.908075] Bluetooth: SCO socket layer initialized')
cur_state['kernel_time_stamp'] = ' ' as string raohiral wrote:ValueError: invalid literal for int() with base 10: '16:25:51.946' ..

KERNEL_TIME_STAMP =\
re.compile(r'(\d{2}:\d{2}:\d{2}.\d{3}) (.*)') #re.compile('^<\d>\[ *(\d+)\.(\d{6})[^\]]*\] (.*)')
LOGCAT_TIME_STAMP =\
re.compile('^(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})\.(\d{3}) (.*)')
def time_and_body(line):
print line
n = KERNEL_TIME_STAMP.search(line)
if n:
groups = n.groups()
return '{}.{}.{}.{}'.format(*groups[:4]), groups[4]
return (None, None)
KERNEL_TIME_STAMP = re.compile(r'(\d{2}):(\d{2}):(\d{2}) (\d{3}) (.*)') # mine
KERNEL_TIME_STAMP = re.compile(r'(\d{2}:\d{2}:\d{2}.\d{3}) (.*)') # yours
live_sessions['full'] = FullLogSession(
start = t,
start_time = __current_time(cur_state))live_sessions['full'] = Nonelive_sessions['full'].end = cur_state['kernel_time_stamp']
class FullLogSession(Session):
def __init__(self,
start=UNKNOWN,
start_time=0,
end=-2, #UNKNOWN,
duration=0.0,
cost=0.0,
typ=UNKNOWN,
reason = UNKNOWN):
super(FullLogSession, self).__init__(
start, start_time, end, duration, cost, typ, reason)
self.discharge_sessions = list()
self.tops = dict()
self.tops['cost_displayon'] = Top('cost')
self.tops['duration_displayon'] = Top('duration')
self.tops['cost_active'] = Top('cost')
self.tops['duration_active'] = Top('duration')
self.tops['cost_awoken'] = Top('cost')
self.tops['duration_awoken'] = Top('duration')
if not TECH and not VERBOSE:
self.usb_time = 0.0
self.cpu1_time = 0.0
self.full_stats = dict()
self.full_stats['BACKGROUND'] = dict()
self.full_stats['ABORT'] = dict()
self.full_stats['DEVICE'] = dict()
self.full_stats['DISPLAY'] = dict()
self.full_stats['DISPLAYOFF'] = dict()
self.full_stats['LONGEST'] = dict()
self.active_sum = Sum()
self.suspend_sum = Sum()
self.head = 0.0
self.tail = 0.0def __current_time(c):
return float(c['kernel_time_stamp'])
def __current_time(c):
return len(c['kernel_time_stamp'])
cur_state['kernel_time_stamp'] = ' ' as string
#This is where its defining current time from log,
def __current_time(c):
return int(c['kernel_time_stamp'])
----------------------------------------------------------------
current time is called here,
def roll(fobj_in, fobj_out):
cur_state = __init_cur()
live_sessions = dict()
live_sessions['full'] = None ################# set to None here
live_sessions['discharge'] = None
live_sessions['charge'] = None
live_sessions['active'] = None
live_sessions['suspend'] = None
live_sessions['wakeup'] = None # started from wakeup_wakelock, ended
live_sessions['last_active'] = None
try:
l = fobj_in.readline()
while (len(l)):
t,b = time_and_body(l)
if t is not None: ################ t must be resulting to None because one of your readlines is not a re match so the following code is skipped
cur_state['kernel_time_stamp'] = t
if not live_sessions['full']:
live_sessions['full'] = FullLogSession( ################### this is not called
start = t,
start_time = __current_time(cur_state))
live_sessions['discharge'] = DischargeSession(
start = t,
start_time = __current_time(cur_state))
for k in REGEX.keys():
r,f = REGEX[k]
m = r.match(b)
if m is not None:
if f in globals().keys():
hook = globals()[f]
hook(live_sessions, cur_state, m)
l = fobj_in.readline()
# close all live sessions #################################################### the code is carrying on from here
__close_sessions(live_sessions, cur_state)
live_sessions['full'].end = cur_state['kernel_time_stamp'] ########################## this cannot be set as live_sessions['full'] = None
live_sessions['full'].end_time = __current_time(cur_state)
live_sessions['full'].duration = __duration(live_sessions['full'])\
+ live_sessions['full'].rtc_only
except:
__debug_print_all(live_sessions, cur_state)
raise
if not TECH and not VERBOSE:
if cur_state['cpu1_on'] > 0:
live_sessions['full'].cpu1_time += __current_time(cur_state) - cur_state['cpu1_on']
if cur_state['charging_start'] > 0:
live_sessions['full'].usb_time += __current_time(cur_state) - cur_state['charging_start']
return live_sessions['full']

def __current_time(c):
return float(c['kernel_time_stamp'])TypeError: float() argument must be a string or a number

Users browsing this forum: raynox and 1 guest