示例#1
0
Array stackTraceToBackTrace(const StackTrace& st) {
  std::vector<void*> bt_pointers;
  st.get(bt_pointers);
  Array ret;
  if (RuntimeOption::FullBacktrace) {
    for (unsigned int i = 0; i < bt_pointers.size(); i++) {
      StackTrace::FramePtr f = StackTrace::Translate(bt_pointers[i]);
      if (RuntimeOption::TranslateSource) {
        SourceInfo::TheSourceInfo.translate(f);
      }
      Array frame;
      frame.set("file",     String(f->filename));
      frame.set("line",     f->lineno);
      frame.set("function", String(f->funcname));
      frame.set("args",     "");
      frame.set("bt",       (int64)bt_pointers[i]);
      ret.append(frame);
    }
  } else {
    for (unsigned int i = 0; i < bt_pointers.size(); i++) {
      Array frame;
      frame.set("file",     "");
      frame.set("line",     0LL);
      frame.set("function", "");
      frame.set("args",     "");
      frame.set("bt",       (int64)bt_pointers[i]);
      ret.append(frame);
    }
    ret.set("bts", String(st.hexEncode()));
  }
  return ret;
}
示例#2
0
LockProfiler::~LockProfiler() {
  if (m_profiling) {
    timespec unlockTime;
    Timer::GetMonotonicTime(unlockTime);
    time_t dsec = unlockTime.tv_sec - m_lockTime.tv_sec;
    long dnsec = unlockTime.tv_nsec - m_lockTime.tv_nsec;
    int64_t dusec = dsec * 1000000 + dnsec / 1000;

    StackTrace st;
    s_pfunc_profile(st.hexEncode(3, 9), dusec);
  }
}
示例#3
0
void SimpleCounter::Count(const string &name) {
  if (Enabled) {
    int count = ++s_counter->m_counters[name];
    if (SampleStackCount > 0) {
      assert(StackTrace::Enabled);
      vector<string> &stackVec = s_counter->m_stacks[name];
      if ((int)stackVec.size() < SampleStackCount ||
          f_rand(0, count - 1) < SampleStackCount) {
        StackTrace st;
        if ((int)stackVec.size() < SampleStackCount) {
          // skip StackTrace methods and the Count() call.
          stackVec.push_back(st.hexEncode(3, 3 + SampleStackDepth));
        } else {
          // skip StackTrace methods and the Count() call.
          stackVec[f_rand(0, SampleStackCount - 1)] =
            st.hexEncode(3, 3 + SampleStackDepth);
        }
      }
    }
  }
}
示例#4
0
LockProfiler::~LockProfiler() {
  if (m_profiling) {
#if defined(__APPLE__)
    timeval unlockTime;
    unlockTime.tv_sec = 0;
    unlockTime.tv_usec = 0;
    gettimeofday(&unlockTime, NULL);
    time_t dsec = unlockTime.tv_sec - m_lockTime.tv_sec;
    long dnsec = unlockTime.tv_usec - m_lockTime.tv_usec;
    int64 dusec = dsec * 1000000 + dnsec;
#else
    timespec unlockTime;
    unlockTime.tv_sec = 0;
    unlockTime.tv_nsec = 0;
    clock_gettime(CLOCK_MONOTONIC, &unlockTime);
    time_t dsec = unlockTime.tv_sec - m_lockTime.tv_sec;
    long dnsec = unlockTime.tv_nsec - m_lockTime.tv_nsec;
    int64 dusec = dsec * 1000000 + dnsec / 1000;
#endif

    StackTrace st;
    s_pfunc_profile(st.hexEncode(3, 9), dusec);
  }
}