LCOV - code coverage report
Current view: top level - out/Release/gen/src/inspector/protocol - HeapProfiler.cpp (source / functions) Hit Total Coverage
Test: app.info Lines: 115 397 29.0 %
Date: 2019-01-20 Functions: 18 46 39.1 %

          Line data    Source code
       1             : // This file is generated
       2             : 
       3             : // Copyright (c) 2016 The Chromium Authors. All rights reserved.
       4             : // Use of this source code is governed by a BSD-style license that can be
       5             : // found in the LICENSE file.
       6             : 
       7             : #include "src/inspector/protocol/HeapProfiler.h"
       8             : 
       9             : #include "src/inspector/protocol/Protocol.h"
      10             : 
      11             : namespace v8_inspector {
      12             : namespace protocol {
      13             : namespace HeapProfiler {
      14             : 
      15             : // ------------- Enum values from types.
      16             : 
      17             : const char Metainfo::domainName[] = "HeapProfiler";
      18             : const char Metainfo::commandPrefix[] = "HeapProfiler.";
      19             : const char Metainfo::version[] = "1.3";
      20             : 
      21           0 : std::unique_ptr<SamplingHeapProfileNode> SamplingHeapProfileNode::fromValue(protocol::Value* value, ErrorSupport* errors)
      22             : {
      23           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
      24           0 :         errors->addError("object expected");
      25             :         return nullptr;
      26             :     }
      27             : 
      28           0 :     std::unique_ptr<SamplingHeapProfileNode> result(new SamplingHeapProfileNode());
      29             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
      30           0 :     errors->push();
      31           0 :     protocol::Value* callFrameValue = object->get("callFrame");
      32           0 :     errors->setName("callFrame");
      33           0 :     result->m_callFrame = ValueConversions<protocol::Runtime::CallFrame>::fromValue(callFrameValue, errors);
      34           0 :     protocol::Value* selfSizeValue = object->get("selfSize");
      35           0 :     errors->setName("selfSize");
      36           0 :     result->m_selfSize = ValueConversions<double>::fromValue(selfSizeValue, errors);
      37           0 :     protocol::Value* idValue = object->get("id");
      38           0 :     errors->setName("id");
      39           0 :     result->m_id = ValueConversions<int>::fromValue(idValue, errors);
      40           0 :     protocol::Value* childrenValue = object->get("children");
      41           0 :     errors->setName("children");
      42           0 :     result->m_children = ValueConversions<protocol::Array<protocol::HeapProfiler::SamplingHeapProfileNode>>::fromValue(childrenValue, errors);
      43           0 :     errors->pop();
      44           0 :     if (errors->hasErrors())
      45             :         return nullptr;
      46             :     return result;
      47             : }
      48             : 
      49          50 : std::unique_ptr<protocol::DictionaryValue> SamplingHeapProfileNode::toValue() const
      50             : {
      51          50 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
      52         200 :     result->setValue("callFrame", ValueConversions<protocol::Runtime::CallFrame>::toValue(m_callFrame.get()));
      53         250 :     result->setValue("selfSize", ValueConversions<double>::toValue(m_selfSize));
      54         250 :     result->setValue("id", ValueConversions<int>::toValue(m_id));
      55         200 :     result->setValue("children", ValueConversions<protocol::Array<protocol::HeapProfiler::SamplingHeapProfileNode>>::toValue(m_children.get()));
      56          50 :     return result;
      57             : }
      58             : 
      59           0 : std::unique_ptr<SamplingHeapProfileNode> SamplingHeapProfileNode::clone() const
      60             : {
      61           0 :     ErrorSupport errors;
      62           0 :     return fromValue(toValue().get(), &errors);
      63             : }
      64             : 
      65           0 : std::unique_ptr<SamplingHeapProfileSample> SamplingHeapProfileSample::fromValue(protocol::Value* value, ErrorSupport* errors)
      66             : {
      67           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
      68           0 :         errors->addError("object expected");
      69             :         return nullptr;
      70             :     }
      71             : 
      72           0 :     std::unique_ptr<SamplingHeapProfileSample> result(new SamplingHeapProfileSample());
      73             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
      74           0 :     errors->push();
      75           0 :     protocol::Value* sizeValue = object->get("size");
      76           0 :     errors->setName("size");
      77           0 :     result->m_size = ValueConversions<double>::fromValue(sizeValue, errors);
      78           0 :     protocol::Value* nodeIdValue = object->get("nodeId");
      79           0 :     errors->setName("nodeId");
      80           0 :     result->m_nodeId = ValueConversions<int>::fromValue(nodeIdValue, errors);
      81           0 :     protocol::Value* ordinalValue = object->get("ordinal");
      82           0 :     errors->setName("ordinal");
      83           0 :     result->m_ordinal = ValueConversions<double>::fromValue(ordinalValue, errors);
      84           0 :     errors->pop();
      85           0 :     if (errors->hasErrors())
      86             :         return nullptr;
      87             :     return result;
      88             : }
      89             : 
      90          25 : std::unique_ptr<protocol::DictionaryValue> SamplingHeapProfileSample::toValue() const
      91             : {
      92          25 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
      93         125 :     result->setValue("size", ValueConversions<double>::toValue(m_size));
      94         125 :     result->setValue("nodeId", ValueConversions<int>::toValue(m_nodeId));
      95         125 :     result->setValue("ordinal", ValueConversions<double>::toValue(m_ordinal));
      96          25 :     return result;
      97             : }
      98             : 
      99           0 : std::unique_ptr<SamplingHeapProfileSample> SamplingHeapProfileSample::clone() const
     100             : {
     101           0 :     ErrorSupport errors;
     102           0 :     return fromValue(toValue().get(), &errors);
     103             : }
     104             : 
     105           0 : std::unique_ptr<SamplingHeapProfile> SamplingHeapProfile::fromValue(protocol::Value* value, ErrorSupport* errors)
     106             : {
     107           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     108           0 :         errors->addError("object expected");
     109             :         return nullptr;
     110             :     }
     111             : 
     112           0 :     std::unique_ptr<SamplingHeapProfile> result(new SamplingHeapProfile());
     113             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     114           0 :     errors->push();
     115           0 :     protocol::Value* headValue = object->get("head");
     116           0 :     errors->setName("head");
     117           0 :     result->m_head = ValueConversions<protocol::HeapProfiler::SamplingHeapProfileNode>::fromValue(headValue, errors);
     118           0 :     protocol::Value* samplesValue = object->get("samples");
     119           0 :     errors->setName("samples");
     120           0 :     result->m_samples = ValueConversions<protocol::Array<protocol::HeapProfiler::SamplingHeapProfileSample>>::fromValue(samplesValue, errors);
     121           0 :     errors->pop();
     122           0 :     if (errors->hasErrors())
     123             :         return nullptr;
     124             :     return result;
     125             : }
     126             : 
     127          20 : std::unique_ptr<protocol::DictionaryValue> SamplingHeapProfile::toValue() const
     128             : {
     129          20 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     130          80 :     result->setValue("head", ValueConversions<protocol::HeapProfiler::SamplingHeapProfileNode>::toValue(m_head.get()));
     131          80 :     result->setValue("samples", ValueConversions<protocol::Array<protocol::HeapProfiler::SamplingHeapProfileSample>>::toValue(m_samples.get()));
     132          20 :     return result;
     133             : }
     134             : 
     135           0 : std::unique_ptr<SamplingHeapProfile> SamplingHeapProfile::clone() const
     136             : {
     137           0 :     ErrorSupport errors;
     138           0 :     return fromValue(toValue().get(), &errors);
     139             : }
     140             : 
     141           0 : std::unique_ptr<AddHeapSnapshotChunkNotification> AddHeapSnapshotChunkNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     142             : {
     143           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     144           0 :         errors->addError("object expected");
     145             :         return nullptr;
     146             :     }
     147             : 
     148           0 :     std::unique_ptr<AddHeapSnapshotChunkNotification> result(new AddHeapSnapshotChunkNotification());
     149             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     150           0 :     errors->push();
     151           0 :     protocol::Value* chunkValue = object->get("chunk");
     152           0 :     errors->setName("chunk");
     153           0 :     result->m_chunk = ValueConversions<String>::fromValue(chunkValue, errors);
     154           0 :     errors->pop();
     155           0 :     if (errors->hasErrors())
     156             :         return nullptr;
     157             :     return result;
     158             : }
     159             : 
     160         175 : std::unique_ptr<protocol::DictionaryValue> AddHeapSnapshotChunkNotification::toValue() const
     161             : {
     162         175 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     163         875 :     result->setValue("chunk", ValueConversions<String>::toValue(m_chunk));
     164         175 :     return result;
     165             : }
     166             : 
     167           0 : std::unique_ptr<AddHeapSnapshotChunkNotification> AddHeapSnapshotChunkNotification::clone() const
     168             : {
     169           0 :     ErrorSupport errors;
     170           0 :     return fromValue(toValue().get(), &errors);
     171             : }
     172             : 
     173           0 : std::unique_ptr<HeapStatsUpdateNotification> HeapStatsUpdateNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     174             : {
     175           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     176           0 :         errors->addError("object expected");
     177             :         return nullptr;
     178             :     }
     179             : 
     180           0 :     std::unique_ptr<HeapStatsUpdateNotification> result(new HeapStatsUpdateNotification());
     181             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     182           0 :     errors->push();
     183           0 :     protocol::Value* statsUpdateValue = object->get("statsUpdate");
     184           0 :     errors->setName("statsUpdate");
     185             :     result->m_statsUpdate = ValueConversions<protocol::Array<int>>::fromValue(statsUpdateValue, errors);
     186           0 :     errors->pop();
     187           0 :     if (errors->hasErrors())
     188             :         return nullptr;
     189             :     return result;
     190             : }
     191             : 
     192           0 : std::unique_ptr<protocol::DictionaryValue> HeapStatsUpdateNotification::toValue() const
     193             : {
     194           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     195           0 :     result->setValue("statsUpdate", ValueConversions<protocol::Array<int>>::toValue(m_statsUpdate.get()));
     196           0 :     return result;
     197             : }
     198             : 
     199           0 : std::unique_ptr<HeapStatsUpdateNotification> HeapStatsUpdateNotification::clone() const
     200             : {
     201           0 :     ErrorSupport errors;
     202           0 :     return fromValue(toValue().get(), &errors);
     203             : }
     204             : 
     205           0 : std::unique_ptr<LastSeenObjectIdNotification> LastSeenObjectIdNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     206             : {
     207           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     208           0 :         errors->addError("object expected");
     209             :         return nullptr;
     210             :     }
     211             : 
     212           0 :     std::unique_ptr<LastSeenObjectIdNotification> result(new LastSeenObjectIdNotification());
     213             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     214           0 :     errors->push();
     215           0 :     protocol::Value* lastSeenObjectIdValue = object->get("lastSeenObjectId");
     216           0 :     errors->setName("lastSeenObjectId");
     217           0 :     result->m_lastSeenObjectId = ValueConversions<int>::fromValue(lastSeenObjectIdValue, errors);
     218           0 :     protocol::Value* timestampValue = object->get("timestamp");
     219           0 :     errors->setName("timestamp");
     220           0 :     result->m_timestamp = ValueConversions<double>::fromValue(timestampValue, errors);
     221           0 :     errors->pop();
     222           0 :     if (errors->hasErrors())
     223             :         return nullptr;
     224             :     return result;
     225             : }
     226             : 
     227           0 : std::unique_ptr<protocol::DictionaryValue> LastSeenObjectIdNotification::toValue() const
     228             : {
     229           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     230           0 :     result->setValue("lastSeenObjectId", ValueConversions<int>::toValue(m_lastSeenObjectId));
     231           0 :     result->setValue("timestamp", ValueConversions<double>::toValue(m_timestamp));
     232           0 :     return result;
     233             : }
     234             : 
     235           0 : std::unique_ptr<LastSeenObjectIdNotification> LastSeenObjectIdNotification::clone() const
     236             : {
     237           0 :     ErrorSupport errors;
     238           0 :     return fromValue(toValue().get(), &errors);
     239             : }
     240             : 
     241           0 : std::unique_ptr<ReportHeapSnapshotProgressNotification> ReportHeapSnapshotProgressNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     242             : {
     243           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     244           0 :         errors->addError("object expected");
     245             :         return nullptr;
     246             :     }
     247             : 
     248           0 :     std::unique_ptr<ReportHeapSnapshotProgressNotification> result(new ReportHeapSnapshotProgressNotification());
     249             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     250           0 :     errors->push();
     251           0 :     protocol::Value* doneValue = object->get("done");
     252           0 :     errors->setName("done");
     253           0 :     result->m_done = ValueConversions<int>::fromValue(doneValue, errors);
     254           0 :     protocol::Value* totalValue = object->get("total");
     255           0 :     errors->setName("total");
     256           0 :     result->m_total = ValueConversions<int>::fromValue(totalValue, errors);
     257           0 :     protocol::Value* finishedValue = object->get("finished");
     258           0 :     if (finishedValue) {
     259           0 :         errors->setName("finished");
     260           0 :         result->m_finished = ValueConversions<bool>::fromValue(finishedValue, errors);
     261             :     }
     262           0 :     errors->pop();
     263           0 :     if (errors->hasErrors())
     264             :         return nullptr;
     265             :     return result;
     266             : }
     267             : 
     268           0 : std::unique_ptr<protocol::DictionaryValue> ReportHeapSnapshotProgressNotification::toValue() const
     269             : {
     270           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     271           0 :     result->setValue("done", ValueConversions<int>::toValue(m_done));
     272           0 :     result->setValue("total", ValueConversions<int>::toValue(m_total));
     273           0 :     if (m_finished.isJust())
     274           0 :         result->setValue("finished", ValueConversions<bool>::toValue(m_finished.fromJust()));
     275           0 :     return result;
     276             : }
     277             : 
     278           0 : std::unique_ptr<ReportHeapSnapshotProgressNotification> ReportHeapSnapshotProgressNotification::clone() const
     279             : {
     280           0 :     ErrorSupport errors;
     281           0 :     return fromValue(toValue().get(), &errors);
     282             : }
     283             : 
     284             : // ------------- Enum values from params.
     285             : 
     286             : 
     287             : // ------------- Frontend notifications.
     288             : 
     289         175 : void Frontend::addHeapSnapshotChunk(const String& chunk)
     290             : {
     291         175 :     if (!m_frontendChannel)
     292         175 :         return;
     293             :     std::unique_ptr<AddHeapSnapshotChunkNotification> messageData = AddHeapSnapshotChunkNotification::create()
     294         175 :         .setChunk(chunk)
     295             :         .build();
     296        1225 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.addHeapSnapshotChunk", std::move(messageData)));
     297             : }
     298             : 
     299           0 : void Frontend::heapStatsUpdate(std::unique_ptr<protocol::Array<int>> statsUpdate)
     300             : {
     301           0 :     if (!m_frontendChannel)
     302           0 :         return;
     303             :     std::unique_ptr<HeapStatsUpdateNotification> messageData = HeapStatsUpdateNotification::create()
     304             :         .setStatsUpdate(std::move(statsUpdate))
     305             :         .build();
     306           0 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.heapStatsUpdate", std::move(messageData)));
     307             : }
     308             : 
     309           0 : void Frontend::lastSeenObjectId(int lastSeenObjectId, double timestamp)
     310             : {
     311           0 :     if (!m_frontendChannel)
     312           0 :         return;
     313             :     std::unique_ptr<LastSeenObjectIdNotification> messageData = LastSeenObjectIdNotification::create()
     314           0 :         .setLastSeenObjectId(lastSeenObjectId)
     315             :         .setTimestamp(timestamp)
     316             :         .build();
     317           0 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.lastSeenObjectId", std::move(messageData)));
     318             : }
     319             : 
     320           0 : void Frontend::reportHeapSnapshotProgress(int done, int total, Maybe<bool> finished)
     321             : {
     322           0 :     if (!m_frontendChannel)
     323           0 :         return;
     324             :     std::unique_ptr<ReportHeapSnapshotProgressNotification> messageData = ReportHeapSnapshotProgressNotification::create()
     325           0 :         .setDone(done)
     326             :         .setTotal(total)
     327             :         .build();
     328           0 :     if (finished.isJust())
     329           0 :         messageData->setFinished(std::move(finished).takeJust());
     330           0 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.reportHeapSnapshotProgress", std::move(messageData)));
     331             : }
     332             : 
     333           0 : void Frontend::resetProfiles()
     334             : {
     335           0 :     if (!m_frontendChannel)
     336           0 :         return;
     337           0 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.resetProfiles"));
     338             : }
     339             : 
     340         175 : void Frontend::flush()
     341             : {
     342         175 :     m_frontendChannel->flushProtocolNotifications();
     343         175 : }
     344             : 
     345           0 : void Frontend::sendRawNotification(const String& notification)
     346             : {
     347           0 :     m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification));
     348           0 : }
     349             : 
     350             : // --------------------- Dispatcher.
     351             : 
     352             : class DispatcherImpl : public protocol::DispatcherBase {
     353             : public:
     354        3834 :     DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend)
     355             :         : DispatcherBase(frontendChannel)
     356       11502 :         , m_backend(backend) {
     357       11502 :         m_dispatchMap["HeapProfiler.addInspectedHeapObject"] = &DispatcherImpl::addInspectedHeapObject;
     358       11502 :         m_dispatchMap["HeapProfiler.collectGarbage"] = &DispatcherImpl::collectGarbage;
     359       11502 :         m_dispatchMap["HeapProfiler.disable"] = &DispatcherImpl::disable;
     360       11502 :         m_dispatchMap["HeapProfiler.enable"] = &DispatcherImpl::enable;
     361       11502 :         m_dispatchMap["HeapProfiler.getHeapObjectId"] = &DispatcherImpl::getHeapObjectId;
     362       11502 :         m_dispatchMap["HeapProfiler.getObjectByHeapObjectId"] = &DispatcherImpl::getObjectByHeapObjectId;
     363       11502 :         m_dispatchMap["HeapProfiler.getSamplingProfile"] = &DispatcherImpl::getSamplingProfile;
     364       11502 :         m_dispatchMap["HeapProfiler.startSampling"] = &DispatcherImpl::startSampling;
     365       11502 :         m_dispatchMap["HeapProfiler.startTrackingHeapObjects"] = &DispatcherImpl::startTrackingHeapObjects;
     366       11502 :         m_dispatchMap["HeapProfiler.stopSampling"] = &DispatcherImpl::stopSampling;
     367       11502 :         m_dispatchMap["HeapProfiler.stopTrackingHeapObjects"] = &DispatcherImpl::stopTrackingHeapObjects;
     368       11502 :         m_dispatchMap["HeapProfiler.takeHeapSnapshot"] = &DispatcherImpl::takeHeapSnapshot;
     369        3834 :     }
     370       11502 :     ~DispatcherImpl() override { }
     371             :     bool canDispatch(const String& method) override;
     372             :     void dispatch(int callId, const String& method, const String& message, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
     373             :     std::unordered_map<String, String>& redirects() { return m_redirects; }
     374             : 
     375             : protected:
     376             :     using CallHandler = void (DispatcherImpl::*)(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
     377             :     using DispatchMap = std::unordered_map<String, CallHandler>;
     378             :     DispatchMap m_dispatchMap;
     379             :     std::unordered_map<String, String> m_redirects;
     380             : 
     381             :     void addInspectedHeapObject(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     382             :     void collectGarbage(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     383             :     void disable(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     384             :     void enable(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     385             :     void getHeapObjectId(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     386             :     void getObjectByHeapObjectId(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     387             :     void getSamplingProfile(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     388             :     void startSampling(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     389             :     void startTrackingHeapObjects(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     390             :     void stopSampling(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     391             :     void stopTrackingHeapObjects(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     392             :     void takeHeapSnapshot(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     393             : 
     394             :     Backend* m_backend;
     395             : };
     396             : 
     397         315 : bool DispatcherImpl::canDispatch(const String& method) {
     398         315 :     return m_dispatchMap.find(method) != m_dispatchMap.end();
     399             : }
     400             : 
     401         315 : void DispatcherImpl::dispatch(int callId, const String& method, const String& message, std::unique_ptr<protocol::DictionaryValue> messageObject)
     402             : {
     403             :     std::unordered_map<String, CallHandler>::iterator it = m_dispatchMap.find(method);
     404             :     DCHECK(it != m_dispatchMap.end());
     405         315 :     protocol::ErrorSupport errors;
     406         945 :     (this->*(it->second))(callId, method, message, std::move(messageObject), &errors);
     407         315 : }
     408             : 
     409             : 
     410           0 : void DispatcherImpl::addInspectedHeapObject(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     411             : {
     412             :     // Prepare input parameters.
     413           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     414           0 :     errors->push();
     415           0 :     protocol::Value* heapObjectIdValue = object ? object->get("heapObjectId") : nullptr;
     416           0 :     errors->setName("heapObjectId");
     417           0 :     String in_heapObjectId = ValueConversions<String>::fromValue(heapObjectIdValue, errors);
     418           0 :     errors->pop();
     419           0 :     if (errors->hasErrors()) {
     420           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     421           0 :         return;
     422             :     }
     423             : 
     424           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     425           0 :     DispatchResponse response = m_backend->addInspectedHeapObject(in_heapObjectId);
     426           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     427           0 :         channel()->fallThrough(callId, method, message);
     428           0 :         return;
     429             :     }
     430           0 :     if (weak->get())
     431           0 :         weak->get()->sendResponse(callId, response);
     432             :     return;
     433             : }
     434             : 
     435         240 : void DispatcherImpl::collectGarbage(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     436             : {
     437             : 
     438         240 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     439         240 :     DispatchResponse response = m_backend->collectGarbage();
     440         240 :     if (response.status() == DispatchResponse::kFallThrough) {
     441           0 :         channel()->fallThrough(callId, method, message);
     442           0 :         return;
     443             :     }
     444         240 :     if (weak->get())
     445         240 :         weak->get()->sendResponse(callId, response);
     446             :     return;
     447             : }
     448             : 
     449           0 : void DispatcherImpl::disable(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     450             : {
     451             : 
     452           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     453           0 :     DispatchResponse response = m_backend->disable();
     454           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     455           0 :         channel()->fallThrough(callId, method, message);
     456           0 :         return;
     457             :     }
     458           0 :     if (weak->get())
     459           0 :         weak->get()->sendResponse(callId, response);
     460             :     return;
     461             : }
     462             : 
     463          20 : void DispatcherImpl::enable(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     464             : {
     465             : 
     466          20 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     467          20 :     DispatchResponse response = m_backend->enable();
     468          20 :     if (response.status() == DispatchResponse::kFallThrough) {
     469           0 :         channel()->fallThrough(callId, method, message);
     470           0 :         return;
     471             :     }
     472          20 :     if (weak->get())
     473          20 :         weak->get()->sendResponse(callId, response);
     474             :     return;
     475             : }
     476             : 
     477           0 : void DispatcherImpl::getHeapObjectId(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     478             : {
     479             :     // Prepare input parameters.
     480           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     481           0 :     errors->push();
     482           0 :     protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
     483           0 :     errors->setName("objectId");
     484           0 :     String in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
     485           0 :     errors->pop();
     486           0 :     if (errors->hasErrors()) {
     487           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     488           0 :         return;
     489             :     }
     490             :     // Declare output parameters.
     491           0 :     String out_heapSnapshotObjectId;
     492             : 
     493           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     494           0 :     DispatchResponse response = m_backend->getHeapObjectId(in_objectId, &out_heapSnapshotObjectId);
     495           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     496           0 :         channel()->fallThrough(callId, method, message);
     497           0 :         return;
     498             :     }
     499           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     500           0 :     if (response.status() == DispatchResponse::kSuccess) {
     501           0 :         result->setValue("heapSnapshotObjectId", ValueConversions<String>::toValue(out_heapSnapshotObjectId));
     502             :     }
     503           0 :     if (weak->get())
     504           0 :         weak->get()->sendResponse(callId, response, std::move(result));
     505             :     return;
     506             : }
     507             : 
     508           0 : void DispatcherImpl::getObjectByHeapObjectId(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     509             : {
     510             :     // Prepare input parameters.
     511           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     512           0 :     errors->push();
     513           0 :     protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
     514           0 :     errors->setName("objectId");
     515           0 :     String in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
     516           0 :     protocol::Value* objectGroupValue = object ? object->get("objectGroup") : nullptr;
     517             :     Maybe<String> in_objectGroup;
     518           0 :     if (objectGroupValue) {
     519           0 :         errors->setName("objectGroup");
     520           0 :         in_objectGroup = ValueConversions<String>::fromValue(objectGroupValue, errors);
     521             :     }
     522           0 :     errors->pop();
     523           0 :     if (errors->hasErrors()) {
     524           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     525           0 :         return;
     526             :     }
     527             :     // Declare output parameters.
     528           0 :     std::unique_ptr<protocol::Runtime::RemoteObject> out_result;
     529             : 
     530           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     531           0 :     DispatchResponse response = m_backend->getObjectByHeapObjectId(in_objectId, std::move(in_objectGroup), &out_result);
     532           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     533           0 :         channel()->fallThrough(callId, method, message);
     534           0 :         return;
     535             :     }
     536           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     537           0 :     if (response.status() == DispatchResponse::kSuccess) {
     538           0 :         result->setValue("result", ValueConversions<protocol::Runtime::RemoteObject>::toValue(out_result.get()));
     539             :     }
     540           0 :     if (weak->get())
     541           0 :         weak->get()->sendResponse(callId, response, std::move(result));
     542             :     return;
     543             : }
     544             : 
     545          20 : void DispatcherImpl::getSamplingProfile(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     546             : {
     547             :     // Declare output parameters.
     548          20 :     std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile> out_profile;
     549             : 
     550          20 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     551          20 :     DispatchResponse response = m_backend->getSamplingProfile(&out_profile);
     552          20 :     if (response.status() == DispatchResponse::kFallThrough) {
     553           0 :         channel()->fallThrough(callId, method, message);
     554           0 :         return;
     555             :     }
     556          20 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     557          20 :     if (response.status() == DispatchResponse::kSuccess) {
     558          60 :         result->setValue("profile", ValueConversions<protocol::HeapProfiler::SamplingHeapProfile>::toValue(out_profile.get()));
     559             :     }
     560          20 :     if (weak->get())
     561          40 :         weak->get()->sendResponse(callId, response, std::move(result));
     562             :     return;
     563             : }
     564             : 
     565           5 : void DispatcherImpl::startSampling(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     566             : {
     567             :     // Prepare input parameters.
     568          15 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     569           5 :     errors->push();
     570          10 :     protocol::Value* samplingIntervalValue = object ? object->get("samplingInterval") : nullptr;
     571             :     Maybe<double> in_samplingInterval;
     572           5 :     if (samplingIntervalValue) {
     573           0 :         errors->setName("samplingInterval");
     574           0 :         in_samplingInterval = ValueConversions<double>::fromValue(samplingIntervalValue, errors);
     575             :     }
     576           5 :     errors->pop();
     577           5 :     if (errors->hasErrors()) {
     578           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     579           0 :         return;
     580             :     }
     581             : 
     582           5 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     583          10 :     DispatchResponse response = m_backend->startSampling(std::move(in_samplingInterval));
     584           5 :     if (response.status() == DispatchResponse::kFallThrough) {
     585           0 :         channel()->fallThrough(callId, method, message);
     586           0 :         return;
     587             :     }
     588           5 :     if (weak->get())
     589           5 :         weak->get()->sendResponse(callId, response);
     590             :     return;
     591             : }
     592             : 
     593           0 : void DispatcherImpl::startTrackingHeapObjects(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     594             : {
     595             :     // Prepare input parameters.
     596           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     597           0 :     errors->push();
     598           0 :     protocol::Value* trackAllocationsValue = object ? object->get("trackAllocations") : nullptr;
     599             :     Maybe<bool> in_trackAllocations;
     600           0 :     if (trackAllocationsValue) {
     601           0 :         errors->setName("trackAllocations");
     602           0 :         in_trackAllocations = ValueConversions<bool>::fromValue(trackAllocationsValue, errors);
     603             :     }
     604           0 :     errors->pop();
     605           0 :     if (errors->hasErrors()) {
     606           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     607           0 :         return;
     608             :     }
     609             : 
     610           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     611           0 :     DispatchResponse response = m_backend->startTrackingHeapObjects(std::move(in_trackAllocations));
     612           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     613           0 :         channel()->fallThrough(callId, method, message);
     614           0 :         return;
     615             :     }
     616           0 :     if (weak->get())
     617           0 :         weak->get()->sendResponse(callId, response);
     618             :     return;
     619             : }
     620             : 
     621           5 : void DispatcherImpl::stopSampling(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     622             : {
     623             :     // Declare output parameters.
     624           5 :     std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile> out_profile;
     625             : 
     626           5 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     627           5 :     DispatchResponse response = m_backend->stopSampling(&out_profile);
     628           5 :     if (response.status() == DispatchResponse::kFallThrough) {
     629           0 :         channel()->fallThrough(callId, method, message);
     630           0 :         return;
     631             :     }
     632           5 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     633           5 :     if (response.status() == DispatchResponse::kSuccess) {
     634          20 :         result->setValue("profile", ValueConversions<protocol::HeapProfiler::SamplingHeapProfile>::toValue(out_profile.get()));
     635             :     }
     636           5 :     if (weak->get())
     637          10 :         weak->get()->sendResponse(callId, response, std::move(result));
     638             :     return;
     639             : }
     640             : 
     641           0 : void DispatcherImpl::stopTrackingHeapObjects(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     642             : {
     643             :     // Prepare input parameters.
     644           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     645           0 :     errors->push();
     646           0 :     protocol::Value* reportProgressValue = object ? object->get("reportProgress") : nullptr;
     647             :     Maybe<bool> in_reportProgress;
     648           0 :     if (reportProgressValue) {
     649           0 :         errors->setName("reportProgress");
     650           0 :         in_reportProgress = ValueConversions<bool>::fromValue(reportProgressValue, errors);
     651             :     }
     652           0 :     errors->pop();
     653           0 :     if (errors->hasErrors()) {
     654           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     655           0 :         return;
     656             :     }
     657             : 
     658           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     659           0 :     DispatchResponse response = m_backend->stopTrackingHeapObjects(std::move(in_reportProgress));
     660           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     661           0 :         channel()->fallThrough(callId, method, message);
     662           0 :         return;
     663             :     }
     664           0 :     if (weak->get())
     665           0 :         weak->get()->sendResponse(callId, response);
     666             :     return;
     667             : }
     668             : 
     669          25 : void DispatcherImpl::takeHeapSnapshot(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     670             : {
     671             :     // Prepare input parameters.
     672          75 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     673          25 :     errors->push();
     674          50 :     protocol::Value* reportProgressValue = object ? object->get("reportProgress") : nullptr;
     675             :     Maybe<bool> in_reportProgress;
     676          25 :     if (reportProgressValue) {
     677          15 :         errors->setName("reportProgress");
     678          15 :         in_reportProgress = ValueConversions<bool>::fromValue(reportProgressValue, errors);
     679             :     }
     680          25 :     errors->pop();
     681          25 :     if (errors->hasErrors()) {
     682           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     683           0 :         return;
     684             :     }
     685             : 
     686          25 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     687          50 :     DispatchResponse response = m_backend->takeHeapSnapshot(std::move(in_reportProgress));
     688          25 :     if (response.status() == DispatchResponse::kFallThrough) {
     689           0 :         channel()->fallThrough(callId, method, message);
     690           0 :         return;
     691             :     }
     692          25 :     if (weak->get())
     693          25 :         weak->get()->sendResponse(callId, response);
     694             :     return;
     695             : }
     696             : 
     697             : // static
     698        3834 : void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
     699             : {
     700        3834 :     std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend));
     701        3834 :     uber->setupRedirects(dispatcher->redirects());
     702       11502 :     uber->registerBackend("HeapProfiler", std::move(dispatcher));
     703        3834 : }
     704             : 
     705             : } // HeapProfiler
     706             : } // namespace v8_inspector
     707             : } // namespace protocol

Generated by: LCOV version 1.10