Beispiel #1
0
ProcStats::ProcStats(AggregateStat* parentStat, AggregateStat* _coreStats) : coreStats(_coreStats) {
    uint32_t maxProcs = zinfo->lineSize;
    lastUpdatePhase = 0;

    // Check that coreStats are appropriate
    assert(coreStats);
    for (uint32_t i = 0; i < coreStats->size(); i++) {
        Stat* s = coreStats->get(i);
        AggregateStat* as = dynamic_cast<AggregateStat*>(s);
        auto err = [s](const char* reason) {
            panic("Stat %s is not per-core (%s)", s->name(), reason);
        };
        if (!as) err("not aggregate stat");
        if (!as->isRegular()) err("irregular aggregate");
        if (as->size() != zinfo->numCores) err("elems != cores");
    }

    // Initialize all the buffers
    bufSize = StatSize(coreStats);
    buf = gm_calloc<uint64_t>(bufSize);
    lastBuf = gm_calloc<uint64_t>(bufSize);

    // Create the procStats
    procStats = new AggregateStat(true);
    procStats->init("procStats", "Per-process stats");
    for (uint32_t p = 0; p < maxProcs; p++) {
        AggregateStat* ps = new AggregateStat(false);
        const char* name = gm_strdup(("procStats-" + Str(p)).c_str());
        ps->init(name, "Per-process stats");
        for (uint32_t i = 0; i < coreStats->size(); i++) {
            AggregateStat* as = dynamic_cast<AggregateStat*>(coreStats->get(i));
            assert(as && as->isRegular());
            ps->append(replStat(as->get(0), as->name(), as->desc()));
        }
        procStats->append(ps);
    }
    parentStat->append(procStats);
}
Beispiel #2
0
AggregateStat* FilterStatsLevel(const AggregateStat* src, const regex& filter, const char* prefix) {
    string base = prefix? (string(prefix) + src->name() + ".") : ""; //if NULL prefix, omit our name (we're root)
    vector<Stat*> children;
    for (uint32_t i = 0; i < src->size(); i++) {
        Stat* child = src->get(i);
        if (AggregateStat* as = dynamic_cast<AggregateStat*>(child)) {
            AggregateStat* fs = FilterStatsLevel(as, filter, base.c_str());
            if (fs) children.push_back(fs);
        } else {
            string name = base + child->name();
            if (regex_match(name, filter)) children.push_back(child);
        }
    }

    if (children.size()) {
        AggregateStat* res = new AggregateStat(src->isRegular());
        res->init(src->name(), src->desc());
        for (Stat* c : children) res->append(c);
        return res;
    } else {
        return NULL;
    }
}