From b5b8632c9fe298c2d2bad262afc290d9d0949b7c Mon Sep 17 00:00:00 2001 From: Anne Zyllee Date: Tue, 19 Mar 2024 18:04:13 -0400 Subject: [PATCH] add readme, start and quit logging --- README_MONITORING.md | 32 ++++++++++++++++++++++++++++++++ src/calibre/gui2/__init__.py | 11 +++++------ src/calibre/gui2/add.py | 2 +- src/calibre/gui2/main.py | 13 ++++++++++--- src/calibre/gui2/ui.py | 15 ++++++++++++--- 5 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 README_MONITORING.md diff --git a/README_MONITORING.md b/README_MONITORING.md new file mode 100644 index 000000000000..adebbc892e41 --- /dev/null +++ b/README_MONITORING.md @@ -0,0 +1,32 @@ +## Steps to execute +Please note that these steps have been designed for, and verified on, a M2 mac running macOS. + +### Step 1 +Clone the forked Calibre repository and check out the `monitoring` branch +``` +git clone https://github.com/annegu/calibre.git -- branch monitoring +``` + +### Step 2 +Download Version 7.7.0 of Calibre ebook reader for macOS at https://calibre-ebook.com/download_osx + +### Step 3 +Create the following script at `/usr/local/bin/calibre-develop` +``` +#!/bin/sh +export CALIBRE_DEVELOP_FROM="ABSOLUTE_PATH_OF_CLONED_REPO" +/Applications/calibre.app/Contents/MacOS/calibre-debug -g +``` +Depending on your permissions, `sudo` may be needed in order to create the script. + +For reference see https://manual.calibre-ebook.com/develop.html#macos-development-environment + +### Step 4 + +Give `calibre-develop` execute permissions +``` +chmod +x /usr/local/bin/calibre-develop +``` + +### Step 5 +Run `./calibre-develop` from `/usr/local/bin/` to see the new logs on output! \ No newline at end of file diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 423791751fc4..91aad747560a 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -1680,12 +1680,11 @@ def make_view_use_window_background(view): def timed_print(*a, **kw): - if not DEBUG: - return - from time import monotonic - if not hasattr(timed_print, 'startup_time'): - timed_print.startup_time = monotonic() - print(f'[{monotonic() - timed_print.startup_time:.2f}]', *a, **kw) + if DEBUG: + from time import monotonic + if not hasattr(timed_print, 'startup_time'): + timed_print.startup_time = monotonic() + print(f'[{monotonic() - timed_print.startup_time:.2f}]', *a, **kw) def local_path_for_resource(qurl: QUrl, base_qurl: 'QUrl | None' = None) -> str: diff --git a/src/calibre/gui2/add.py b/src/calibre/gui2/add.py index 2327a0334f2b..a72293027277 100644 --- a/src/calibre/gui2/add.py +++ b/src/calibre/gui2/add.py @@ -24,7 +24,7 @@ from calibre.ebooks.metadata import authors_to_sort_string from calibre.ebooks.metadata.book.base import Metadata from calibre.ebooks.metadata.opf2 import OPF -from calibre.gui2 import error_dialog, gprefs, warning_dialog +from calibre.gui2 import error_dialog, gprefs, warning_dialog, timed_print from calibre.gui2.dialogs.duplicates import DuplicatesQuestion from calibre.gui2.dialogs.progress import ProgressDialog from calibre.ptempfile import PersistentTemporaryDirectory diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 54f849fc0f19..80ac34d17e58 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -235,7 +235,7 @@ class GuiRunner(QObject): def __init__(self, opts, args, actions, app, gui_debug=None): self.startup_time = monotonic() - timed_print('Starting up...') + timed_print('\n********** Starting Up **********') self.opts, self.args, self.app = opts, args, app self.gui_debug = gui_debug self.actions = actions @@ -261,6 +261,7 @@ def start_gui(self, db): timed_print('splash screen hidden') self.splash_screen = None timed_print('Started up in %.2f seconds'%(monotonic() - self.startup_time), 'with', len(db.data), 'books') + timed_print("\n******** Startup Complete *******\n") main.set_exception_handler() if len(self.args) > 1: main.handle_cli_args(self.args[1:]) @@ -275,13 +276,13 @@ def choose_dir(self, initial_dir): default_dir=initial_dir) def show_error(self, title, msg, det_msg=''): - print(det_msg, file=sys.stderr) + timed_print(det_msg, file=sys.stderr) self.hide_splash_screen() with self.app: error_dialog(self.splash_screen, title, msg, det_msg=det_msg, show=True) def initialization_failed(self): - print('Catastrophic failure initializing GUI, bailing out...') + timed_print('Catastrophic failure initializing GUI, bailing out...') QCoreApplication.exit(1) raise SystemExit(1) @@ -341,10 +342,13 @@ def initialize_db(self): # On some windows systems the existing db file gets locked # by something when running restore from the main process. # So run the restore in a separate process. + + timed_print('Restoring db in separate process on Windows...') windows_repair(self.library_path) self.app.quit() return if repair_library(self.library_path): + timed_print('Initializing new db...') db = LibraryDatabase(self.library_path) except: self.show_error(_('Bad database location'), @@ -363,6 +367,7 @@ def show_splash_screen(self): def hide_splash_screen(self): if self.splash_screen is not None: + timed_print('Hiding splash screen...') self.splash_screen.hide() self.splash_screen = None @@ -387,6 +392,8 @@ def run_in_debug_mode(): '--gui-debug', logpath, stdout=open(logpath, 'wb'), stderr=subprocess.STDOUT, stdin=open(os.devnull, 'rb')) + timed_print('Running in Debug Mode..') + def run_gui(opts, args, app, gui_debug=None): with SingleInstance('db') as si: diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index e1d438f9c030..55bdfe57e9ce 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -224,6 +224,7 @@ def initialize(self, library_path, db, actions, show_gui=True): t.setInterval(1000), t.timeout.connect(self.handle_changes_from_server_debounced), t.setSingleShot(True) self._spare_pool = None self.must_restart_before_config = False + timed_print("Initializing UI components...") for ac in self.iactions.values(): try: @@ -368,6 +369,7 @@ def initialize(self, library_path, db, actions, show_gui=True): # ######################## Search Restriction ########################## if db.new_api.pref('virtual_lib_on_startup'): + timed_print("Applying search restriction...") self.apply_virtual_library(db.new_api.pref('virtual_lib_on_startup')) self.rebuild_vl_tabs() @@ -441,6 +443,7 @@ def post_initialize_actions(self): if self.layout_container.is_visible.quick_view: self.iactions['Quickview'].show_on_startup() self.listener.start_listening() + timed_print("Starting UI listener...") self.start_smartdevice() # Collect cycles now gc.collect() @@ -558,9 +561,6 @@ def do_proceed(self, func, payload): if callable(func): func(payload) - def no_op(self, *args): - pass - def system_tray_icon_activated(self, r=False): if r in (QSystemTrayIcon.ActivationReason.Trigger, QSystemTrayIcon.ActivationReason.MiddleClick, False): if self.isVisible(): @@ -593,6 +593,7 @@ def update_toggle_to_tray_action(self, *args): _('Hide main window') if self.isVisible() else _('Show main window')) def hide_windows(self): + timed_print("Window hidden") for window in QApplication.topLevelWidgets(): if isinstance(window, (MainWindow, QDialog)) and \ window.isVisible(): @@ -601,6 +602,7 @@ def hide_windows(self): self.update_toggle_to_tray_action() def show_windows(self, *args): + timed_print("Window shown") for window in QApplication.topLevelWidgets(): if getattr(window, '__systray_minimized', False): window.show() @@ -1169,6 +1171,7 @@ def quit(self, checked=True, restart=False, debug_on_restart=False, def donate(self, *args): from calibre.utils.localization import localize_website_link open_url(QUrl(localize_website_link('https://calibre-ebook.com/donate'))) + timed_print("Donation created") def confirm_quit(self): if self.job_manager.has_jobs(): @@ -1187,9 +1190,11 @@ def confirm_quit(self): if not question_dialog(self, _('Library updates waiting'), msg): return False + timed_print('\n********* Shutting Down *********') return True def shutdown(self, write_settings=True): + timed_print("UI shutting down...") self.shutting_down = True if hasattr(self.library_view, 'connect_to_book_display_timer'): self.library_view.connect_to_book_display_timer.stop() @@ -1227,7 +1232,10 @@ def shutdown(self, write_settings=True): self.write_settings() if getattr(self, 'update_checker', None): self.update_checker.shutdown() + + timed_print('Closing UI listener...') self.listener.close() + timed_print('Closing UI servers...') self.job_manager.server.close() self.job_manager.threaded_server.close() self.device_manager.keep_going = False @@ -1277,6 +1285,7 @@ def eh(t, v, tb): wait_for_cleanup() wait_for_stop() self.shutdown_completed.emit() + timed_print('\n******* Shutdown Complete *******\n') return True def run_wizard(self, *args):