Bug 128941 - Make it possible to start and stop the bytecode sampler.
Summary: Make it possible to start and stop the bytecode sampler.
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Oliver Hunt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-17 16:30 PST by Oliver Hunt
Modified: 2014-02-18 11:08 PST (History)
0 users

See Also:


Attachments
Patch (8.13 KB, patch)
2014-02-17 16:40 PST, Oliver Hunt
no flags Details | Formatted Diff | Diff
Patch (7.27 KB, patch)
2014-02-18 10:58 PST, Oliver Hunt
oliver: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Hunt 2014-02-17 16:30:46 PST
Make it possible to start and stop the bytecode sampler.
Comment 1 Oliver Hunt 2014-02-17 16:40:18 PST
Created attachment 224445 [details]
Patch
Comment 2 Filip Pizlo 2014-02-17 16:55:14 PST
Comment on attachment 224445 [details]
Patch

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

> Source/JavaScriptCore/ChangeLog:9
> +        Refactor the bytecode sampler logic to allow us to start and stop
> +        profiling sessions dynamically.

What is this for?

> Source/JavaScriptCore/runtime/VM.cpp:419
> +void VM::initializeBytecodeProfiler()
> +{
> +    ASSERT(m_bytecodeProfilerEnabled);
> +    if (m_perBytecodeProfiler)
> +        return;
> +    
> +    m_perBytecodeProfiler = adoptPtr(new Profiler::Database(*this));
> +}
> +
> +void VM::startBytecodeProfiler()
> +{
> +    if (m_bytecodeProfilerEnabled)
> +        return;
> +    m_bytecodeProfilerEnabled = true;
> +    if (entryScope)
> +        entryScope->setRecompilationNeeded(true);
> +    else
> +        initializeBytecodeProfiler();
> +    
> +}

Why are starting and initializing two different things?

> Source/JavaScriptCore/runtime/VM.cpp:438
> +String VM::stopBytecodeProfiler()
> +{
> +    m_bytecodeProfilerEnabled = false;
> +    if (!m_perBytecodeProfiler)
> +        return String();
> +    String result = m_perBytecodeProfiler->toJSON();
> +    if (entryScope)
> +        entryScope->setRecompilationNeeded(true);
> +    else
> +        destroyBytecodeProfiler();
> +    return result;
> +}

I really don't like this API.  I think it's weird that stopping the profiler, and getting its JSON, are part of the same thing.  Why can't you have two separate APIs?

> Source/JavaScriptCore/runtime/VM.h:516
> +        void prepareProfilerIfNecessary()
> +        {
> +            if (m_perBytecodeProfiler && !m_bytecodeProfilerEnabled)
> +                destroyBytecodeProfiler();
> +            else if (m_bytecodeProfilerEnabled && !m_perBytecodeProfiler)
> +                initializeBytecodeProfiler();
> +        }

This is really weird.  A method called "prapare" that destroys the profiler, or initializes it?  I don't understand this method.
Comment 3 Oliver Hunt 2014-02-17 17:12:52 PST
(In reply to comment #2)
> (From update of attachment 224445 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=224445&action=review
> 
> > Source/JavaScriptCore/ChangeLog:9
> > +        Refactor the bytecode sampler logic to allow us to start and stop
> > +        profiling sessions dynamically.
> 
> What is this for?

So we'll be able to profile pages in browser

> 
> > Source/JavaScriptCore/runtime/VM.cpp:419
> > +void VM::initializeBytecodeProfiler()
> > +{
> > +    ASSERT(m_bytecodeProfilerEnabled);
> > +    if (m_perBytecodeProfiler)
> > +        return;
> > +    
> > +    m_perBytecodeProfiler = adoptPtr(new Profiler::Database(*this));
> > +}
> > +
> > +void VM::startBytecodeProfiler()
> > +{
> > +    if (m_bytecodeProfilerEnabled)
> > +        return;
> > +    m_bytecodeProfilerEnabled = true;
> > +    if (entryScope)
> > +        entryScope->setRecompilationNeeded(true);
> > +    else
> > +        initializeBytecodeProfiler();
> > +    
> > +}
> 
> Why are starting and initializing two different things?

So you can start the profiler from inside JS, i guess that's not strictly necessary but it was useful for testing.

> 
> > Source/JavaScriptCore/runtime/VM.cpp:438
> > +String VM::stopBytecodeProfiler()
> > +{
> > +    m_bytecodeProfilerEnabled = false;
> > +    if (!m_perBytecodeProfiler)
> > +        return String();
> > +    String result = m_perBytecodeProfiler->toJSON();
> > +    if (entryScope)
> > +        entryScope->setRecompilationNeeded(true);
> > +    else
> > +        destroyBytecodeProfiler();
> > +    return result;
> > +}
> 
> I really don't like this API.  I think it's weird that stopping the profiler, and getting its JSON, are part of the same thing.  Why can't you have two separate APIs?

If we don't have the ability to start/stop from js this ins't necessary

> 
> > Source/JavaScriptCore/runtime/VM.h:516
> > +        void prepareProfilerIfNecessary()
> > +        {
> > +            if (m_perBytecodeProfiler && !m_bytecodeProfilerEnabled)
> > +                destroyBytecodeProfiler();
> > +            else if (m_bytecodeProfilerEnabled && !m_perBytecodeProfiler)
> > +                initializeBytecodeProfiler();
> > +        }
> 
> This is really weird.  A method called "prapare" that destroys the profiler, or initializes it?  I don't understand this method.
Comment 4 Oliver Hunt 2014-02-18 10:58:07 PST
Created attachment 224522 [details]
Patch