RefPtr<Inspector::Protocol::Network::Initiator> InspectorNetworkAgent::buildInitiatorObject(Document* document) { RefPtr<ScriptCallStack> stackTrace = createScriptCallStack(JSMainThreadExecState::currentState(), ScriptCallStack::maxCallStackSizeToCapture); if (stackTrace && stackTrace->size() > 0) { auto initiatorObject = Inspector::Protocol::Network::Initiator::create() .setType(Inspector::Protocol::Network::Initiator::Type::Script) .release(); initiatorObject->setStackTrace(stackTrace->buildInspectorArray()); return WTFMove(initiatorObject); } if (document && document->scriptableDocumentParser()) { auto initiatorObject = Inspector::Protocol::Network::Initiator::create() .setType(Inspector::Protocol::Network::Initiator::Type::Parser) .release(); initiatorObject->setUrl(document->url().string()); initiatorObject->setLineNumber(document->scriptableDocumentParser()->textPosition().m_line.oneBasedInt()); return WTFMove(initiatorObject); } if (m_isRecalculatingStyle && m_styleRecalculationInitiator) return m_styleRecalculationInitiator; return Inspector::Protocol::Network::Initiator::create() .setType(Inspector::Protocol::Network::Initiator::Type::Other) .release(); }
void HttpServer::runOrExitProcess() { if (StaticContentCache::TheFileCache && StructuredLog::enabled() && StructuredLog::coinflip(RuntimeOption::EvalStaticContentsLogRate)) { CacheManager::setLogger([](bool existsCheck, const std::string& name) { auto record = StructuredLogEntry{}; record.setInt("existsCheck", existsCheck); record.setStr("file", name); bool needsCppStack = true; if (!g_context.isNull()) { VMRegAnchor _; if (vmfp()) { auto const bt = createBacktrace(BacktraceArgs().withArgValues(false)); std::vector<std::string> frameStrings; std::vector<folly::StringPiece> frames; for (int i = 0; i < bt.size(); i++) { auto f = bt.rvalAt(i).toArray(); if (f.exists(s_file)) { std::string s = f.rvalAt(s_file).toString().toCppString(); if (f.exists(s_line)) { s += folly::sformat(":{}", f.rvalAt(s_line).toInt64()); } frameStrings.emplace_back(std::move(s)); frames.push_back(frameStrings.back()); } } record.setVec("stack", frames); needsCppStack = false; } } if (needsCppStack) { record.setStackTrace("stack", StackTrace{StackTrace::Force{}}); } StructuredLog::log("hhvm_file_cache", record); }); } auto startupFailure = [] (const std::string& msg) { Logger::Error(msg); Logger::Error("Shutting down due to failure(s) to bind in " "HttpServer::runAndExitProcess"); // Logger flushes itself---we don't need to run any atexit handlers // (historically we've mostly just SEGV'd while trying) ... _Exit(1); }; if (!RuntimeOption::InstanceId.empty()) { std::string msg = "Starting instance " + RuntimeOption::InstanceId; if (!RuntimeOption::DeploymentId.empty()) { msg += " from deployment " + RuntimeOption::DeploymentId; } Logger::Info(msg); } m_watchDog.start(); if (RuntimeOption::ServerPort) { if (!startServer(true)) { startupFailure("Unable to start page server"); not_reached(); } Logger::Info("page server started"); } StartTime = time(nullptr); if (RuntimeOption::AdminServerPort) { if (!startServer(false)) { startupFailure("Unable to start admin server"); not_reached(); } Logger::Info("admin server started"); } for (unsigned int i = 0; i < m_satellites.size(); i++) { std::string name = m_satellites[i]->getName(); try { m_satellites[i]->start(); Logger::Info("satellite server %s started", name.c_str()); } catch (Exception &e) { startupFailure( folly::format("Unable to start satellite server {}: {}", name, e.getMessage()).str() ); not_reached(); } } if (!Eval::Debugger::StartServer()) { startupFailure("Unable to start debugger server"); not_reached(); } else if (RuntimeOption::EnableDebuggerServer) { Logger::Info("debugger server started"); } try { InitFiniNode::ServerInit(); } catch (std::exception &e) { startupFailure( folly::sformat("Exception in InitFiniNode::ServerInit(): {}", e.what())); } { BootStats::mark("servers started"); Logger::Info("all servers started"); createPid(); Lock lock(this); BootStats::done(); // continously running until /stop is received on admin server, or // takeover is requested. while (!m_stopped) { wait(); } if (m_stopReason) { Logger::Warning("Server stopping with reason: %s\n", m_stopReason); } // if we were killed, bail out immediately if (m_killed) { Logger::Info("page server killed"); return; } } if (RuntimeOption::ServerPort) { Logger::Info("stopping page server"); m_pageServer->stop(); } onServerShutdown(); EvictFileCache(); waitForServers(); m_watchDog.waitForEnd(); playShutdownRequest(RuntimeOption::ServerCleanupRequest); hphp_process_exit(); Logger::Info("all servers stopped"); }