Changeset 142618 in webkit


Ignore:
Timestamp:
Feb 12, 2013 6:53:34 AM (11 years ago)
Author:
loislo@chromium.org
Message:

Web Inspector: Native Memory Instrumentation: reportLeaf method doesn't report the leaf node properly.
https://bugs.webkit.org/show_bug.cgi?id=109554

Source/WebCore:

In some cases leaves have no pointer so with the old schema we can't generate nodeId for them because we
can't insert 0 into hashmap. It happens when we call addPrivateBuffer method.

Drive by fix: I introduced a client interface for the HeapGraphSerializer.
It helps me to do the tests for the serializer.

Reviewed by Yury Semikhatsky.

It is covered by newly added tests in TestWebKitAPI.

  • inspector/HeapGraphSerializer.cpp:

(WebCore::HeapGraphSerializer::HeapGraphSerializer):
(WebCore::HeapGraphSerializer::pushUpdate):
(WebCore::HeapGraphSerializer::reportNode):
(WebCore::HeapGraphSerializer::toNodeId):
(WebCore::HeapGraphSerializer::addRootNode):

  • inspector/HeapGraphSerializer.h:

(HeapGraphSerializerClient):
(WebCore::HeapGraphSerializerClient::~HeapGraphSerializerClient):
(HeapGraphSerializer):

  • inspector/InspectorMemoryAgent.cpp:

(WebCore::InspectorMemoryAgent::getProcessMemoryDistributionImpl):

Tools:

In some cases leaves have no pointer. As example when we report a leaf via addPrivateBuffer.
This patch has new set of tests for HeapGraphSerializer.

Reviewed by Yury Semikhatsky.

  • TestWebKitAPI/TestWebKitAPI.gypi:
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebCore/HeapGraphSerializerTest.cpp: Added.
  • TestWebKitAPI/win/TestWebKitAPI.vcproj:
