profiler
This commit is contained in:
14
journal.py
14
journal.py
@@ -1,6 +1,6 @@
|
||||
from copy import deepcopy
|
||||
from datetime import datetime, timedelta
|
||||
from functools import reduce, partial
|
||||
from functools import cache, reduce, partial
|
||||
from pathlib import Path
|
||||
from shutil import copyfile, rmtree
|
||||
from subprocess import run
|
||||
@@ -23,7 +23,7 @@ def remove_chars(text, chars):
|
||||
return ''.join([c for c in text if c not in chars])
|
||||
|
||||
def get_words(text):
|
||||
return remove_chars(text, '.,-:;').lower().split()
|
||||
return remove_chars(text, '.,-:;/').lower().split()
|
||||
|
||||
def nth_or_default(n, l, default):
|
||||
return l[n] if n < len(l) else default
|
||||
@@ -231,6 +231,7 @@ def init_hacky_hackery(journal):
|
||||
global _global_do_not_use
|
||||
_global_do_not_use = journal
|
||||
|
||||
@cache
|
||||
def get_foods_file():
|
||||
return parse_foods_file(_global_do_not_use['files']['foods'])
|
||||
|
||||
@@ -1026,6 +1027,12 @@ def handle_tasks(args):
|
||||
|
||||
save_journal(edit_entries_by_predicate(load_journal(), predicate))
|
||||
|
||||
def handle_profile(args):
|
||||
import cProfile
|
||||
|
||||
cProfile.run("export_journal(load_journal(), Path(mkdtemp()))", sort='cumtime')
|
||||
|
||||
|
||||
### MAIN
|
||||
|
||||
def main():
|
||||
@@ -1046,7 +1053,8 @@ def main():
|
||||
'summary': handle_summary,
|
||||
'backup': handle_backup,
|
||||
'search': handle_search,
|
||||
'tasks': handle_tasks
|
||||
'tasks': handle_tasks,
|
||||
'profile': handle_profile,
|
||||
}
|
||||
|
||||
handler = command_handlers.get(command, handle_invalid)
|
||||
|
||||
Reference in New Issue
Block a user