Bug 87672

Summary: [Qt] Add quirks for running the web process in a profiler shell, like valgrind
Product: WebKit Reporter: Balazs Kelemen <kbalazs>
Component: WebKit2Assignee: Balazs Kelemen <kbalazs>
Status: RESOLVED FIXED    
Severity: Normal CC: cmarcelo, jturcotte, menard, vestbo, webkit.review.bot, zherczeg, zoltan
Priority: P3 Keywords: Qt, QtTriaged
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Balazs Kelemen 2012-05-28 09:56:41 PDT
The only reliable way to run the web process in valgrind is to change ProcessLauncherQt.cpp.
I think it's worth to add an env var quirk for this.
Comment 1 Balazs Kelemen 2012-05-28 10:18:32 PDT
Created attachment 144381 [details]
Patch
Comment 2 Caio Marcelo de Oliveira Filho 2012-05-29 01:25:50 PDT
Comment on attachment 144381 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=144381&action=review

Cool! :-)  I have some comments. I wish these debugging features / environment variables were more discoverable, maybe we could add a --help to our main.cpp to describe them?

> Source/WebKit2/ChangeLog:9
> +        Consider the enironment variables QT_WEB_PROCESS_COMMAND_PREFIX
> +        and QT_PLUGIN_PROCESS_COMMAND_PREFIX. If set use their values as

Typo "environment". I think it would be clearer to just say: "If environment variables QT_WEB_... and QT_PLUGIN_... are set, use their values...".

Also other environment variables use QT_WEBKIT_ prefix, maybe we should follow the same here.

> Tools/ChangeLog:8
> +        Add a dedicated environment variable quirk (QT_WTR_NO_TIMEOUT)

Why existing --no-timeout option is not enough?
Comment 3 Balazs Kelemen 2012-05-29 04:55:17 PDT
Created attachment 144525 [details]
Patch
Comment 4 Balazs Kelemen 2012-05-29 04:58:00 PDT
(In reply to comment #2)
> (From update of attachment 144381 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=144381&action=review
> 
> Cool! :-)  I have some comments. I wish these debugging features / environment variables were more discoverable, maybe we could add a --help to our main.cpp to describe them?

I don't think it belongs to either MiniBrowser or WebKitTestRunner. I will update the wiki with these ;)

> 
> > Source/WebKit2/ChangeLog:9
> > +        Consider the enironment variables QT_WEB_PROCESS_COMMAND_PREFIX
> > +        and QT_PLUGIN_PROCESS_COMMAND_PREFIX. If set use their values as
> 
> Typo "environment". I think it would be clearer to just say: "If environment variables QT_WEB_... and QT_PLUGIN_... are set, use their values...".
> 
> Also other environment variables use QT_WEBKIT_ prefix, maybe we should follow the same here.

Fixed both.

> 
> > Tools/ChangeLog:8
> > +        Add a dedicated environment variable quirk (QT_WTR_NO_TIMEOUT)
> 
> Why existing --no-timeout option is not enough?

Good point, I removed that.
Comment 5 Balazs Kelemen 2012-05-29 06:26:22 PDT
> 
> > 
> > > Tools/ChangeLog:8
> > > +        Add a dedicated environment variable quirk (QT_WTR_NO_TIMEOUT)
> > 
> > Why existing --no-timeout option is not enough?
> 
> Good point, I removed that.

Hm, actually it is not enough, because it only disables the watchdog timer, not the runloop timer. But it's another bug.
Comment 6 Simon Hausmann 2012-06-01 23:43:09 PDT
Comment on attachment 144525 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=144525&action=review

I think this is a very good idea (r+). But please fix the string handling before landing. Just call qgetenv() every time and remember to use constData() if you can.

In this case I would even argue that the use of arg() is overkill, this is merely about concatenating a bunch of strings, so perhaps it would make sense to use the string builder in Qt with the % operator:

http://doc-snapshot.qt-project.org/5.0/qstring.html#more-efficient-string-construction

> Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp:105
> +    static QByteArray webProcessPrefix = qgetenv("QT_WEBKIT_WEB_PROCESS_COMMAND_PREFIX");
> +    static QByteArray pluginProcessPrefix = qgetenv("QT_WEBKIT_PLUGIN_PROCESS_COMMAND_PREFIX");

I wouldn't simply bother with making those global variables. The strings are already global in the environment and we don't launch processes often enough to IMHO justify the time we "save" by not extracting the strings again out of the environment. At the same time the _copy_ of the string uses memory for no reason :)

> Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp:118
> +    QString commandLine = prefix.isEmpty() ? QStringLiteral("%1 %2") : QString(QStringLiteral("%1 %2 %3")).arg(QLatin1String(prefix.data()));

By calling data() instead of constData() you'll end up creating a copy of the QByteArray for no reason. The non-const data() calls detach() and will detach because the refcount will be 2 (the original prefix variable holds one ref, the local prefix variable another one).
Comment 7 Balazs Kelemen 2012-06-02 07:02:50 PDT
(In reply to comment #5)
> > 
> > > 
> > > > Tools/ChangeLog:8
> > > > +        Add a dedicated environment variable quirk (QT_WTR_NO_TIMEOUT)
> > > 
> > > Why existing --no-timeout option is not enough?
> > 
> > Good point, I removed that.
> 
> Hm, actually it is not enough, because it only disables the watchdog timer, not the runloop timer. But it's another bug.

No, I misread it. It should be enough.
Comment 8 Balazs Kelemen 2012-06-02 10:17:17 PDT
(In reply to comment #6)
> (From update of attachment 144525 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=144525&action=review
> 
> I think this is a very good idea (r+). But please fix the string handling before landing. Just call qgetenv() every time and remember to use constData() if you can.
> 
> In this case I would even argue that the use of arg() is overkill, this is merely about concatenating a bunch of strings, so perhaps it would make sense to use the string builder in Qt with the % operator:

Thanks for the detailed review. It's enough for another round, so I'm going to upload a new patch.
Comment 9 Balazs Kelemen 2012-06-02 10:20:11 PDT
Created attachment 145449 [details]
Patch
Comment 10 Tor Arne Vestbø 2012-06-06 09:09:52 PDT
Comment on attachment 145449 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=145449&action=review

> Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp:110
> +        commandLine = commandLine % static_cast<QString>(executablePathOfWebProcess());

static_cast?

> Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp:115
> +        commandLine = commandLine % static_cast<QString>(executablePathOfPluginProcess());

??
Comment 11 Balazs Kelemen 2012-06-06 10:19:04 PDT
Created attachment 146057 [details]
Patch
Comment 12 Balazs Kelemen 2012-06-12 07:40:18 PDT
(In reply to comment #7)
> (In reply to comment #5)
> > > 
> > > > 
> > > > > Tools/ChangeLog:8
> > > > > +        Add a dedicated environment variable quirk (QT_WTR_NO_TIMEOUT)
> > > > 
> > > > Why existing --no-timeout option is not enough?
> > > 
> > > Good point, I removed that.
> > 
> > Hm, actually it is not enough, because it only disables the watchdog timer, not the runloop timer. But it's another bug.
> 
> No, I misread it. It should be enough.

D'oh, misread again. It's enough with QT_WEBKIT2_DEBUG but we don't want this with valgrind. I'm going to add a switch for the responsiveness timer.
Comment 13 Balazs Kelemen 2012-06-12 07:59:05 PDT
Created attachment 147087 [details]
Patch
Comment 14 Tor Arne Vestbø 2012-06-13 07:22:33 PDT
Comment on attachment 147087 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=147087&action=review

> Tools/WebKitTestRunner/TestController.cpp:569
> +    if (!m_useRensponsivityTimer) {
> +        platformRunUntil(done, m_noTimeout);
> +        return;
> +    }
> +

Why don't we just call runUntil() with NoTimeout ?
Comment 15 Balazs Kelemen 2012-06-13 07:56:27 PDT
Created attachment 147315 [details]
Patch
Comment 16 Jocelyn Turcotte 2012-07-11 07:09:14 PDT
Comment on attachment 147315 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=147315&action=review

> Source/WebKit2/ChangeLog:9
> +        and/or QT_WEBKIT_PLUGIN_PROCESS_COMMAND_PREFIX set, use their

*are* set,

> Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp:107
> +        QByteArray webProcessPrefix = qgetenv("QT_WEBKIT_WEB_PROCESS_COMMAND_PREFIX");

1. This is pretty long
2. It would be nice if this name would align with QT_WEBKIT2_DEBUG since their use cases are related.
So maybe we could name them QT_WEBKIT2_WP_CMD_PREFIX and QT_WEBKIT2_PP_CMD_PREFIX?

> Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp:110
> +        if (!webProcessPrefix.isEmpty())
> +            commandLine = QLatin1String(webProcessPrefix.constData()) % QLatin1Char(' ');
> +        commandLine = commandLine % QString(executablePathOfWebProcess());

This can be simplified to:
commandLine = QLatin1String(webProcessPrefix.constData()) % QLatin1Char(' ') % QString(executablePathOfWebProcess());

> Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp:153
> -    commandLine = commandLine.arg(sockets[0]);
> +    commandLine = commandLine % QLatin1Char(' ') % QString::number(sockets[0]);

You can leave that one as it is, arg() is perfect for this and reads better if you have to convert to numbers anyway.

> Tools/ChangeLog:11
> +        profiling purposes because it only effects the timeout

it only *affects*

> Tools/WebKitTestRunner/TestController.cpp:264
> +        if (argument == "--no-runloop-timeout") {

I'm wondering if it wouldn't be better to just also avoid the timer in TestControllerQt if m_useWaitToDumpWatchdogTimer is false. Please try it and if it works I would avoid adding an extra command line argument which might cause confusion. A lot of people that tried to run this into valgrind probably tried --no-timout because it sounds right from that point of view.
Comment 17 Jocelyn Turcotte 2012-07-11 08:41:41 PDT
Comment on attachment 147315 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=147315&action=review

>> Tools/WebKitTestRunner/TestController.cpp:264
>> +        if (argument == "--no-runloop-timeout") {
> 
> I'm wondering if it wouldn't be better to just also avoid the timer in TestControllerQt if m_useWaitToDumpWatchdogTimer is false. Please try it and if it works I would avoid adding an extra command line argument which might cause confusion. A lot of people that tried to run this into valgrind probably tried --no-timout because it sounds right from that point of view.

Ok talked on IRC and that would probably break performance tests, so let's add a switch and maybe rename it to something clearer to those not wanting to read the code.

> Tools/WebKitTestRunner/TestController.cpp:571
> +    if (!m_useRunloopTimer) {
> +        platformRunUntil(done, m_noTimeout);
> +        return;
> +    }
> +
>      double timeout;
>      switch (timeoutDuration) {

Try to avoid the duplicate call to platformRunUntil.
Something like:

double timeout = m_noTimeout;
if (m_useRunLoopTimer) {
    switch (timeoutDuration) {
    ....

> Tools/WebKitTestRunner/TestController.h:132
> +    bool m_useRunloopTimer;

Maybe rename this to m_forceNoTimeout.
Comment 18 Balazs Kelemen 2012-07-11 09:17:48 PDT
Created attachment 151715 [details]
Patch
Comment 19 Balazs Kelemen 2012-07-11 09:20:44 PDT
(In reply to comment #16)
> (From update of attachment 147315 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=147315&action=review
> 
> > Source/WebKit2/ChangeLog:9
> > +        and/or QT_WEBKIT_PLUGIN_PROCESS_COMMAND_PREFIX set, use their
> 
> *are* set,
> 
> > Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp:107
> > +        QByteArray webProcessPrefix = qgetenv("QT_WEBKIT_WEB_PROCESS_COMMAND_PREFIX");
> 
> 1. This is pretty long
> 2. It would be nice if this name would align with QT_WEBKIT2_DEBUG since their use cases are related.
> So maybe we could name them QT_WEBKIT2_WP_CMD_PREFIX and QT_WEBKIT2_PP_CMD_PREFIX?

Done, done.

> 
> > Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp:110
> > +        if (!webProcessPrefix.isEmpty())
> > +            commandLine = QLatin1String(webProcessPrefix.constData()) % QLatin1Char(' ');
> > +        commandLine = commandLine % QString(executablePathOfWebProcess());
> 
> This can be simplified to:
> commandLine = QLatin1String(webProcessPrefix.constData()) % QLatin1Char(' ') % QString(executablePathOfWebProcess());
> 
> > Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp:153
> > -    commandLine = commandLine.arg(sockets[0]);
> > +    commandLine = commandLine % QLatin1Char(' ') % QString::number(sockets[0]);
> 
> You can leave that one as it is, arg() is perfect for this and reads better if you have to convert to numbers anyway.

Simplified and changed back to use QString::arg as discussed on irc since it is more readable and it only runs once so we should not bother optmising it.
Comment 20 Balazs Kelemen 2012-07-11 09:21:10 PDT
(In reply to comment #17)
> (From update of attachment 147315 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=147315&action=review
> 
> >> Tools/WebKitTestRunner/TestController.cpp:264
> >> +        if (argument == "--no-runloop-timeout") {
> > 
> > I'm wondering if it wouldn't be better to just also avoid the timer in TestControllerQt if m_useWaitToDumpWatchdogTimer is false. Please try it and if it works I would avoid adding an extra command line argument which might cause confusion. A lot of people that tried to run this into valgrind probably tried --no-timout because it sounds right from that point of view.
> 
> Ok talked on IRC and that would probably break performance tests, so let's add a switch and maybe rename it to something clearer to those not wanting to read the code.
> 
> > Tools/WebKitTestRunner/TestController.cpp:571
> > +    if (!m_useRunloopTimer) {
> > +        platformRunUntil(done, m_noTimeout);
> > +        return;
> > +    }
> > +
> >      double timeout;
> >      switch (timeoutDuration) {
> 
> Try to avoid the duplicate call to platformRunUntil.
> Something like:
> 
> double timeout = m_noTimeout;
> if (m_useRunLoopTimer) {
>     switch (timeoutDuration) {
>     ....
> 
> > Tools/WebKitTestRunner/TestController.h:132
> > +    bool m_useRunloopTimer;
> 
> Maybe rename this to m_forceNoTimeout.

Done, done.
Comment 21 Jocelyn Turcotte 2012-07-13 05:24:03 PDT
Comment on attachment 151715 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=151715&action=review

> Tools/ChangeLog:12
> +        profiling purposes because it only affects the timeout
> +        for running the actual test and we should keep this

"for running the actual test" could read something like "when waiting for the end of a test" to be clearer.

> Tools/WebKitTestRunner/TestController.cpp:264
> +        if (argument == "--no-timeout-for-all") {

"No timeout for all" doesn't read so well with my limited english skills. Maybe --no-timeout-at-all or --no-timeout-ever or --no-timeout-for-debugging?

> Tools/WebKitTestRunner/TestController.cpp:265
> +            m_useWaitToDumpWatchdogTimer = false;

That line won't have any effect as far as I know, since both ShortTimeout and LongTimeout will be the same as NoTimeout with your changes to runUntil.
Comment 22 Balazs Kelemen 2012-07-13 08:55:09 PDT
Created attachment 152271 [details]
Patch
Comment 23 Balazs Kelemen 2012-07-13 09:02:06 PDT
Created attachment 152272 [details]
Patch

synced changelog
Comment 24 Balazs Kelemen 2012-07-13 09:02:43 PDT
(In reply to comment #21)
> (From update of attachment 151715 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=151715&action=review
> 
> > Tools/ChangeLog:12
> > +        profiling purposes because it only affects the timeout
> > +        for running the actual test and we should keep this
> 
> "for running the actual test" could read something like "when waiting for the end of a test" to be clearer.

Fixed, and expanded the explanation so hopefully it is more understandable now.

> 
> > Tools/WebKitTestRunner/TestController.cpp:264
> > +        if (argument == "--no-timeout-for-all") {
> 
> "No timeout for all" doesn't read so well with my limited english skills. Maybe --no-timeout-at-all or --no-timeout-ever or --no-timeout-for-debugging?

Fixed, I choose --no-timeout-at-all.

> 
> > Tools/WebKitTestRunner/TestController.cpp:265
> > +            m_useWaitToDumpWatchdogTimer = false;
> 
> That line won't have any effect as far as I know, since both ShortTimeout and LongTimeout will be the same as NoTimeout with your changes to runUntil.

It is also used by the injected bundle, it is passed to it in TestInvocation::invoke.
Comment 25 Jocelyn Turcotte 2012-07-24 06:08:56 PDT
Comment on attachment 152272 [details]
Patch

(In reply to comment #24)
> It is also used by the injected bundle, it is passed to it in TestInvocation::invoke.

Yep you're right, ok looks good!
Comment 26 Balazs Kelemen 2012-07-24 06:15:02 PDT
Comment on attachment 152272 [details]
Patch

Clearing flags on attachment: 152272

Committed r123464: <http://trac.webkit.org/changeset/123464>
Comment 27 Balazs Kelemen 2012-07-24 06:15:09 PDT
All reviewed patches have been landed.  Closing bug.