Ejemplo n.º 1
0
void
Mgr::computePartners()
{
  StringToADescMap metricsIncl;
  StringToADescMap metricsExcl;

  // -------------------------------------------------------
  // populate maps
  // -------------------------------------------------------
  for (uint i = 0; i < m_metrics.size(); ++i) {
    Metric::ADesc* m = m_metrics[i];
    string nm = m->namePfxBaseSfx();

    StringToADescMap* metricsMap = NULL;
    switch (m->type()) {
      case ADesc::TyIncl: metricsMap = &metricsIncl; break;
      case ADesc::TyExcl: metricsMap = &metricsExcl; break;
      default: break;
    }
    
    if (metricsMap) {
      DIAG_MsgIf(0, "Metric::Mgr::computePartners: insert: " << nm
		 << " [" << m->name() << "]");
      std::pair<StringToADescMap::iterator, bool> ret =
	metricsMap->insert(make_pair(nm, m));
      DIAG_Assert(ret.second, "Metric::Mgr::computePartners: Found duplicate entry inserting:\n\t" << m->toString() << "\nOther entry:\n\t" << ret.first->second->toString());
    }
  }

  // -------------------------------------------------------
  // find partners
  // -------------------------------------------------------
  for (uint i = 0; i < m_metrics.size(); ++i) {
    Metric::ADesc* m = m_metrics[i];
    string nm = m->namePfxBaseSfx();

    StringToADescMap* metricsMap = NULL;
    switch (m->type()) {
      case ADesc::TyIncl: metricsMap = &metricsExcl; break;
      case ADesc::TyExcl: metricsMap = &metricsIncl; break;
      default: break;
    }
    
    if (metricsMap) {
      StringToADescMap::iterator it = metricsMap->find(nm);
      if (it != metricsMap->end()) {
	Metric::ADesc* partner = it->second;
	m->partner(partner);
	DIAG_MsgIf(0, "Metric::Mgr::computePartners: found: "
		   << m->name() << " -> " << partner->name());
      }
    }
  }
}
Ejemplo n.º 2
0
Metric::DerivedDesc*
Mgr::makeSummaryMetric(const string mDrvdTy, const Metric::ADesc* mSrc,
		       const Metric::ADescVec& mOpands)
{
  Metric::AExpr** opands = new Metric::AExpr*[mOpands.size()];
  for (uint i = 0; i < mOpands.size(); ++i) {
    Metric::ADesc* m = mOpands[i];
    opands[i] = new Metric::Var(m->name(), m->id());
  }

  bool doDispPercent = true;
  bool isPercent = false;
  bool isVisible = true;

  // This is a cheesy way of creating the metrics, but it is good
  // enough for now.

  Metric::AExpr* expr = NULL;
  if (mDrvdTy.find("Sum", 0) == 0) {
    expr = new Metric::Plus(opands, mOpands.size());
  }
  else if (mDrvdTy.find("Mean", 0) == 0) {
    expr = new Metric::Mean(opands, mOpands.size());
    doDispPercent = false;
  }
  else if (mDrvdTy.find("StdDev", 0) == 0) {
    expr = new Metric::StdDev(opands, mOpands.size());
    doDispPercent = false;
  }
  else if (mDrvdTy.find("CfVar", 0) == 0) {
    expr = new Metric::CoefVar(opands, mOpands.size());
    doDispPercent = false;
  }
  else if (mDrvdTy.find("%CfVar", 0) == 0) {
    expr = new Metric::RStdDev(opands, mOpands.size());
    isPercent = true;
  }
  else if (mDrvdTy.find("Min", 0) == 0) {
    expr = new Metric::Min(opands, mOpands.size());
    doDispPercent = false;
  }
  else if (mDrvdTy.find("Max", 0) == 0) {
    expr = new Metric::Max(opands, mOpands.size());
    doDispPercent = false;
  }
  else {
    DIAG_Die(DIAG_UnexpectedInput);
  }
  
  string mNmFmt = mSrc->nameToFmt();
  string mNmBase = mSrc->nameBase() + ":" + mDrvdTy;
  const string& mDesc = mSrc->description();

  DerivedDesc* m =
    new DerivedDesc(mNmFmt, mDesc, expr, isVisible, true/*isSortKey*/,
		    doDispPercent, isPercent);
  m->nameBase(mNmBase);
  m->nameSfx(""); // clear; cf. Prof::CallPath::Profile::RFlg_NoMetricSfx
  m->zeroDBInfo(); // clear
  insert(m);
  expr->accumId(m->id());

  if (expr->hasAccum2()) {
    string m2NmBase = mNmBase + ":accum2";
    DerivedDesc* m2 =
      new DerivedDesc(mNmFmt, mDesc, NULL/*expr*/, false/*isVisible*/,
		      false/*isSortKey*/, false/*doDispPercent*/,
		      false/*isPercent*/);
    m2->nameBase(m2NmBase);
    m2->nameSfx(""); // clear; cf. Prof::CallPath::Profile::RFlg_NoMetricSfx
    m2->zeroDBInfo(); // clear
    insert(m2);

    expr->accum2Id(m2->id());
  }

  if (expr->hasNumSrcVar()) {
    string m3NmBase = mNmBase + ":num-src";
    Metric::NumSource* m3Expr = new Metric::NumSource(mOpands.size());
    DerivedDesc* m3 =
      new DerivedDesc(mNmFmt, mDesc, m3Expr, false/*isVisible*/,
		      false/*isSortKey*/, false/*doDispPercent*/,
		      false/*isPercent*/);
    m3->nameBase(m3NmBase);
    m3->nameSfx(""); // clear; cf. Prof::CallPath::Profile::RFlg_NoMetricSfx
    m3->zeroDBInfo(); // clear
    insert(m3);
    m3Expr->accumId(m3->id());

    expr->numSrcVarId(m3->id());
  }

  return m;
}