当前位置: 首页>>代码示例>>C++>>正文


C++ TraceData类代码示例

本文整理汇总了C++中TraceData的典型用法代码示例。如果您正苦于以下问题:C++ TraceData类的具体用法?C++ TraceData怎么用?C++ TraceData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TraceData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: update

void CostListItem::update()
{
  if (!_costItem) return;
  TraceData* d = _costItem->data();

  double total = d->subCost(_eventType);
  if (total == 0.0) {
    setText(0, QString("---"));
    setIcon(0, QPixmap());
    return;
  }

  _pure = _costItem->subCost(_eventType);
  double pure  = 100.0 * _pure / total;
  QString str;
  if (GlobalConfig::showPercentage())
    str = QString("%1").arg(pure, 0, 'f', GlobalConfig::percentPrecision());
  else
    str = _costItem->prettySubCost(_eventType);

  if (_skipped) {
    // special handling for skip entries...
    setText(0, QString("< %1").arg(str));
    return;
  }

  setText(0, str);
  setIcon(0, costPixmap(_eventType, _costItem, total, false));
}
开发者ID:ShermanHuang,项目名称:kdesdk,代码行数:29,代码来源:costlistitem.cpp

示例2: nowNs

MicroProfilerSection::~MicroProfilerSection() {
  if (!isProfiling_ || !profiling.isProfiling_) {
    return;
  }
  auto endTime = nowNs();
  auto endNumProfileSections = profileSections;
  myTraceData.addTime(name_, endTime - startTime_, endNumProfileSections - startNumProfileSections_ - 1);
}
开发者ID:39otrebla,项目名称:react-native,代码行数:8,代码来源:MicroProfiler.cpp

示例3: update

void EventTypeItem::update()
{
    TraceData* d = _costItem ? _costItem->data() : 0;
    double total = d ? ((double)d->subCost(_eventType)) : 0.0;

    if (total == 0.0) {
        setText(1, "-");
        setIcon(1, QIcon());
        setText(2, "-");
        setIcon(2, QIcon());
        return;
    }

    TraceFunction* f = (_costItem && _costItem->type()==ProfileContext::Function) ?
                       (TraceFunction*)_costItem : 0;

    ProfileCostArray* selfTotalCost = f ? f->data() : d;
    if (f && GlobalConfig::showExpanded()) {
        ProfileCostArray* parent = 0;
        switch(_groupType) {
        case ProfileContext::Object:
            parent = f->object();
            break;
        case ProfileContext::Class:
            parent = f->cls();
            break;
        case ProfileContext::File:
            parent = f->file();
            break;
        case ProfileContext::FunctionCycle:
            parent = f->cycle();
            break;
        default:
            break;
        }
        if (parent) selfTotalCost = parent;
    }
    if (_costItem && _costItem->type()==ProfileContext::FunctionCycle) {
        f = (TraceFunction*)_costItem;
        selfTotalCost = f->data();
    }

    double selfTotal = selfTotalCost->subCost(_eventType);

    // for all cost items there is a self cost
    _pure = _costItem ? _costItem->subCost(_eventType) : SubCost(0);
    double pure  = 100.0 * _pure / selfTotal;
    if (GlobalConfig::showPercentage()) {
        setText(2, QString("%1")
                .arg(pure, 0, 'f', GlobalConfig::percentPrecision()));
    }
    else if (_costItem)
        setText(2, _costItem->prettySubCost(_eventType));

    setIcon(2, QIcon(costPixmap(_eventType, _costItem, selfTotal, false)));

    if (!f) {
        setText(1, "-");
        setIcon(1, QIcon());
        return;
    }

    _sum = f->inclusive()->subCost(_eventType);
    double sum  = 100.0 * _sum / total;
    if (GlobalConfig::showPercentage()) {
        setText(1, QString("%1")
                .arg(sum, 0, 'f', GlobalConfig::percentPrecision()));
    }
    else
        setText(1, _sum.pretty());

    setIcon(1, QIcon(costPixmap(_eventType, f->inclusive(), total, false)));
}
开发者ID:Zekom,项目名称:kcachegrind,代码行数:73,代码来源:eventtypeitem.cpp