Location:
trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r142614 r142618  
     12013-02-12  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: Native Memory Instrumentation: reportLeaf method doesn't report the leaf node properly.
     4        https://bugs.webkit.org/show_bug.cgi?id=109554
     5
     6        In some cases leaves have no pointer so with the old schema we can't generate nodeId for them because we
     7        can't insert 0 into hashmap. It happens when we call addPrivateBuffer method.
     8
     9        Drive by fix: I introduced a client interface for the HeapGraphSerializer.
     10        It helps me to do the tests for the serializer.
     11
     12        Reviewed by Yury Semikhatsky.
     13
     14        It is covered by newly added tests in TestWebKitAPI.
     15
     16        * inspector/HeapGraphSerializer.cpp:
     17        (WebCore::HeapGraphSerializer::HeapGraphSerializer):
     18        (WebCore::HeapGraphSerializer::pushUpdate):
     19        (WebCore::HeapGraphSerializer::reportNode):
     20        (WebCore::HeapGraphSerializer::toNodeId):
     21        (WebCore::HeapGraphSerializer::addRootNode):
     22        * inspector/HeapGraphSerializer.h:
     23        (HeapGraphSerializerClient):
     24        (WebCore::HeapGraphSerializerClient::~HeapGraphSerializerClient):
     25        (HeapGraphSerializer):
     26        * inspector/InspectorMemoryAgent.cpp:
     27        (WebCore::InspectorMemoryAgent::getProcessMemoryDistributionImpl):
     28
    1292013-02-12  Vsevolod Vlasov  <vsevik@chromium.org>
    230
  • trunk/Source/WebCore/inspector/HeapGraphSerializer.cpp

    r142241 r142618  
    4444namespace WebCore {
    4545
    46 HeapGraphSerializer::HeapGraphSerializer(InspectorFrontend::Memory* frontend)
    47     : m_frontend(frontend)
     46HeapGraphSerializer::HeapGraphSerializer(Client* client)
     47    : m_client(client)
    4848    , m_strings(Strings::create())
    4949    , m_edges(Edges::create())
     
    5151    , m_nodes(Nodes::create())
    5252    , m_baseToRealNodeIdMap(BaseToRealNodeIdMap::create())
    53 {
    54     ASSERT(m_frontend);
     53    , m_leafCount(0)
     54{
     55    ASSERT(m_client);
    5556    m_strings->addItem(String()); // An empty string with 0 index.
    5657
     
    9293        .setBaseToRealNodeId(m_baseToRealNodeIdMap.release());
    9394
    94     m_frontend->addNativeSnapshotChunk(chunk);
     95    m_client->addNativeSnapshotChunk(chunk.release());
    9596
    9697    m_strings = Strings::create();
     
    102103void HeapGraphSerializer::reportNode(const WTF::MemoryObjectInfo& info)
    103104{
     105    ASSERT(info.reportedPointer());
    104106    reportNodeImpl(info, m_nodeEdgesCount);
    105107    m_nodeEdgesCount = 0;
     
    183185int HeapGraphSerializer::toNodeId(const void* to)
    184186{
    185     ASSERT(to);
    186     Address2NodeId::AddResult result = m_address2NodeIdMap.add(to, m_address2NodeIdMap.size());
     187    if (!to)
     188        return s_firstNodeId + m_address2NodeIdMap.size() + m_leafCount++;
     189
     190    Address2NodeId::AddResult result = m_address2NodeIdMap.add(to, s_firstNodeId + m_leafCount + m_address2NodeIdMap.size());
    187191    return result.iterator->value;
    188192}
     
    195199    m_nodes->addItem(addString("Root"));
    196200    m_nodes->addItem(0);
    197     m_nodes->addItem(m_address2NodeIdMap.size());
     201    m_nodes->addItem(s_firstNodeId + m_address2NodeIdMap.size() + m_leafCount);
    198202    m_nodes->addItem(0);
    199203    m_nodes->addItem(m_roots.size());
  • trunk/Source/WebCore/inspector/HeapGraphSerializer.h

    r142074 r142618  
    4444namespace WebCore {
    4545
    46 class HeapGraphEdge;
    47 class HeapGraphNode;
    48 class InspectorObject;
    49 
    5046class HeapGraphSerializer {
    5147    WTF_MAKE_NONCOPYABLE(HeapGraphSerializer);
    5248public:
    53     explicit HeapGraphSerializer(InspectorFrontend::Memory*);
     49
     50    class Client {
     51    public:
     52        virtual ~Client() { }
     53        virtual void addNativeSnapshotChunk(PassRefPtr<TypeBuilder::Memory::HeapSnapshotChunk>) = 0;
     54    };
     55
     56    explicit HeapGraphSerializer(Client*);
    5457    ~HeapGraphSerializer();
    5558    void reportNode(const WTF::MemoryObjectInfo&);
     
    7477    int reportNodeImpl(const WTF::MemoryObjectInfo&, int edgesCount);
    7578
    76     InspectorFrontend::Memory* m_frontend;
     79    Client* m_client;
    7780
    7881    typedef HashMap<String, int> StringMap;
     
    101104    size_t m_edgeTypes[WTF::LastMemberTypeEntry];
    102105    int m_unknownClassNameId;
     106    int m_leafCount;
     107
     108    static const int s_firstNodeId = 1;
    103109};
    104110
  • trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp

    r142281 r142618  
    331331}
    332332
     333namespace {
     334
     335class FrontendWrapper : public HeapGraphSerializer::Client {
     336public:
     337    explicit FrontendWrapper(InspectorFrontend::Memory* frontend) : m_frontend(frontend) { }
     338    virtual void addNativeSnapshotChunk(PassRefPtr<TypeBuilder::Memory::HeapSnapshotChunk> heapSnapshotChunk) OVERRIDE
     339    {
     340        m_frontend->addNativeSnapshotChunk(heapSnapshotChunk);
     341    }
     342private:
     343    InspectorFrontend::Memory* m_frontend;
     344};
     345
     346}
     347
    333348void InspectorMemoryAgent::getProcessMemoryDistributionImpl(bool reportGraph, TypeNameToSizeMap* memoryInfo)
    334349{
    335350    OwnPtr<HeapGraphSerializer> graphSerializer;
    336     if (reportGraph)
    337         graphSerializer = adoptPtr(new HeapGraphSerializer(m_frontend));
     351    OwnPtr<FrontendWrapper> frontendWrapper;
     352
     353    if (reportGraph) {
     354        frontendWrapper = adoptPtr(new FrontendWrapper(m_frontend));
     355        graphSerializer = adoptPtr(new HeapGraphSerializer(frontendWrapper.get()));
     356    }
     357
    338358    MemoryInstrumentationClientImpl memoryInstrumentationClient(graphSerializer.get());
    339359    m_inspectorClient->getAllocatedObjects(memoryInstrumentationClient.allocatedObjects());
     
    353373        memoryInstrumentation.addRootObject(graphSerializer.get());
    354374        graphSerializer->finish();
     375        graphSerializer.release(); // Release it earlier than frontendWrapper
     376        frontendWrapper.release();
    355377    }
    356378
  • trunk/Tools/ChangeLog

    r142617 r142618  
     12013-02-12  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: Native Memory Instrumentation: reportLeaf method doesn't report the leaf node properly.
     4        https://bugs.webkit.org/show_bug.cgi?id=109554
     5
     6        In some cases leaves have no pointer. As example when we report a leaf via addPrivateBuffer.
     7        This patch has new set of tests for HeapGraphSerializer.
     8
     9        Reviewed by Yury Semikhatsky.
     10
     11        * TestWebKitAPI/TestWebKitAPI.gypi:
     12        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     13        * TestWebKitAPI/Tests/WebCore/HeapGraphSerializerTest.cpp: Added.
     14        * TestWebKitAPI/win/TestWebKitAPI.vcproj:
     15
    1162013-02-12  Zan Dobersek  <zdobersek@igalia.com>
    217
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.gypi

    r137924 r142618  
    3232    'variables': {
    3333        'TestWebKitAPI_files': [
     34            'Tests/WebCore/HeapGraphSerializerTest.cpp',
    3435            'Tests/WebCore/LayoutUnit.cpp',
    3536            'Tests/WTF/AtomicString.cpp',
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r142381 r142618  
    1515                0FC6C4CF141034AD005B7F0C /* MetaAllocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */; };
    1616                14464013167A8305000BD218 /* LayoutUnit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14464012167A8305000BD218 /* LayoutUnit.cpp */; };
     17                788CB4AE348F4040827FCCD0 /* HeapGraphGeneratorTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 788CB4AE348F4040827FCCD0 /* HeapGraphGeneratorTest.cpp */; };
    1718                14F3B11315E45EAB00210069 /* SaturatedArithmeticOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14F3B11215E45EAB00210069 /* SaturatedArithmeticOperations.cpp */; };
    1819                1A02C84F125D4A8400E3F4BD /* Find.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A02C84E125D4A8400E3F4BD /* Find.cpp */; };
     
    273274                0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MetaAllocator.cpp; path = WTF/MetaAllocator.cpp; sourceTree = "<group>"; };
    274275                14464012167A8305000BD218 /* LayoutUnit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutUnit.cpp; sourceTree = "<group>"; };
     276                788CB4AE348F4040827FCCD0 /* HeapGraphGeneratorTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HeapGraphGeneratorTest.cpp; sourceTree = "<group>"; };
    275277                14F3B11215E45EAB00210069 /* SaturatedArithmeticOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SaturatedArithmeticOperations.cpp; path = WTF/SaturatedArithmeticOperations.cpp; sourceTree = "<group>"; };
    276278                1A02C84B125D4A5E00E3F4BD /* find.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = find.html; sourceTree = "<group>"; };
     
    565567                                440A1D3814A0103A008A66F2 /* KURL.cpp */,
    566568                                14464012167A8305000BD218 /* LayoutUnit.cpp */,
     569                                788CB4AE348F4040827FCCD0 /* HeapGraphGeneratorTest.cpp */,
    567570                        );
    568571                        path = WebCore;
     
    10151018                                440A1D3914A0103A008A66F2 /* KURL.cpp in Sources */,
    10161019                                14464013167A8305000BD218 /* LayoutUnit.cpp in Sources */,
     1020                                788CB4AE348F4040827FCCD0 /* HeapGraphGeneratorTest.cpp in Sources */,
    10171021                                26300B1816755CD90066886D /* ListHashSet.cpp in Sources */,
    10181022                                52CB47411448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */,
  • trunk/Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj

    r137924 r142618  
    417417                                </Filter>
    418418                                <File
     419                                        RelativePath="..\Tests\WebCore\HeapGraphGeneratorTest.cpp"
     420                                        >
     421                                </File>
     422                                <File
    419423                                        RelativePath="..\Tests\WebCore\LayoutUnit.cpp"
    420424                                        >
Note: See TracChangeset for help on using the changeset viewer.