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: 66 331 19.9 %
Date: 2017-04-26 Functions: 12 41 29.3 %

          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.2";
      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* childrenValue = object->get("children");
      38           0 :     errors->setName("children");
      39           0 :     result->m_children = ValueConversions<protocol::Array<protocol::HeapProfiler::SamplingHeapProfileNode>>::fromValue(childrenValue, errors);
      40           0 :     errors->pop();
      41           0 :     if (errors->hasErrors())
      42             :         return nullptr;
      43             :     return result;
      44             : }
      45             : 
      46           0 : std::unique_ptr<protocol::DictionaryValue> SamplingHeapProfileNode::toValue() const
      47             : {
      48           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
      49           0 :     result->setValue("callFrame", ValueConversions<protocol::Runtime::CallFrame>::toValue(m_callFrame.get()));
      50           0 :     result->setValue("selfSize", ValueConversions<double>::toValue(m_selfSize));
      51           0 :     result->setValue("children", ValueConversions<protocol::Array<protocol::HeapProfiler::SamplingHeapProfileNode>>::toValue(m_children.get()));
      52           0 :     return result;
      53             : }
      54             : 
      55           0 : std::unique_ptr<SamplingHeapProfileNode> SamplingHeapProfileNode::clone() const
      56             : {
      57           0 :     ErrorSupport errors;
      58           0 :     return fromValue(toValue().get(), &errors);
      59             : }
      60             : 
      61           0 : std::unique_ptr<SamplingHeapProfile> SamplingHeapProfile::fromValue(protocol::Value* value, ErrorSupport* errors)
      62             : {
      63           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
      64           0 :         errors->addError("object expected");
      65             :         return nullptr;
      66             :     }
      67             : 
      68           0 :     std::unique_ptr<SamplingHeapProfile> result(new SamplingHeapProfile());
      69             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
      70           0 :     errors->push();
      71           0 :     protocol::Value* headValue = object->get("head");
      72           0 :     errors->setName("head");
      73           0 :     result->m_head = ValueConversions<protocol::HeapProfiler::SamplingHeapProfileNode>::fromValue(headValue, errors);
      74           0 :     errors->pop();
      75           0 :     if (errors->hasErrors())
      76             :         return nullptr;
      77             :     return result;
      78             : }
      79             : 
      80           0 : std::unique_ptr<protocol::DictionaryValue> SamplingHeapProfile::toValue() const
      81             : {
      82           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
      83           0 :     result->setValue("head", ValueConversions<protocol::HeapProfiler::SamplingHeapProfileNode>::toValue(m_head.get()));
      84           0 :     return result;
      85             : }
      86             : 
      87           0 : std::unique_ptr<SamplingHeapProfile> SamplingHeapProfile::clone() const
      88             : {
      89           0 :     ErrorSupport errors;
      90           0 :     return fromValue(toValue().get(), &errors);
      91             : }
      92             : 
      93           0 : std::unique_ptr<AddHeapSnapshotChunkNotification> AddHeapSnapshotChunkNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
      94             : {
      95           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
      96           0 :         errors->addError("object expected");
      97             :         return nullptr;
      98             :     }
      99             : 
     100           0 :     std::unique_ptr<AddHeapSnapshotChunkNotification> result(new AddHeapSnapshotChunkNotification());
     101             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     102           0 :     errors->push();
     103           0 :     protocol::Value* chunkValue = object->get("chunk");
     104           0 :     errors->setName("chunk");
     105           0 :     result->m_chunk = ValueConversions<String>::fromValue(chunkValue, errors);
     106           0 :     errors->pop();
     107           0 :     if (errors->hasErrors())
     108             :         return nullptr;
     109             :     return result;
     110             : }
     111             : 
     112         176 : std::unique_ptr<protocol::DictionaryValue> AddHeapSnapshotChunkNotification::toValue() const
     113             : {
     114         176 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     115         880 :     result->setValue("chunk", ValueConversions<String>::toValue(m_chunk));
     116         176 :     return result;
     117             : }
     118             : 
     119           0 : std::unique_ptr<AddHeapSnapshotChunkNotification> AddHeapSnapshotChunkNotification::clone() const
     120             : {
     121           0 :     ErrorSupport errors;
     122           0 :     return fromValue(toValue().get(), &errors);
     123             : }
     124             : 
     125           0 : std::unique_ptr<ReportHeapSnapshotProgressNotification> ReportHeapSnapshotProgressNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     126             : {
     127           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     128           0 :         errors->addError("object expected");
     129             :         return nullptr;
     130             :     }
     131             : 
     132           0 :     std::unique_ptr<ReportHeapSnapshotProgressNotification> result(new ReportHeapSnapshotProgressNotification());
     133             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     134           0 :     errors->push();
     135           0 :     protocol::Value* doneValue = object->get("done");
     136           0 :     errors->setName("done");
     137           0 :     result->m_done = ValueConversions<int>::fromValue(doneValue, errors);
     138           0 :     protocol::Value* totalValue = object->get("total");
     139           0 :     errors->setName("total");
     140           0 :     result->m_total = ValueConversions<int>::fromValue(totalValue, errors);
     141           0 :     protocol::Value* finishedValue = object->get("finished");
     142           0 :     if (finishedValue) {
     143           0 :         errors->setName("finished");
     144           0 :         result->m_finished = ValueConversions<bool>::fromValue(finishedValue, errors);
     145             :     }
     146           0 :     errors->pop();
     147           0 :     if (errors->hasErrors())
     148             :         return nullptr;
     149             :     return result;
     150             : }
     151             : 
     152           0 : std::unique_ptr<protocol::DictionaryValue> ReportHeapSnapshotProgressNotification::toValue() const
     153             : {
     154           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     155           0 :     result->setValue("done", ValueConversions<int>::toValue(m_done));
     156           0 :     result->setValue("total", ValueConversions<int>::toValue(m_total));
     157           0 :     if (m_finished.isJust())
     158           0 :         result->setValue("finished", ValueConversions<bool>::toValue(m_finished.fromJust()));
     159           0 :     return result;
     160             : }
     161             : 
     162           0 : std::unique_ptr<ReportHeapSnapshotProgressNotification> ReportHeapSnapshotProgressNotification::clone() const
     163             : {
     164           0 :     ErrorSupport errors;
     165           0 :     return fromValue(toValue().get(), &errors);
     166             : }
     167             : 
     168           0 : std::unique_ptr<LastSeenObjectIdNotification> LastSeenObjectIdNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     169             : {
     170           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     171           0 :         errors->addError("object expected");
     172             :         return nullptr;
     173             :     }
     174             : 
     175           0 :     std::unique_ptr<LastSeenObjectIdNotification> result(new LastSeenObjectIdNotification());
     176             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     177           0 :     errors->push();
     178           0 :     protocol::Value* lastSeenObjectIdValue = object->get("lastSeenObjectId");
     179           0 :     errors->setName("lastSeenObjectId");
     180           0 :     result->m_lastSeenObjectId = ValueConversions<int>::fromValue(lastSeenObjectIdValue, errors);
     181           0 :     protocol::Value* timestampValue = object->get("timestamp");
     182           0 :     errors->setName("timestamp");
     183           0 :     result->m_timestamp = ValueConversions<double>::fromValue(timestampValue, errors);
     184           0 :     errors->pop();
     185           0 :     if (errors->hasErrors())
     186             :         return nullptr;
     187             :     return result;
     188             : }
     189             : 
     190           0 : std::unique_ptr<protocol::DictionaryValue> LastSeenObjectIdNotification::toValue() const
     191             : {
     192           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     193           0 :     result->setValue("lastSeenObjectId", ValueConversions<int>::toValue(m_lastSeenObjectId));
     194           0 :     result->setValue("timestamp", ValueConversions<double>::toValue(m_timestamp));
     195           0 :     return result;
     196             : }
     197             : 
     198           0 : std::unique_ptr<LastSeenObjectIdNotification> LastSeenObjectIdNotification::clone() const
     199             : {
     200           0 :     ErrorSupport errors;
     201           0 :     return fromValue(toValue().get(), &errors);
     202             : }
     203             : 
     204           0 : std::unique_ptr<HeapStatsUpdateNotification> HeapStatsUpdateNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
     205             : {
     206           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
     207           0 :         errors->addError("object expected");
     208             :         return nullptr;
     209             :     }
     210             : 
     211           0 :     std::unique_ptr<HeapStatsUpdateNotification> result(new HeapStatsUpdateNotification());
     212             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
     213           0 :     errors->push();
     214           0 :     protocol::Value* statsUpdateValue = object->get("statsUpdate");
     215           0 :     errors->setName("statsUpdate");
     216           0 :     result->m_statsUpdate = ValueConversions<protocol::Array<int>>::fromValue(statsUpdateValue, errors);
     217           0 :     errors->pop();
     218           0 :     if (errors->hasErrors())
     219             :         return nullptr;
     220             :     return result;
     221             : }
     222             : 
     223           0 : std::unique_ptr<protocol::DictionaryValue> HeapStatsUpdateNotification::toValue() const
     224             : {
     225           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     226           0 :     result->setValue("statsUpdate", ValueConversions<protocol::Array<int>>::toValue(m_statsUpdate.get()));
     227           0 :     return result;
     228             : }
     229             : 
     230           0 : std::unique_ptr<HeapStatsUpdateNotification> HeapStatsUpdateNotification::clone() const
     231             : {
     232           0 :     ErrorSupport errors;
     233           0 :     return fromValue(toValue().get(), &errors);
     234             : }
     235             : 
     236             : // ------------- Enum values from params.
     237             : 
     238             : 
     239             : // ------------- Frontend notifications.
     240             : 
     241         176 : void Frontend::addHeapSnapshotChunk(const String& chunk)
     242             : {
     243         176 :     if (!m_frontendChannel)
     244         176 :         return;
     245             :     std::unique_ptr<AddHeapSnapshotChunkNotification> messageData = AddHeapSnapshotChunkNotification::create()
     246         176 :         .setChunk(chunk)
     247             :         .build();
     248        1232 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.addHeapSnapshotChunk", std::move(messageData)));
     249             : }
     250             : 
     251           0 : void Frontend::resetProfiles()
     252             : {
     253           0 :     if (!m_frontendChannel)
     254           0 :         return;
     255           0 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.resetProfiles"));
     256             : }
     257             : 
     258           0 : void Frontend::reportHeapSnapshotProgress(int done, int total, Maybe<bool> finished)
     259             : {
     260           0 :     if (!m_frontendChannel)
     261           0 :         return;
     262             :     std::unique_ptr<ReportHeapSnapshotProgressNotification> messageData = ReportHeapSnapshotProgressNotification::create()
     263           0 :         .setDone(done)
     264             :         .setTotal(total)
     265             :         .build();
     266           0 :     if (finished.isJust())
     267           0 :         messageData->setFinished(std::move(finished).takeJust());
     268           0 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.reportHeapSnapshotProgress", std::move(messageData)));
     269             : }
     270             : 
     271           0 : void Frontend::lastSeenObjectId(int lastSeenObjectId, double timestamp)
     272             : {
     273           0 :     if (!m_frontendChannel)
     274           0 :         return;
     275             :     std::unique_ptr<LastSeenObjectIdNotification> messageData = LastSeenObjectIdNotification::create()
     276           0 :         .setLastSeenObjectId(lastSeenObjectId)
     277             :         .setTimestamp(timestamp)
     278             :         .build();
     279           0 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.lastSeenObjectId", std::move(messageData)));
     280             : }
     281             : 
     282           0 : void Frontend::heapStatsUpdate(std::unique_ptr<protocol::Array<int>> statsUpdate)
     283             : {
     284           0 :     if (!m_frontendChannel)
     285           0 :         return;
     286             :     std::unique_ptr<HeapStatsUpdateNotification> messageData = HeapStatsUpdateNotification::create()
     287             :         .setStatsUpdate(std::move(statsUpdate))
     288             :         .build();
     289           0 :     m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.heapStatsUpdate", std::move(messageData)));
     290             : }
     291             : 
     292         176 : void Frontend::flush()
     293             : {
     294         176 :     m_frontendChannel->flushProtocolNotifications();
     295         176 : }
     296             : 
     297           0 : void Frontend::sendRawNotification(const String& notification)
     298             : {
     299           0 :     m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification));
     300           0 : }
     301             : 
     302             : // --------------------- Dispatcher.
     303             : 
     304             : class DispatcherImpl : public protocol::DispatcherBase {
     305             : public:
     306        4573 :     DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fallThroughForNotFound)
     307             :         : DispatcherBase(frontendChannel)
     308             :         , m_backend(backend)
     309        9146 :         , m_fallThroughForNotFound(fallThroughForNotFound) {
     310       13719 :         m_dispatchMap["HeapProfiler.enable"] = &DispatcherImpl::enable;
     311       13719 :         m_dispatchMap["HeapProfiler.disable"] = &DispatcherImpl::disable;
     312       13719 :         m_dispatchMap["HeapProfiler.startTrackingHeapObjects"] = &DispatcherImpl::startTrackingHeapObjects;
     313       13719 :         m_dispatchMap["HeapProfiler.stopTrackingHeapObjects"] = &DispatcherImpl::stopTrackingHeapObjects;
     314       13719 :         m_dispatchMap["HeapProfiler.takeHeapSnapshot"] = &DispatcherImpl::takeHeapSnapshot;
     315       13719 :         m_dispatchMap["HeapProfiler.collectGarbage"] = &DispatcherImpl::collectGarbage;
     316       13719 :         m_dispatchMap["HeapProfiler.getObjectByHeapObjectId"] = &DispatcherImpl::getObjectByHeapObjectId;
     317       13719 :         m_dispatchMap["HeapProfiler.addInspectedHeapObject"] = &DispatcherImpl::addInspectedHeapObject;
     318       13719 :         m_dispatchMap["HeapProfiler.getHeapObjectId"] = &DispatcherImpl::getHeapObjectId;
     319       13719 :         m_dispatchMap["HeapProfiler.startSampling"] = &DispatcherImpl::startSampling;
     320       13719 :         m_dispatchMap["HeapProfiler.stopSampling"] = &DispatcherImpl::stopSampling;
     321        4573 :     }
     322       13719 :     ~DispatcherImpl() override { }
     323             :     DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
     324             : 
     325             : protected:
     326             :     using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
     327             :     using DispatchMap = protocol::HashMap<String, CallHandler>;
     328             :     DispatchMap m_dispatchMap;
     329             : 
     330             :     DispatchResponse::Status enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     331             :     DispatchResponse::Status disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     332             :     DispatchResponse::Status startTrackingHeapObjects(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     333             :     DispatchResponse::Status stopTrackingHeapObjects(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     334             :     DispatchResponse::Status takeHeapSnapshot(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     335             :     DispatchResponse::Status collectGarbage(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     336             :     DispatchResponse::Status getObjectByHeapObjectId(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     337             :     DispatchResponse::Status addInspectedHeapObject(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     338             :     DispatchResponse::Status getHeapObjectId(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     339             :     DispatchResponse::Status startSampling(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     340             :     DispatchResponse::Status stopSampling(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     341             : 
     342             :     Backend* m_backend;
     343             :     bool m_fallThroughForNotFound;
     344             : };
     345             : 
     346         402 : DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject)
     347             : {
     348             :     protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
     349         402 :     if (it == m_dispatchMap.end()) {
     350           0 :         if (m_fallThroughForNotFound)
     351             :             return DispatchResponse::kFallThrough;
     352           0 :         reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
     353           0 :         return DispatchResponse::kError;
     354             :     }
     355             : 
     356         402 :     protocol::ErrorSupport errors;
     357        1206 :     return (this->*(it->second))(callId, std::move(messageObject), &errors);
     358             : }
     359             : 
     360             : 
     361         132 : DispatchResponse::Status DispatcherImpl::enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     362             : {
     363             : 
     364         132 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     365         132 :     DispatchResponse response = m_backend->enable();
     366         132 :     if (weak->get())
     367         132 :         weak->get()->sendResponse(callId, response);
     368         264 :     return response.status();
     369             : }
     370             : 
     371         126 : DispatchResponse::Status DispatcherImpl::disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     372             : {
     373             : 
     374         126 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     375         126 :     DispatchResponse response = m_backend->disable();
     376         126 :     if (weak->get())
     377         126 :         weak->get()->sendResponse(callId, response);
     378         252 :     return response.status();
     379             : }
     380             : 
     381           0 : DispatchResponse::Status DispatcherImpl::startTrackingHeapObjects(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     382             : {
     383             :     // Prepare input parameters.
     384           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     385           0 :     errors->push();
     386           0 :     protocol::Value* trackAllocationsValue = object ? object->get("trackAllocations") : nullptr;
     387             :     Maybe<bool> in_trackAllocations;
     388           0 :     if (trackAllocationsValue) {
     389           0 :         errors->setName("trackAllocations");
     390           0 :         in_trackAllocations = ValueConversions<bool>::fromValue(trackAllocationsValue, errors);
     391             :     }
     392           0 :     errors->pop();
     393           0 :     if (errors->hasErrors()) {
     394           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     395           0 :         return DispatchResponse::kError;
     396             :     }
     397             : 
     398           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     399           0 :     DispatchResponse response = m_backend->startTrackingHeapObjects(std::move(in_trackAllocations));
     400           0 :     if (weak->get())
     401           0 :         weak->get()->sendResponse(callId, response);
     402           0 :     return response.status();
     403             : }
     404             : 
     405           0 : DispatchResponse::Status DispatcherImpl::stopTrackingHeapObjects(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     406             : {
     407             :     // Prepare input parameters.
     408           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     409           0 :     errors->push();
     410           0 :     protocol::Value* reportProgressValue = object ? object->get("reportProgress") : nullptr;
     411             :     Maybe<bool> in_reportProgress;
     412           0 :     if (reportProgressValue) {
     413           0 :         errors->setName("reportProgress");
     414           0 :         in_reportProgress = ValueConversions<bool>::fromValue(reportProgressValue, errors);
     415             :     }
     416           0 :     errors->pop();
     417           0 :     if (errors->hasErrors()) {
     418           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     419           0 :         return DispatchResponse::kError;
     420             :     }
     421             : 
     422           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     423           0 :     DispatchResponse response = m_backend->stopTrackingHeapObjects(std::move(in_reportProgress));
     424           0 :     if (weak->get())
     425           0 :         weak->get()->sendResponse(callId, response);
     426           0 :     return response.status();
     427             : }
     428             : 
     429          12 : DispatchResponse::Status DispatcherImpl::takeHeapSnapshot(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     430             : {
     431             :     // Prepare input parameters.
     432          36 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     433          12 :     errors->push();
     434          24 :     protocol::Value* reportProgressValue = object ? object->get("reportProgress") : nullptr;
     435             :     Maybe<bool> in_reportProgress;
     436          12 :     if (reportProgressValue) {
     437          24 :         errors->setName("reportProgress");
     438          12 :         in_reportProgress = ValueConversions<bool>::fromValue(reportProgressValue, errors);
     439             :     }
     440          12 :     errors->pop();
     441          12 :     if (errors->hasErrors()) {
     442           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     443           0 :         return DispatchResponse::kError;
     444             :     }
     445             : 
     446          12 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     447          24 :     DispatchResponse response = m_backend->takeHeapSnapshot(std::move(in_reportProgress));
     448          12 :     if (weak->get())
     449          12 :         weak->get()->sendResponse(callId, response);
     450          12 :     return response.status();
     451             : }
     452             : 
     453         132 : DispatchResponse::Status DispatcherImpl::collectGarbage(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     454             : {
     455             : 
     456         132 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     457         132 :     DispatchResponse response = m_backend->collectGarbage();
     458         132 :     if (weak->get())
     459         132 :         weak->get()->sendResponse(callId, response);
     460         264 :     return response.status();
     461             : }
     462             : 
     463           0 : DispatchResponse::Status DispatcherImpl::getObjectByHeapObjectId(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     464             : {
     465             :     // Prepare input parameters.
     466           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     467           0 :     errors->push();
     468           0 :     protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
     469           0 :     errors->setName("objectId");
     470           0 :     String in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
     471           0 :     protocol::Value* objectGroupValue = object ? object->get("objectGroup") : nullptr;
     472             :     Maybe<String> in_objectGroup;
     473           0 :     if (objectGroupValue) {
     474           0 :         errors->setName("objectGroup");
     475           0 :         in_objectGroup = ValueConversions<String>::fromValue(objectGroupValue, errors);
     476             :     }
     477           0 :     errors->pop();
     478           0 :     if (errors->hasErrors()) {
     479           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     480           0 :         return DispatchResponse::kError;
     481             :     }
     482             :     // Declare output parameters.
     483           0 :     std::unique_ptr<protocol::Runtime::RemoteObject> out_result;
     484             : 
     485           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     486           0 :     DispatchResponse response = m_backend->getObjectByHeapObjectId(in_objectId, std::move(in_objectGroup), &out_result);
     487           0 :     if (response.status() == DispatchResponse::kFallThrough)
     488             :         return response.status();
     489           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     490           0 :     if (response.status() == DispatchResponse::kSuccess) {
     491           0 :         result->setValue("result", ValueConversions<protocol::Runtime::RemoteObject>::toValue(out_result.get()));
     492             :     }
     493           0 :     if (weak->get())
     494           0 :         weak->get()->sendResponse(callId, response, std::move(result));
     495           0 :     return response.status();
     496             : }
     497             : 
     498           0 : DispatchResponse::Status DispatcherImpl::addInspectedHeapObject(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     499             : {
     500             :     // Prepare input parameters.
     501           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     502           0 :     errors->push();
     503           0 :     protocol::Value* heapObjectIdValue = object ? object->get("heapObjectId") : nullptr;
     504           0 :     errors->setName("heapObjectId");
     505           0 :     String in_heapObjectId = ValueConversions<String>::fromValue(heapObjectIdValue, errors);
     506           0 :     errors->pop();
     507           0 :     if (errors->hasErrors()) {
     508           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     509           0 :         return DispatchResponse::kError;
     510             :     }
     511             : 
     512           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     513           0 :     DispatchResponse response = m_backend->addInspectedHeapObject(in_heapObjectId);
     514           0 :     if (weak->get())
     515           0 :         weak->get()->sendResponse(callId, response);
     516           0 :     return response.status();
     517             : }
     518             : 
     519           0 : DispatchResponse::Status DispatcherImpl::getHeapObjectId(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     520             : {
     521             :     // Prepare input parameters.
     522           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     523           0 :     errors->push();
     524           0 :     protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
     525           0 :     errors->setName("objectId");
     526           0 :     String in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
     527           0 :     errors->pop();
     528           0 :     if (errors->hasErrors()) {
     529           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     530           0 :         return DispatchResponse::kError;
     531             :     }
     532             :     // Declare output parameters.
     533             :     String out_heapSnapshotObjectId;
     534             : 
     535           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     536           0 :     DispatchResponse response = m_backend->getHeapObjectId(in_objectId, &out_heapSnapshotObjectId);
     537           0 :     if (response.status() == DispatchResponse::kFallThrough)
     538             :         return response.status();
     539           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     540           0 :     if (response.status() == DispatchResponse::kSuccess) {
     541           0 :         result->setValue("heapSnapshotObjectId", ValueConversions<String>::toValue(out_heapSnapshotObjectId));
     542             :     }
     543           0 :     if (weak->get())
     544           0 :         weak->get()->sendResponse(callId, response, std::move(result));
     545           0 :     return response.status();
     546             : }
     547             : 
     548           0 : DispatchResponse::Status DispatcherImpl::startSampling(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     549             : {
     550             :     // Prepare input parameters.
     551           0 :     protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     552           0 :     errors->push();
     553           0 :     protocol::Value* samplingIntervalValue = object ? object->get("samplingInterval") : nullptr;
     554             :     Maybe<double> in_samplingInterval;
     555           0 :     if (samplingIntervalValue) {
     556           0 :         errors->setName("samplingInterval");
     557           0 :         in_samplingInterval = ValueConversions<double>::fromValue(samplingIntervalValue, errors);
     558             :     }
     559           0 :     errors->pop();
     560           0 :     if (errors->hasErrors()) {
     561           0 :         reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
     562           0 :         return DispatchResponse::kError;
     563             :     }
     564             : 
     565           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     566           0 :     DispatchResponse response = m_backend->startSampling(std::move(in_samplingInterval));
     567           0 :     if (weak->get())
     568           0 :         weak->get()->sendResponse(callId, response);
     569           0 :     return response.status();
     570             : }
     571             : 
     572           0 : DispatchResponse::Status DispatcherImpl::stopSampling(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     573             : {
     574             :     // Declare output parameters.
     575           0 :     std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile> out_profile;
     576             : 
     577           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     578           0 :     DispatchResponse response = m_backend->stopSampling(&out_profile);
     579           0 :     if (response.status() == DispatchResponse::kFallThrough)
     580             :         return response.status();
     581           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     582           0 :     if (response.status() == DispatchResponse::kSuccess) {
     583           0 :         result->setValue("profile", ValueConversions<protocol::HeapProfiler::SamplingHeapProfile>::toValue(out_profile.get()));
     584             :     }
     585           0 :     if (weak->get())
     586           0 :         weak->get()->sendResponse(callId, response, std::move(result));
     587           0 :     return response.status();
     588             : }
     589             : 
     590             : // static
     591        4573 : void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend)
     592             : {
     593       18292 :     dispatcher->registerBackend("HeapProfiler", std::unique_ptr<protocol::DispatcherBase>(new DispatcherImpl(dispatcher->channel(), backend, dispatcher->fallThroughForNotFound())));
     594        4573 : }
     595             : 
     596             : } // HeapProfiler
     597             : } // namespace v8_inspector
     598             : } // namespace protocol

Generated by: LCOV version 1.10