Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for stats #2248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions README_MONITORING.md
Original file line number Diff line number Diff line change
@@ -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!
11 changes: 5 additions & 6 deletions src/calibre/gui2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines -1683 to +1687
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This in particular is just changing

if not X:
    return
Y

to

if X:
    Y

and I call either spam or noise.



def local_path_for_resource(qurl: QUrl, base_qurl: 'QUrl | None' = None) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/calibre/gui2/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/calibre/gui2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:])
Expand All @@ -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)

Expand Down Expand Up @@ -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'),
Expand All @@ -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

Expand All @@ -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:
Expand Down
15 changes: 12 additions & 3 deletions src/calibre/gui2/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand All @@ -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()
Expand Down Expand Up @@ -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():
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down