Пример #1
0
static Exception* generate_memory_exceeded_exception() {
  auto exceptionStack = createBacktrace(BacktraceArgs()
                                        .withSelf()
                                        .withThis());
  return new RequestMemoryExceededException(
    "request has exceeded memory limit", exceptionStack);
}
Пример #2
0
void XenonRequestLocalData::log(Xenon::SampleType t,
                                const char* info,
                                c_WaitableWaitHandle* wh) {
  if (!m_inRequest) return;

  TRACE(1, "XenonRequestLocalData::log\n");
  time_t now = time(nullptr);
  auto bt = createBacktrace(BacktraceArgs()
                             .skipTop(t == Xenon::EnterSample)
                             .skipInlined(t == Xenon::EnterSample)
                             .fromWaitHandle(wh)
                             .withMetadata()
                             .ignoreArgs());
  auto logDest = RuntimeOption::XenonStructLogDest;
  if (!logDest.empty()) {
    StructuredLogEntry cols;
    cols.setStr("type", Xenon::show(t));
    if (info) {
      cols.setStr("info", info);
    }
    addBacktraceToStructLog(bt, cols);
    StructuredLog::log(logDest, cols);
  } else {
    m_stackSnapshots.append(make_darray(
      s_time, now,
      s_stack, bt,
      s_isWait, !Xenon::isCPUTime(t),
      s_type, Xenon::show(t),
      s_info, info ? info : ""
    ));
  }
}
Пример #3
0
static Exception* generate_memory_exceeded_exception(c_WaitableWaitHandle* wh) {
  auto exceptionStack = createBacktrace(BacktraceArgs()
                                        .fromWaitHandle(wh)
                                        .withSelf()
                                        .withThis());
  return new RequestMemoryExceededException(
    "request has exceeded memory limit", exceptionStack);
}
Пример #4
0
Array HHVM_FUNCTION(debug_backtrace, int64_t options /* = 1 */,
                                     int64_t limit /* = 0 */) {
  bool provide_object = options & k_DEBUG_BACKTRACE_PROVIDE_OBJECT;
  bool ignore_args = options & k_DEBUG_BACKTRACE_IGNORE_ARGS;
  return createBacktrace(BacktraceArgs()
                         .withThis(provide_object)
                         .ignoreArgs(ignore_args)
                         .setLimit(limit));
}
Пример #5
0
static Array HHVM_FUNCTION(xdebug_get_function_stack) {
  // Need to reverse the backtrace to match php5 xdebug.
  auto bt = createBacktrace(BacktraceArgs()
                            .skipTop()
                            .withPseudoMain()
                            .withArgNames()
                            .withArgValues(XDebugExtension::CollectParams));
  return ArrayUtil::Reverse(bt).toArray();
}
Пример #6
0
bool CmdWhere::onServer(DebuggerProxy &proxy) {
  if (m_type == KindOfWhereAsync) {
    m_stacktrace = createAsyncStacktrace();
  } else {
    m_stacktrace = createBacktrace(BacktraceArgs()
                                   .withSelf()
                                   .ignoreArgs(!m_stackArgs));
  }
  return proxy.sendToClient(this);
}
Пример #7
0
static Exception* generate_request_timeout_exception() {
  auto exceptionMsg = folly::sformat(
    RuntimeOption::ClientExecutionMode()
      ? "Maximum execution time of {} seconds exceeded"
      : "entire web request took longer than {} seconds and timed out",
    RID().getTimeout());
  auto exceptionStack = createBacktrace(BacktraceArgs()
                                        .withSelf()
                                        .withThis());
  return new RequestTimeoutException(exceptionMsg, exceptionStack);
}
Пример #8
0
static Exception* generate_request_cpu_timeout_exception() {
  auto exceptionMsg = folly::sformat(
    "Maximum CPU time of {} seconds exceeded",
    RID().getCPUTimeout()
  );

  auto exceptionStack = createBacktrace(BacktraceArgs()
                                        .withSelf()
                                        .withThis());
  return new RequestCPUTimeoutException(exceptionMsg, exceptionStack);
}
Пример #9
0
void ExtendedLogger::log(LogLevelType level, const std::string &msg,
                         const StackTrace *stackTrace,
                         bool escape /* = true */,
                         bool escapeMore /* = false */) {
  Array bt = createBacktrace(BacktraceArgs());
  if (!bt.empty()) {
    Logger::log(level, msg, stackTrace, escape, escape);
    Log(level, bt, escape, escapeMore);
    return;
  }
  Logger::log(level, msg, stackTrace, escape, escapeMore);
}
Пример #10
0
static Exception* generate_request_cpu_timeout_exception() {
  auto info = ThreadInfo::s_threadInfo.getNoCheck();
  auto& data = info->m_reqInjectionData;

  auto exceptionMsg =
    folly::sformat("Maximum CPU time of {} seconds exceeded",
                   data.getCPUTimeout());
  auto exceptionStack = createBacktrace(BacktraceArgs()
                                        .withSelf()
                                        .withThis());
  return new RequestCPUTimeoutException(exceptionMsg, exceptionStack);
}
Пример #11
0
static Exception* generate_request_timeout_exception(c_WaitableWaitHandle* wh) {
  auto exceptionMsg = folly::sformat(
    !RuntimeOption::ServerExecutionMode() || is_cli_mode()
      ? "Maximum execution time of {} seconds exceeded"
      : "entire web request took longer than {} seconds and timed out",
    RID().getTimeout());
  auto exceptionStack = createBacktrace(BacktraceArgs()
                                        .fromWaitHandle(wh)
                                        .withSelf()
                                        .withThis()
                                        .withMetadata());
  return new RequestTimeoutException(exceptionMsg, exceptionStack);
}
Пример #12
0
String debug_string_backtrace(bool skip, bool ignore_args /* = false */,
                              int64_t limit /* = 0 */) {
  Array bt;
  StringBuffer buf;
  bt = createBacktrace(BacktraceArgs()
                       .skipTop(skip)
                       .ignoreArgs(ignore_args)
                       .setLimit(limit));
  int i = 0;
  for (ArrayIter it = bt.begin(); !it.end(); it.next(), i++) {
    Array frame = it.second().toArray();
    buf.append('#');
    buf.append(i);
    if (i < 10) buf.append(' ');
    buf.append(' ');
    if (frame.exists(s_class)) {
      buf.append(frame->get(s_class).toString());
      buf.append(frame->get(s_type).toString());
    }
    buf.append(frame->get(s_function).toString());
    buf.append("(");
    if (!ignore_args) {
      bool first = true;
      for (ArrayIter it(frame->get(s_args).toArray());
          !it.end();
          it.next()) {
        if (!first) {
          buf.append(", ");
        } else {
          first = false;
        }
        try {
          buf.append(it.second().toString());
        } catch (FatalErrorException& fe) {
          buf.append(fe.getMessage());
        }
      }
    }
    buf.append(")");
    if (frame.exists(s_file)) {
      buf.append(" called at [");
      buf.append(frame->get(s_file).toString());
      buf.append(':');
      buf.append(frame->get(s_line).toString());
      buf.append(']');
    }
    buf.append('\n');
  }
  return buf.detach();
}
Пример #13
0
void XenonRequestLocalData::log(Xenon::SampleType t, c_WaitableWaitHandle* wh) {
  TRACE(1, "XenonRequestLocalData::log\n");
  time_t now = time(nullptr);
  auto bt = createBacktrace(BacktraceArgs()
                             .skipTop(t == Xenon::EnterSample)
                             .fromWaitHandle(wh)
                             .withMetadata()
                             .ignoreArgs());
  m_stackSnapshots.append(make_map_array(
    s_time, now,
    s_stack, bt,
    s_isWait, (t == Xenon::IOWaitSample)
  ));
}
Пример #14
0
static Exception* generate_request_timeout_exception() {
  auto info = ThreadInfo::s_threadInfo.getNoCheck();
  auto& data = info->m_reqInjectionData;

  auto exceptionMsg = folly::sformat(
    RuntimeOption::ClientExecutionMode()
      ? "Maximum execution time of {} seconds exceeded"
      : "entire web request took longer than {} seconds and timed out",
    data.getTimeout());
  auto exceptionStack = createBacktrace(BacktraceArgs()
                                        .withSelf()
                                        .withThis());
  return new RequestTimeoutException(exceptionMsg, exceptionStack);
}
Пример #15
0
void XenonRequestLocalData::log(Xenon::SampleType t) {
  TRACE(1, "XenonRequestLocalData::log\n");
  time_t now = time(nullptr);
  Array snapshot;
  snapshot.set(s_time, now, true);
  bool skipFirst = (t == Xenon::EnterSample) ? true : false;
  Array bt = createBacktrace(BacktraceArgs()
                             .skipTop(skipFirst)
                             .withSelf()
                             .ignoreArgs());
  snapshot.set(s_phpStack, bt, true);
  snapshot.set(s_asyncStack, logAsyncStack(), true);
  snapshot.set(s_isWait, (t == Xenon::IOWaitSample));
  m_stackSnapshots.append(snapshot);
}
Пример #16
0
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");
}
Пример #17
0
void ExtendedException::computeBacktrace(bool skipFrame /* = false */) {
  Array bt = createBacktrace(BacktraceArgs()
                          .skipTop(skipFrame)
                          .withSelf());
  m_btp = bt.get();
}