示例4: TraceData

namespace react {

#if !MICRO_PROFILER_STUB_IMPLEMENTATION
struct TraceData {
  TraceData();
  ~TraceData();

  void addTime(MicroProfilerName name, uint_fast64_t time, uint_fast32_t internalClockCalls);

  std::thread::id threadId_;
  uint_fast64_t startTime_;
  std::atomic_uint_fast64_t times_[MicroProfilerName::__LENGTH__] = {};
  std::atomic_uint_fast32_t calls_[MicroProfilerName::__LENGTH__] = {};
  std::atomic_uint_fast32_t childProfileSections_[MicroProfilerName::__LENGTH__] = {};
};

struct ProfilingImpl {
  std::mutex mutex_;
  std::vector<TraceData*> allTraceData_;
  bool isProfiling_ = false;
  uint_fast64_t startTime_;
  uint_fast64_t endTime_;
  uint_fast64_t clockOverhead_;
  uint_fast64_t profileSectionOverhead_;
};

static ProfilingImpl profiling;
thread_local TraceData myTraceData;
thread_local uint_fast32_t profileSections = 0;

static uint_fast64_t nowNs() {
  struct timespec time;
  clock_gettime(CLOCK_REALTIME, &time);
  return uint_fast64_t(1000000000) * time.tv_sec + time.tv_nsec;
}

static uint_fast64_t diffNs(uint_fast64_t start, uint_fast64_t end) {
  return end - start;
}

static std::string formatTimeNs(uint_fast64_t timeNs) {
  std::ostringstream out;
  out.precision(2);
  if (timeNs < 1000) {
    out << timeNs << "ns";
  } else if (timeNs < 1000000) {
    out << timeNs / 1000.0 << "us";
  } else {
    out << std::fixed << timeNs / 1000000.0 << "ms";
  }
  return out.str();
}

MicroProfilerSection::MicroProfilerSection(MicroProfilerName name) :
    isProfiling_(profiling.isProfiling_),
    name_(name),
    startNumProfileSections_(profileSections) {
  if (!isProfiling_) {
    return;
  }
  profileSections++;
  startTime_ = nowNs();
}
MicroProfilerSection::~MicroProfilerSection() {
  if (!isProfiling_ || !profiling.isProfiling_) {
    return;
  }
  auto endTime = nowNs();
  auto endNumProfileSections = profileSections;
  myTraceData.addTime(name_, endTime - startTime_, endNumProfileSections - startNumProfileSections_ - 1);
}

TraceData::TraceData() :
    threadId_(std::this_thread::get_id()) {
  std::lock_guard<std::mutex> lock(profiling.mutex_);
  profiling.allTraceData_.push_back(this);
}

TraceData::~TraceData() {
  std::lock_guard<std::mutex> lock(profiling.mutex_);
  auto& infos = profiling.allTraceData_;
  infos.erase(std::remove(infos.begin(), infos.end(), this), infos.end());
}

void TraceData::addTime(MicroProfilerName name, uint_fast64_t time, uint_fast32_t childprofileSections) {
  times_[name] += time;
  calls_[name]++;
  childProfileSections_[name] += childprofileSections;
}

static void printReport() {
  LOG(ERROR) << "======= MICRO PROFILER REPORT =======";
  LOG(ERROR) << "- Total Time: " << formatTimeNs(diffNs(profiling.startTime_, profiling.endTime_));
  LOG(ERROR) << "- Clock Overhead: " << formatTimeNs(profiling.clockOverhead_);
  LOG(ERROR) << "- Profiler Section Overhead: " << formatTimeNs(profiling.profileSectionOverhead_);
  for (auto info : profiling.allTraceData_) {
    LOG(ERROR) << "--- Thread ID 0x" << std::hex << info->threadId_ << " ---";
    for (int i = 0; i < MicroProfilerName::__LENGTH__; i++) {
      if (info->times_[i] > 0) {
        auto totalTime = info->times_[i].load();
//.........这里部分代码省略.........
开发者ID:39otrebla,项目名称:react-native,代码行数:101,代码来源:MicroProfiler.cpp

示例5: loadStart

/**
 * The main import function...
 */
int CachegrindLoader::loadInternal(TraceData* data,
                                   QIODevice* device, const QString& filename)
{
    if (!data || !device) return 0;

    _data = data;
    _filename = filename;
    _lineNo = 0;

    loadStart(_filename);

    FixFile file(device, _filename);
    if (!file.exists()) {
        loadFinished(QStringLiteral("File does not exist"));
        return 0;
    }

    int statusProgress = 0;

#if USE_FIXCOST
    // FixCost Memory Pool
    FixPool* pool = _data->fixPool();
#endif

    _part = 0;
    partsAdded = 0;
    prepareNewPart();

    FixString line;
    char c;

    // current position
    nextLineType  = SelfCost;
    // default if there is no "positions:" line
    hasLineInfo = true;
    hasAddrInfo = false;

    while (file.nextLine(line)) {

        _lineNo++;

#if TRACE_LOADER
        qDebug() << "[CachegrindLoader] " << _filename << ":" << _lineNo
                 << " - '" << QString(line) << "'";
#endif

        // if we cannot strip a character, this was an empty line
        if (!line.first(c)) continue;

        if (c <= '9') {

            if (c == '#') continue;

            // parse position(s)
            if (!parsePosition(line, currentPos)) {
                error(QStringLiteral("Invalid position specification '%1'").arg(line));
                continue;
            }

            // go through after big switch
        }
        else { // if (c > '9')

            line.stripFirst(c);

            /* in order of probability */
            switch(c) {

            case 'f':

                // fl=
                if (line.stripPrefix("l=")) {

                    setFile(line);
                    // this is the default for new functions
                    currentFunctionFile = currentFile;
                    continue;
                }

                // fi=, fe=
                if (line.stripPrefix("i=") ||
                    line.stripPrefix("e=")) {

                    setFile(line);
                    continue;
                }

                // fn=
                if (line.stripPrefix("n=")) {

                    if (currentFile != currentFunctionFile)
                        currentFile = currentFunctionFile;
                    setFunction(line);

                    // on a new function, update status
                    int progress = (int)(100.0 * file.current() / file.len() +.5);
                    if (progress != statusProgress) {
//.........这里部分代码省略.........
开发者ID:KDE,项目名称:kcachegrind,代码行数:101,代码来源:cachegrindloader.cpp

示例6: update

void CostTypeItem::update()
{
  TraceData* d = _costItem ? _costItem->data() : 0;
  double total = d ? ((double)d->subCost(_costType)) : 0.0;

  if (total == 0.0) {
    setText(1, "-");
    setPixmap(1, QPixmap());
    setText(2, "-");
    setPixmap(2, QPixmap());
    return;
  }

  TraceFunction* f = (_costItem->type()==TraceCost::Function) ?
                     (TraceFunction*)_costItem : 0;

  TraceCost* selfTotalCost = f ? f->data() : d;
  if (f && Configuration::showExpanded()) {
      switch(_groupType) {
      case TraceCost::Object: selfTotalCost = f->object(); break;
      case TraceCost::Class:  selfTotalCost = f->cls(); break;
      case TraceCost::File:   selfTotalCost = f->file(); break;
      case TraceCost::FunctionCycle: selfTotalCost = f->cycle(); break;
      default: break;
      }
  }
  if (_costItem->type()==TraceCost::FunctionCycle) {
      f = (TraceFunction*)_costItem;
      selfTotalCost = f->data();
  }

  double selfTotal = selfTotalCost->subCost(_costType);

  // for all cost items there's a self cost
  _pure = _costItem ? _costItem->subCost(_costType) : SubCost(0);
  double pure  = 100.0 * _pure / selfTotal;
  if (Configuration::showPercentage()) {
    setText(2, QString("%1")
            .arg(pure, 0, 'f', Configuration::percentPrecision()));
  }
  else
    setText(2, _costItem->prettySubCost(_costType));

  setPixmap(2, costPixmap(_costType, _costItem, selfTotal, false));

  if (!f) {
    setText(1, "-");
    setPixmap(1, QPixmap());
    return;
  }

  _sum = f->inclusive()->subCost(_costType);
  double sum  = 100.0 * _sum / total;
  if (Configuration::showPercentage()) {
    setText(1, QString("%1")
            .arg(sum, 0, 'f', Configuration::percentPrecision()));
  }
  else
    setText(1, _sum.pretty());

  setPixmap(1, costPixmap(_costType, f->inclusive(), total, false));
}
开发者ID:serghei,项目名称:kde-kdesdk,代码行数:62,代码来源:costtypeitem.cpp

示例7: ensureFile

// make sure that a valid file is set, at least dummy with empty name
void CachegrindLoader::ensureFile()
{
    if (currentFile) return;

    currentFile = _data->file(_emptyString);
    currentPartFile = currentFile->partFile(_part);
}
开发者ID:KDE,项目名称:kcachegrind,代码行数:8,代码来源:cachegrindloader.cpp

示例8: setFunction

void CachegrindLoader::setFunction(const QString& name)
{
    ensureFile();
    ensureObject();

    currentFunction = compressedFunction( name,
                                          currentFile,
                                          currentObject);

    if (!currentFunction) {
        error(QStringLiteral("Invalid function specification, setting to unknown"));

        currentFunction = _data->function(_emptyString,
                                          currentFile,
                                          currentObject);
    }

    currentPartFunction = currentFunction->partFunction(_part,
                                                        currentPartFile,
                                                        currentPartObject);

    currentFunctionSource = 0;
    currentLine = 0;
    currentPartLine = 0;
}
开发者ID:KDE,项目名称:kcachegrind,代码行数:25,代码来源:cachegrindloader.cpp

示例9: setCalledFunction

void CachegrindLoader::setCalledFunction(const QString& name)
{
    // if called object/file not set, use current object/file
    if (!currentCalledObject) {
        currentCalledObject = currentObject;
        currentCalledPartObject = currentPartObject;
    }

    if (!currentCalledFile) {
        // !=0 as functions needs file
        currentCalledFile = currentFile;
        currentCalledPartFile = currentPartFile;
    }

    currentCalledFunction = compressedFunction(name,
                                               currentCalledFile,
                                               currentCalledObject);
    if (!currentCalledFunction) {
        error(QStringLiteral("Invalid called function, setting to unknown"));

        currentCalledFunction = _data->function(_emptyString,
                                                currentCalledFile,
                                                currentCalledObject);
    }

    currentCalledPartFunction =
            currentCalledFunction->partFunction(_part,
                                                currentCalledPartFile,
                                                currentCalledPartObject);
}
开发者ID:KDE,项目名称:kcachegrind,代码行数:30,代码来源:cachegrindloader.cpp

示例10: ensureObject

// make sure that a valid object is set, at least dummy with empty name
void CachegrindLoader::ensureObject()
{
    if (currentObject) return;

    currentObject = _data->object(_emptyString);
    currentPartObject = currentObject->partObject(_part);
}
开发者ID:KDE,项目名称:kcachegrind,代码行数:8,代码来源:cachegrindloader.cpp

示例11: compressedFile

// Note: Callgrind sometimes gives different IDs for same file
// (when references to same source file come from different ELF objects)
TraceFile* CachegrindLoader::compressedFile(const QString& name)
{
    if ((name[0] != '(') || !name[1].isDigit()) return _data->file(checkUnknown(name));

    // compressed format using _fileVector
    int p = name.indexOf(')');
    if (p<2) {
        error(QStringLiteral("Invalid compressed file ('%1')").arg(name));
        return 0;
    }
    int index = name.midRef(1, p-1).toUInt();
    TraceFile* f = 0;
    p++;
    while((name.length()>p) && name.at(p).isSpace()) p++;
    if (name.length()>p) {
        if (_fileVector.size() <= index) {
            int newSize = index * 2;
#if TRACE_LOADER
            qDebug() << " CachegrindLoader::fileVector enlarged to "
                     << newSize;
#endif
            _fileVector.resize(newSize);
        }

        QString realName = checkUnknown(name.mid(p));
        f = (TraceFile*) _fileVector.at(index);
        if (f && (f->name() != realName)) {
            error(QStringLiteral("Redefinition of compressed file index %1 (was '%2') to %3")
                  .arg(index).arg(f->name()).arg(realName));
        }

        f = _data->file(realName);
        _fileVector.replace(index, f);
    }
    else {
        if ((_fileVector.size() <= index) ||
            ( (f=(TraceFile*)_fileVector.at(index)) == 0)) {
            error(QStringLiteral("Undefined compressed file index %1").arg(index));
            return 0;
        }
    }

    return f;
}
开发者ID:KDE,项目名称:kcachegrind,代码行数:46,代码来源:cachegrindloader.cpp

示例12: compressedObject

TraceObject* CachegrindLoader::compressedObject(const QString& name)
{
    if ((name[0] != '(') || !name[1].isDigit()) return _data->object(checkUnknown(name));

    // compressed format using _objectVector
    int p = name.indexOf(')');
    if (p<2) {
        error(QStringLiteral("Invalid compressed ELF object ('%1')").arg(name));
        return 0;
    }
    int index = name.midRef(1, p-1).toInt();
    TraceObject* o = 0;
    p++;
    while((name.length()>p) && name.at(p).isSpace()) p++;
    if (name.length()>p) {
        if (_objectVector.size() <= index) {
            int newSize = index * 2;
#if TRACE_LOADER
            qDebug() << " CachegrindLoader: objectVector enlarged to "
                     << newSize;
#endif
            _objectVector.resize(newSize);
        }

        QString realName = checkUnknown(name.mid(p));
        o = (TraceObject*) _objectVector.at(index);
        if (o && (o->name() != realName)) {
            error(QStringLiteral("Redefinition of compressed ELF object index %1 (was '%2') to %3")
                  .arg(index).arg(o->name()).arg(realName));
        }

        o = _data->object(realName);
        _objectVector.replace(index, o);
    }
    else {
        if ((_objectVector.size() <= index) ||
            ( (o=(TraceObject*)_objectVector.at(index)) == 0)) {
            error(QStringLiteral("Undefined compressed ELF object index %1").arg(index));
            return 0;
        }
    }

    return o;
}
开发者ID:KDE,项目名称:kcachegrind,代码行数:44,代码来源:cachegrindloader.cpp

示例13: setCalledObject

void CachegrindLoader::setCalledObject(const QString& name)
{
    currentCalledObject = compressedObject(name);

    if (!currentCalledObject) {
        error(QStringLiteral("Invalid specification of called ELF object, setting to unknown"));

        currentCalledObject = _data->object(_emptyString);
    }

    currentCalledPartObject = currentCalledObject->partObject(_part);
}
开发者ID:KDE,项目名称:kcachegrind,代码行数:12,代码来源:cachegrindloader.cpp

示例14: setCalledFile

void CachegrindLoader::setCalledFile(const QString& name)
{
    currentCalledFile = compressedFile(name);

    if (!currentCalledFile) {
        error(QStringLiteral("Invalid specification of called file, setting to unknown"));

        currentCalledFile = _data->file(_emptyString);
    }

    currentCalledPartFile = currentCalledFile->partFile(_part);
}
开发者ID:KDE,项目名称:kcachegrind,代码行数:12,代码来源:cachegrindloader.cpp

示例15: setObject

void CachegrindLoader::setObject(const QString& name)
{
  currentObject = compressedObject(name);
  if (!currentObject) {
	  error(QString("Invalid ELF object specification, setting to unknown"));

    currentObject = _data->object(_emptyString);
  }

  currentPartObject = currentObject->partObject(_part);
  currentFunction = 0;
  currentPartFunction = 0;
}
开发者ID:DeepCV,项目名称:kcachegrind,代码行数:13,代码来源:cachegrindloader.cpp


注:本文中的TraceData类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。