Skip to content

console message without new line is not showed. console message can affect simulation speed #2492

@Thomas-Feldmeier

Description

@Thomas-Feldmeier

if a robot does only
printf("hello world")
this is not printed in console (missing new line like \n or std::endl etc.)

if the robot print every timeStep and webots runs as fast as possible (e.g. FastMode), the console print will be the limiting factor for speed. (e.g. with basicTimeStep 16 and 5 robots who do not print: x200 speed. same with print every timeStep: x17 speed)

both issues can be easily handled by the user (adding a newline or printing less often), but they are unexpected and undocumented and may confuse a lot. (why is my debug message not printed? why is the simulation so slow after i only added some debug messages?)

Hint: WbConsole.cpp:
void WbConsole::handleCRAndLF(const QString &msg) {
...
if (!line.isEmpty()) {
if (mIsOverwriteEnabled) {
...
textCursor.insertHtml(line);
} else
mEditor->appendHtml(line);
mIsOverwriteEnabled = endsWithCR;

mEditor->appendHtml is a function in QPlainTextEdit in Qt

it is not called for lines with missing \n

in above scenario, 1 robot is as slow as 5 robots if all are printing
so all the prints wait for Qt to handle them (blocking call)

a new thread could speed up the simulation in FastMode
the main thread should never have to wait for this new thread but still synchronization has to be done

maybe like this: (pseudo-code)

int32 counterA, counterB // 32 bits, so read/write is atomic on an PC or most 32-bit computers

the main thread is increasing counterA only
the new thread is increasing counterB only

both are indices for an cyclic data array with sufficient size

main thread: if(++counterA % SIZE == counterB % SIZE) error SIZE should be higher or the new thread is not working fast enough
else data[counterA] = pointer to string to print

new thread:
print all data from counterB to counterA (cyclic)
counterB = counterA (freeing space in data)
wait for 16 milliseconds (60 fps)

this way the main thread is not slowed at all by synchronization and the new thread still updates the console fast enough

Metadata

Metadata

Labels

enhancementImplementation of a minor featurelow priorityNot yet a development priority

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions