Bug 141781

Summary: ChildProcess should take an os_activity
Product: WebKit Reporter: Gavin Barraclough <barraclough>
Component: WebKit2Assignee: Gavin Barraclough <barraclough>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, barraclough, cdumez, commit-queue, ddkilzer, mjs, rniwa, sam
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Fix
none
Cleanup; Fixed the build
none
Got rid of macro
none
Fixed Mavericks build
none
Patch
none
Patch rniwa: review+

Description Gavin Barraclough 2015-02-18 16:53:59 PST
This should make activity tracing work.
Comment 1 Gavin Barraclough 2015-02-18 16:58:26 PST
Created attachment 246860 [details]
Fix
Comment 2 Anders Carlsson 2015-02-18 17:14:34 PST
Comment on attachment 246860 [details]
Fix

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

> Source/WebKit2/NetworkProcess/mac/NetworkProcessMac.mm:64
> +    m_osActivity = os_activity_start("com.apple.WebKit.Networking", OS_ACTIVITY_FLAG_DEFAULT);

Why do you need to do this in initializeProcessName, as opposed to platformInitialize?
Comment 3 Ryosuke Niwa 2015-02-27 19:04:53 PST
Created attachment 247581 [details]
Cleanup; Fixed the build
Comment 4 Ryosuke Niwa 2015-02-27 19:50:31 PST
<rdar://problem/19818204>
Comment 5 Sam Weinig 2015-02-28 13:19:28 PST
Comment on attachment 247581 [details]
Cleanup; Fixed the build

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

> Source/WebKit2/Shared/ChildProcess.cpp:42
> +#if HAVE(OS_ACTIVITY)
> +    m_osActivity = OS_ACTIVITY_NULL;
> +#endif

Can we do this with an in header initializer?

> Source/WebKit2/Shared/ChildProcess.cpp:50
> +#if HAVE(OS_ACTIVITY)
> +    if (m_osActivity != OS_ACTIVITY_NULL)
> +        os_activity_end(m_osActivity);
> +#endif

When will this actually ever be called? I think all the ChildProcess instances are actually singletons.  Is it important for this to run?

> Source/WebKit2/Shared/ChildProcess.h:106
> +#if HAVE(OS_ACTIVITY)
> +    // We can't make this private because os_activity_start forces __builtin_constant_p on name.
> +    os_activity_t m_osActivity;
> +#define startOSActivity(name) { m_osActivity = os_activity_start(name, OS_ACTIVITY_FLAG_DEFAULT); };
> +#else
> +#define startOSActivity(name) { };
> +#endif

This seems a bit gross to me.  I have two ideas about how to make it a bit nicer:

1) Get rid of the macro. Just call os_activity_start(name, OS_ACTIVITY_FLAG_DEFAULT); directly with some #ifdefs in the few places where it needs to be called.
2) Move all this activity code to process entry points (see WebContentServiceInitializer.mm, DatabaseServiceInitializer.mm etc.) We might even be able to make use of the XPCServiceInitializer helper with some static const names.
Comment 6 Ryosuke Niwa 2015-02-28 13:28:07 PST
(In reply to comment #5)
> Comment on attachment 247581 [details]
> Cleanup; Fixed the build
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=247581&action=review
> 
> > Source/WebKit2/Shared/ChildProcess.cpp:42
> > +#if HAVE(OS_ACTIVITY)
> > +    m_osActivity = OS_ACTIVITY_NULL;
> > +#endif
> 
> Can we do this with an in header initializer?

If we did that, we need to either move the member variable to somewhere below the first private member variable is defined or if-def-else the initialization list because the first initializations needs to be prefixed with ':' and not ','. i.e.

ChildProcess::ChildProcess()
#if HAVE(OS_ACTIVITY)
    : m_osActivity(OS_ACTIVITY_NULL)
    , m_terminationTimeout(0)
#else
    : m_terminationTimeout(0)
#endif

> > Source/WebKit2/Shared/ChildProcess.cpp:50
> > +#if HAVE(OS_ACTIVITY)
> > +    if (m_osActivity != OS_ACTIVITY_NULL)
> > +        os_activity_end(m_osActivity);
> > +#endif
> 
> When will this actually ever be called? I think all the ChildProcess
> instances are actually singletons.  Is it important for this to run?

We need to run this code when the child process terminates.

> > Source/WebKit2/Shared/ChildProcess.h:106
> > +#if HAVE(OS_ACTIVITY)
> > +    // We can't make this private because os_activity_start forces __builtin_constant_p on name.
> > +    os_activity_t m_osActivity;
> > +#define startOSActivity(name) { m_osActivity = os_activity_start(name, OS_ACTIVITY_FLAG_DEFAULT); };
> > +#else
> > +#define startOSActivity(name) { };
> > +#endif
> 
> This seems a bit gross to me.  I have two ideas about how to make it a bit
> nicer:
> 
> 1) Get rid of the macro. Just call os_activity_start(name,
> OS_ACTIVITY_FLAG_DEFAULT); directly with some #ifdefs in the few places
> where it needs to be called.

That's what Gavin's original patch did. I didn't want to repeat OS_ACTIVITY_FLAG_DEFAULT everywhere but perhaps that's less gross...

> 2) Move all this activity code to process entry points (see
> WebContentServiceInitializer.mm, DatabaseServiceInitializer.mm etc.) We
> might even be able to make use of the XPCServiceInitializer helper with some
> static const names.

I don't think that'll work because of __builtin_constant_p. Basically, os_activity_start needs to be "called" with a string literal.
Comment 7 Ryosuke Niwa 2015-02-28 13:35:52 PST
I guess I should be calling os_activity_end inside ChildProcess::terminate instead?
Comment 8 Sam Weinig 2015-02-28 17:21:42 PST
(In reply to comment #6)
> (In reply to comment #5)
> > Comment on attachment 247581 [details]
> > Cleanup; Fixed the build
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=247581&action=review
> > 
> > > Source/WebKit2/Shared/ChildProcess.cpp:42
> > > +#if HAVE(OS_ACTIVITY)
> > > +    m_osActivity = OS_ACTIVITY_NULL;
> > > +#endif
> > 
> > Can we do this with an in header initializer?
> 
> If we did that, we need to either move the member variable to somewhere
> below the first private member variable is defined or if-def-else the
> initialization list because the first initializations needs to be prefixed
> with ':' and not ','. i.e.
> 
> ChildProcess::ChildProcess()
> #if HAVE(OS_ACTIVITY)
>     : m_osActivity(OS_ACTIVITY_NULL)
>     , m_terminationTimeout(0)
> #else
>     : m_terminationTimeout(0)
> #endif
> 
> > > Source/WebKit2/Shared/ChildProcess.cpp:50
> > > +#if HAVE(OS_ACTIVITY)
> > > +    if (m_osActivity != OS_ACTIVITY_NULL)
> > > +        os_activity_end(m_osActivity);
> > > +#endif
> > 
> > When will this actually ever be called? I think all the ChildProcess
> > instances are actually singletons.  Is it important for this to run?
> 
> We need to run this code when the child process terminates.

Why? What does it do? What happens if we don't?

> 
> > > Source/WebKit2/Shared/ChildProcess.h:106
> > > +#if HAVE(OS_ACTIVITY)
> > > +    // We can't make this private because os_activity_start forces __builtin_constant_p on name.
> > > +    os_activity_t m_osActivity;
> > > +#define startOSActivity(name) { m_osActivity = os_activity_start(name, OS_ACTIVITY_FLAG_DEFAULT); };
> > > +#else
> > > +#define startOSActivity(name) { };
> > > +#endif
> > 
> > This seems a bit gross to me.  I have two ideas about how to make it a bit
> > nicer:
> > 
> > 1) Get rid of the macro. Just call os_activity_start(name,
> > OS_ACTIVITY_FLAG_DEFAULT); directly with some #ifdefs in the few places
> > where it needs to be called.
> 
> That's what Gavin's original patch did. I didn't want to repeat
> OS_ACTIVITY_FLAG_DEFAULT everywhere but perhaps that's less gross...

I think it is quite a bit less gross than a public member.

> 
> > 2) Move all this activity code to process entry points (see
> > WebContentServiceInitializer.mm, DatabaseServiceInitializer.mm etc.) We
> > might even be able to make use of the XPCServiceInitializer helper with some
> > static const names.
> 
> I don't think that'll work because of __builtin_constant_p. Basically,
> os_activity_start needs to be "called" with a string literal.

Well, with the magic of templates, you should be able to provide a real compile time literal.
Comment 9 Ryosuke Niwa 2015-02-28 17:52:32 PST
(In reply to comment #8)
> (In reply to comment #6)
> > (In reply to comment #5)
> > > Comment on attachment 247581 [details]
> > > Cleanup; Fixed the build
> > > 2) Move all this activity code to process entry points (see
> > > WebContentServiceInitializer.mm, DatabaseServiceInitializer.mm etc.) We
> > > might even be able to make use of the XPCServiceInitializer helper with some
> > > static const names.
> > 
> > I don't think that'll work because of __builtin_constant_p. Basically,
> > os_activity_start needs to be "called" with a string literal.
> 
> Well, with the magic of templates, you should be able to provide a real
> compile time literal.

No. It needs to be a string literal at the pre-processor time because os_activity_start is a macro, not a function.
Comment 10 Ryosuke Niwa 2015-02-28 18:00:11 PST
(In reply to comment #8)
> (In reply to comment #6)
> > (In reply to comment #5)
> > > Comment on attachment 247581 [details]
> > > Cleanup; Fixed the build
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=247581&action=review
> > > 
> > > > Source/WebKit2/Shared/ChildProcess.cpp:42
> > > > +#if HAVE(OS_ACTIVITY)
> > > > +    m_osActivity = OS_ACTIVITY_NULL;
> > > > +#endif
> > > 
> > > Can we do this with an in header initializer?
> > 
> > If we did that, we need to either move the member variable to somewhere
> > below the first private member variable is defined or if-def-else the
> > initialization list because the first initializations needs to be prefixed
> > with ':' and not ','. i.e.
> > 
> > ChildProcess::ChildProcess()
> > #if HAVE(OS_ACTIVITY)
> >     : m_osActivity(OS_ACTIVITY_NULL)
> >     , m_terminationTimeout(0)
> > #else
> >     : m_terminationTimeout(0)
> > #endif
> > 
> > > > Source/WebKit2/Shared/ChildProcess.cpp:50
> > > > +#if HAVE(OS_ACTIVITY)
> > > > +    if (m_osActivity != OS_ACTIVITY_NULL)
> > > > +        os_activity_end(m_osActivity);
> > > > +#endif
> > > 
> > > When will this actually ever be called? I think all the ChildProcess
> > > instances are actually singletons.  Is it important for this to run?
> > 
> > We need to run this code when the child process terminates.
> 
> Why? What does it do? What happens if we don't?

I don't know.
Comment 11 Ryosuke Niwa 2015-03-02 12:58:20 PST
Created attachment 247695 [details]
Got rid of macro
Comment 12 David Kilzer (:ddkilzer) 2015-03-02 15:43:04 PST
Comment on attachment 247695 [details]
Got rid of macro

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

> Source/WebKit2/DatabaseProcess/ios/DatabaseProcessIOS.mm:46
> +    m_osActivity = os_activity_start("com.apple.WebKit.Databases", OS_ACTIVITY_FLAG_DEFAULT);

Need #if HAVE(OS_ACTIVITY)/#endif around this line in each file.
Comment 13 Ryosuke Niwa 2015-03-02 15:47:38 PST
Created attachment 247707 [details]
Fixed Mavericks build
Comment 14 Sam Weinig 2015-05-04 17:50:18 PDT
Comment on attachment 247707 [details]
Fixed Mavericks build

Given that these never really need to be destroyed, I think putting them WebContentServiceInitializer (WebContentServiceEntryPoint.mm) and related places is the right way to go.  That will keep it in platform specific code and not litter the cross platform FooProcess classes.
Comment 15 David Kilzer (:ddkilzer) 2015-05-11 10:38:27 PDT
Comment on attachment 247707 [details]
Fixed Mavericks build

r- per Sam's Comment #14.
Comment 16 Sam Weinig 2015-05-11 18:23:13 PDT
Created attachment 252916 [details]
Patch
Comment 17 Sam Weinig 2015-05-11 19:06:32 PDT
Created attachment 252922 [details]
Patch
Comment 18 Ryosuke Niwa 2015-05-11 19:08:22 PDT
Comment on attachment 252922 [details]
Patch

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

> Source/WebKit2/DatabaseProcess/EntryPoint/mac/XPCService/DatabaseServiceEntryPoint.mm:51
> +#if HAVE(OS_ACTIVITY)
> +    os_activity_end(activity);
> +#endif

I guess this code never runs?
Comment 19 Sam Weinig 2015-05-12 09:27:03 PDT
Committed revision 184203.
Comment 20 Sam Weinig 2015-05-12 09:27:29 PDT
(In reply to comment #18)
> Comment on attachment 252922 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=252922&action=review
> 
> > Source/WebKit2/DatabaseProcess/EntryPoint/mac/XPCService/DatabaseServiceEntryPoint.mm:51
> > +#if HAVE(OS_ACTIVITY)
> > +    os_activity_end(activity);
> > +#endif
> 
> I guess this code never runs?

In most cases no, but it makes the compiler happy :).