Skip to content

Commit

Permalink
fix: [crashlogs] improve timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
cvandeplas committed Nov 26, 2024
1 parent 37e962a commit c50f7a4
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/sysdiagnose/parsers/crashlogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def execute(self) -> list | dict:
for file in files:
logger.info(f"Processing file: {file}")
if file.endswith('crashes_and_spins.log'):
result.extend(CrashLogsParser.parse_summary_file(file))
result.extend(self.parse_summary_file(file))
elif os.path.basename(file).startswith('.'):
pass
elif file.endswith('.ips'):
Expand Down Expand Up @@ -192,15 +192,15 @@ def process_ips_lines(lines: list) -> dict:

return result

def parse_summary_file(path: str) -> list | dict:
def parse_summary_file(self, path: str) -> list | dict:
logger.info(f"Parsing summary file: {path}")
result = []
with open(path, 'r') as f:
for line in f:
if not line.startswith('/'):
continue

app, timestamp = CrashLogsParser.metadata_from_filename(line)
app, timestamp = self.metadata_from_filename(line)
path = line.split(',')[0]
entry = {
'app_name': app,
Expand All @@ -209,8 +209,7 @@ def parse_summary_file(path: str) -> list | dict:
'timestamp': timestamp.timestamp(),
'filename': os.path.basename(path),
'path': path,
'warning': 'Timezone not considered, parsed local time as UTC'
# FIXME timezone is from local phone time at file creation. Not UTC
'warning': 'Timezone may be wrong, parsed local time as same timezone as sysdiagnose creation time'
}
result.append(entry)
return result
Expand Down Expand Up @@ -250,7 +249,7 @@ def split_binary_images(line) -> dict:
}
return result

def metadata_from_filename(filename: str) -> tuple[str, datetime]:
def metadata_from_filename(self, filename: str) -> tuple[str, datetime]:
while True:
# option 1: YYYY-MM-DD-HHMMSS
m = re.search(r'/([^/]+)-(\d{4}-\d{2}-\d{2}-\d{6})', filename)
Expand All @@ -267,6 +266,6 @@ def metadata_from_filename(filename: str) -> tuple[str, datetime]:
return app, datetime.fromtimestamp(0, tz=timezone.utc)

app = m.group(1)
# FIXME timezone is from local phone time at file creation. Not UTC
timestamp = timestamp.replace(tzinfo=timezone.utc)
# FIXME timezone is from local phone time at file creation. Not the TZ while creating the sysdiagnose image
timestamp = timestamp.replace(tzinfo=self.sysdiagnose_creation_datetime.tzinfo)
return app, timestamp

0 comments on commit c50f7a4

Please sign in to comment.