mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-07-20 19:04:35 +02:00
i3-companion: reduce CPU usage by avoiding f-string for logger.debug
This commit is contained in:
parent
bf08c327a3
commit
4d76aedb61
1 changed files with 24 additions and 15 deletions
|
@ -144,7 +144,7 @@ def retry(max_retries):
|
||||||
retries = max_retries
|
retries = max_retries
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
logger.debug(f"execute {fn} (remaining tries: {retries})")
|
logger.debug("execute %s (remaining tries: %s)", fn, retries)
|
||||||
return await fn(*args, **kwargs)
|
return await fn(*args, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if retries > 0:
|
if retries > 0:
|
||||||
|
@ -177,7 +177,7 @@ def debounce(sleep, *, unless=None):
|
||||||
await asyncio.wait_for(
|
await asyncio.wait_for(
|
||||||
workers[fn].urgent.wait(), timeout=sleep
|
workers[fn].urgent.wait(), timeout=sleep
|
||||||
)
|
)
|
||||||
logger.debug(f"urgent work received for {fn}")
|
logger.debug("urgent work received for %s", fn)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
pass
|
pass
|
||||||
args, kwargs = workers[fn].queue
|
args, kwargs = workers[fn].queue
|
||||||
|
@ -185,11 +185,11 @@ def debounce(sleep, *, unless=None):
|
||||||
workers[fn].urgent.clear()
|
workers[fn].urgent.clear()
|
||||||
|
|
||||||
# Execute the work
|
# Execute the work
|
||||||
logger.debug(f"execute work for {fn}")
|
logger.debug("execute work for %s", fn)
|
||||||
try:
|
try:
|
||||||
await fn(*args, **kwargs)
|
await fn(*args, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"while running {fn}, worker got %s", e)
|
logger.debug("while running %s, worker got %s", fn, e)
|
||||||
workers[fn] = None
|
workers[fn] = None
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -198,21 +198,21 @@ def debounce(sleep, *, unless=None):
|
||||||
break
|
break
|
||||||
|
|
||||||
# No more work
|
# No more work
|
||||||
logger.debug(f"no more work for {fn}")
|
logger.debug("no more work for %s", fn)
|
||||||
workers[fn] = None
|
workers[fn] = None
|
||||||
|
|
||||||
@functools.wraps(fn)
|
@functools.wraps(fn)
|
||||||
async def wrapper(*args, **kwargs):
|
async def wrapper(*args, **kwargs):
|
||||||
if workers[fn] is None:
|
if workers[fn] is None:
|
||||||
logger.debug(f"create new worker for {fn}")
|
logger.debug("create new worker for %s", fn)
|
||||||
workers[fn] = types.SimpleNamespace()
|
workers[fn] = types.SimpleNamespace()
|
||||||
workers[fn].task = asyncio.create_task(worker())
|
workers[fn].task = asyncio.create_task(worker())
|
||||||
workers[fn].urgent = asyncio.Event()
|
workers[fn].urgent = asyncio.Event()
|
||||||
workers[fn].queue = (args, kwargs)
|
workers[fn].queue = (args, kwargs)
|
||||||
else:
|
else:
|
||||||
logger.debug(f"enqueue new work for {fn}")
|
logger.debug("enqueue new work for %s", fn)
|
||||||
if unless is not None and unless(*args, **kwargs):
|
if unless is not None and unless(*args, **kwargs):
|
||||||
logger.debug(f"wake up now for {fn}")
|
logger.debug("wake up now for %s", fn)
|
||||||
workers[fn].urgent.set()
|
workers[fn].urgent.set()
|
||||||
return await workers[fn].task
|
return await workers[fn].task
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ async def workspace_rename(i3, event):
|
||||||
continue
|
continue
|
||||||
for k, v in application_icons.items():
|
for k, v in application_icons.items():
|
||||||
if re.match(rf"^{k}\b", name, re.IGNORECASE):
|
if re.match(rf"^{k}\b", name, re.IGNORECASE):
|
||||||
logger.debug(f"in {attr}, found '{name}', matching {k}")
|
logger.debug("in %s, found '%s', matching %s", attr, name, k)
|
||||||
return v
|
return v
|
||||||
return application_icons_nomatch
|
return application_icons_nomatch
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ async def workspace_rename(i3, event):
|
||||||
icons -= application_icons_alone
|
icons -= application_icons_alone
|
||||||
new_name = f"{workspace.num}:{'|'.join(icons)}".rstrip(":")
|
new_name = f"{workspace.num}:{'|'.join(icons)}".rstrip(":")
|
||||||
if workspace.name != new_name:
|
if workspace.name != new_name:
|
||||||
logger.debug(f"rename workspace {workspace.num}")
|
logger.debug("rename workspace %s", workspace.num)
|
||||||
command = f'rename workspace "{workspace.name}" to "{new_name}"'
|
command = f'rename workspace "{workspace.name}" to "{new_name}"'
|
||||||
commands.append(command)
|
commands.append(command)
|
||||||
await i3.command(";".join(commands))
|
await i3.command(";".join(commands))
|
||||||
|
@ -356,7 +356,7 @@ async def worksplace_exclusive(i3, event):
|
||||||
|
|
||||||
# Can the new window just intrude?
|
# Can the new window just intrude?
|
||||||
if can_intrude(w):
|
if can_intrude(w):
|
||||||
logger.debug(f"window {w.name} can intrude")
|
logger.debug("window %s can intrude", w.name)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get the workspace. From an event, w.workspace() is None, so
|
# Get the workspace. From an event, w.workspace() is None, so
|
||||||
|
@ -377,7 +377,7 @@ async def worksplace_exclusive(i3, event):
|
||||||
}
|
}
|
||||||
exclusives = ids.intersection(exclusive_apps)
|
exclusives = ids.intersection(exclusive_apps)
|
||||||
if not exclusives:
|
if not exclusives:
|
||||||
logger.debug("no exclusive app, {w.name} can go there")
|
logger.debug("no exclusive app, %s can go there", w.name)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Create a new workspace and move the window here
|
# Create a new workspace and move the window here
|
||||||
|
@ -426,7 +426,7 @@ async def quake_console(i3, event):
|
||||||
"scratchpad show,"
|
"scratchpad show,"
|
||||||
f"move absolute position {posx}px {posy}px"
|
f"move absolute position {posx}px {posy}px"
|
||||||
)
|
)
|
||||||
logger.debug(f"QuakeConsole: {command}")
|
logger.debug("QuakeConsole: %s", command)
|
||||||
await i3.command(command)
|
await i3.command(command)
|
||||||
|
|
||||||
|
|
||||||
|
@ -761,7 +761,7 @@ async def dunst_status_check(i3, event):
|
||||||
async def network_manager_notifications(i3, event, path, state, reason):
|
async def network_manager_notifications(i3, event, path, state, reason):
|
||||||
"""Display notifications related to Network Manager state."""
|
"""Display notifications related to Network Manager state."""
|
||||||
ofnm = "org.freedesktop.NetworkManager"
|
ofnm = "org.freedesktop.NetworkManager"
|
||||||
logger.debug(f"from {path} state: {state}, reason: {reason}")
|
logger.debug("from %s state: %s, reason: %s", path, state, reason)
|
||||||
if state not in {NM_ACTIVE_CONNECTION_STATE_ACTIVATED}:
|
if state not in {NM_ACTIVE_CONNECTION_STATE_ACTIVATED}:
|
||||||
# Deactivated state does not contain enough information,
|
# Deactivated state does not contain enough information,
|
||||||
# unless we maintain state.
|
# unless we maintain state.
|
||||||
|
@ -899,7 +899,12 @@ async def main(options):
|
||||||
for fn, events in on.functions.items():
|
for fn, events in on.functions.items():
|
||||||
for event in events:
|
for event in events:
|
||||||
if isinstance(event, I3Event):
|
if isinstance(event, I3Event):
|
||||||
i3.on(event, fn)
|
def wrapping(fn, event):
|
||||||
|
async def wrapped(i3, event):
|
||||||
|
logger.debug("received i3 event %s for %s", event, fn)
|
||||||
|
return await fn(i3, event)
|
||||||
|
return wrapped
|
||||||
|
i3.on(event, wrapping(fn, event))
|
||||||
|
|
||||||
# React to some bindings
|
# React to some bindings
|
||||||
async def binding_event(i3, event):
|
async def binding_event(i3, event):
|
||||||
|
@ -918,6 +923,7 @@ async def main(options):
|
||||||
for fn, events in on.functions.items():
|
for fn, events in on.functions.items():
|
||||||
for e in events:
|
for e in events:
|
||||||
if isinstance(e, CommandEvent) and e.name == kind:
|
if isinstance(e, CommandEvent) and e.name == kind:
|
||||||
|
logger.debug("received command event %s for %s", event, fn)
|
||||||
await fn(i3, cmd)
|
await fn(i3, cmd)
|
||||||
|
|
||||||
i3.on(I3Event.BINDING, binding_event)
|
i3.on(I3Event.BINDING, binding_event)
|
||||||
|
@ -937,7 +943,10 @@ async def main(options):
|
||||||
)
|
)
|
||||||
async def wrapped(path, args):
|
async def wrapped(path, args):
|
||||||
if event.onlyif is not None and not event.onlyif(args):
|
if event.onlyif is not None and not event.onlyif(args):
|
||||||
|
logger.debug("received DBus event for %s but not interested",
|
||||||
|
fn)
|
||||||
return
|
return
|
||||||
|
logger.debug("received DBus event %s for %s", event, fn)
|
||||||
return await fn(i3, event, path, *args)
|
return await fn(i3, event, path, *args)
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue