Skip to content

Commit e570193

Browse files
add timing checks for debug
1 parent 74169a0 commit e570193

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

internal_filesystem/lib/mpos/apps.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import uio
44
import ujson
55
import uos
6+
import utime # for timing calls
67

78
import _thread
89
import traceback
@@ -19,14 +20,18 @@ def good_stack_size():
1920

2021
# Run the script in the current thread:
2122
def execute_script(script_source, is_file, cwd=None, classname=None):
23+
import utime # for timing read and compile
2224
thread_id = _thread.get_ident()
2325
compile_name = 'script' if not is_file else script_source
2426
print(f"Thread {thread_id}: executing script with cwd: {cwd}")
2527
try:
2628
if is_file:
2729
print(f"Thread {thread_id}: reading script from file {script_source}")
2830
with open(script_source, 'r') as f: # No need to check if it exists as exceptions are caught
31+
start_time = utime.ticks_ms()
2932
script_source = f.read()
33+
read_time = utime.ticks_diff(utime.ticks_ms(), start_time)
34+
print(f"execute_script: reading script_source took {read_time}ms")
3035
script_globals = {
3136
'lv': lv,
3237
'__name__': "__main__"
@@ -37,8 +42,14 @@ def execute_script(script_source, is_file, cwd=None, classname=None):
3742
if cwd:
3843
sys.path.append(cwd)
3944
try:
45+
start_time = utime.ticks_ms()
4046
compiled_script = compile(script_source, compile_name, 'exec')
47+
compile_time = utime.ticks_diff(utime.ticks_ms(), start_time)
48+
print(f"execute_script: compiling script_source took {compile_time}ms")
49+
start_time = utime.ticks_ms()
4150
exec(compiled_script, script_globals)
51+
end_time = utime.ticks_diff(utime.ticks_ms(), start_time)
52+
print(f"apps.py execute_script: exec took {end_time}ms")
4253
# Introspect globals
4354
#classes = {k: v for k, v in script_globals.items() if isinstance(v, type)}
4455
#functions = {k: v for k, v in script_globals.items() if callable(v) and not isinstance(v, type)}
@@ -49,7 +60,10 @@ def execute_script(script_source, is_file, cwd=None, classname=None):
4960
if classname:
5061
main_activity = script_globals.get(classname)
5162
if main_activity:
63+
start_time = utime.ticks_ms()
5264
Activity.startActivity(None, Intent(activity_class=main_activity))
65+
end_time = utime.ticks_diff(utime.ticks_ms(), start_time)
66+
print(f"execute_script: Activity.startActivity took {end_time}ms")
5367
else:
5468
print("Warning: could not find main_activity")
5569
except Exception as e:
@@ -102,6 +116,8 @@ def start_app_by_name(app_name, is_launcher=False):
102116

103117
def start_app(app_dir, is_launcher=False):
104118
print(f"main.py start_app({app_dir},{is_launcher})")
119+
import utime
120+
start_time = utime.ticks_ms()
105121
mpos.ui.set_foreground_app(app_dir) # would be better to store only the app name...
106122
manifest_path = f"{app_dir}/META-INF/MANIFEST.JSON"
107123
app = mpos.apps.parse_manifest(manifest_path)
@@ -117,6 +133,8 @@ def start_app(app_dir, is_launcher=False):
117133
mpos.ui.open_bar()
118134
else:
119135
mpos.ui.close_bar()
136+
end_time = utime.ticks_diff(utime.ticks_ms(), start_time)
137+
print(f"start_app() took {end_time}ms")
120138

121139
def restart_launcher():
122140
mpos.ui.empty_screen_stack()
@@ -326,7 +344,10 @@ def _launch_activity(intent, result_callback=None):
326344
activity = intent.activity_class()
327345
activity.intent = intent
328346
activity._result_callback = result_callback # Pass callback to activity
347+
start_time = utime.ticks_ms()
329348
activity.onCreate()
349+
end_time = utime.ticks_diff(utime.ticks_ms(), start_time)
350+
print(f"apps.py _launch_activity: activity.onCreate took {end_time}ms")
330351
return activity
331352

332353
@staticmethod

internal_filesystem/lib/mpos/ui.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import utime # for timing calls
2+
13
import lvgl as lv
24
import mpos.apps
35

@@ -488,10 +490,21 @@ def setContentView(new_activity, new_screen):
488490
screen_stack.append((new_activity, new_screen))
489491
close_top_layer_msgboxes() # otherwise they remain
490492
if new_activity:
493+
start_time = utime.ticks_ms()
491494
new_activity.onStart(new_screen) # Initialize UI elements
495+
end_time = utime.ticks_diff(utime.ticks_ms(), start_time)
496+
print(f"ui.py setContentView: new_activity.onStart took {end_time}ms")
497+
498+
start_time = utime.ticks_ms()
492499
lv.screen_load(new_screen)
500+
end_time = utime.ticks_diff(utime.ticks_ms(), start_time)
501+
print(f"ui.py setContentView: screen_load took {end_time}ms")
502+
493503
if new_activity:
504+
start_time = utime.ticks_ms()
494505
new_activity.onResume(new_screen) # Screen is now active
506+
end_time = utime.ticks_diff(utime.ticks_ms(), start_time)
507+
print(f"ui.py setContentView: new_activity.onResume took {end_time}ms")
495508

496509

497510
def back_screen():

0 commit comments

Comments
 (0)