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

qbs session uses CPU #1

Open
arBmind opened this issue Aug 9, 2020 · 0 comments
Open

qbs session uses CPU #1

arBmind opened this issue Aug 9, 2020 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@arBmind
Copy link
Member

arBmind commented Aug 9, 2020

Observation:

  • QtCreator spawns multiple qbs session processes
  • On Windows each qbs session process consumes a .1-.3 % of my CPU when idle. With 4 processes this doubles the idle usage of my laptop and is a huge waste of battery.

Goals:

  • Do not drain my battery / consume idle power
  • Reduce extra processes and communication overhead

Analysis:

  • qbs session communicates over stdin and stdout with host process (QtCreator)
  • uses a QTimer to check if data was sent every 10ms
  • A qbs session process is spawned for each project configuration (Up to 4 per project - I guess debug/release and 2nd config)
  • clangbackend is not measurable on idle.
    • uses seperate named pipe (non blocking socket)
    • stdio is forwarded to qtcreator (not used for communication)
    • custom QDataStream based encoding (only useful for Qt environments)
  • clangd used by VsCode is not measurable on idle.
    • simple use of blocking stdin
    • mitigates debugger interrupts (see clang-tools-extra/clangd/JSONTransport.cpp)
    • seems to spawn threads for actual work

Experiments on qbs:

  • Even waiting for 90ms effectively brick qbs.
  • Using singleShot timer might help for sleeping. But does not stop idle drain.

Perfect solution:

  • Write a dedicated qbsd
  • use approach from clangd with blocking stdin reading
  • spawn/communicate with thread per session
  • hope: qbscore was doing something similar when it was part of qtcreator?
  • possible challenges:
    • protocol needs to be extended by something like a sessionId, start and end of sessions.
    • qtcreator needs to hold a common instance and despawn qbsd when not needed

Hacking solution:

  • Use worker thread in qbs to read stdin blockingly
  • Abort thread by closing stdin
  • Process received data with signals

Alternatives:

  • Use CompletionIO for Windows
    • Would require adding completion IO support to Qt main loop (might not be actually hard, but requires very careful design)
@arBmind arBmind added enhancement New feature or request help wanted Extra attention is needed labels Nov 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant