示例#1
0
TraversalVisitType IteratorStack::VisitType() const
{  
  switch(clientTraversalOrder) {
  case PreOrder:
  case ReversePreOrder:
    return PreVisit;
  case PostOrder: 
  case ReversePostOrder:
    return PostVisit;
//case ReversePreAndPostOrder:
  case PreAndPostOrder: {
    StackableIterator* top = dynamic_cast<StackableIterator*>(Top());
    SingletonIterator* stop = dynamic_cast<SingletonIterator*>(top);
    if (top == 0) {
      DIAG_Die("");
    } else if (stop != 0) {
      return stop->VisitType();
    } else {
      return PreVisit;
    }
  }
  default:
    DIAG_Die("");
  }
  return PostVisit;  // bogus return--not reached
}
示例#2
0
string
toStr(const unsigned x, int base)
{
  const char* format = NULL;

  switch (base) {
  case 10:
    //int numSz = (x == 0) ? 1 : (int) log10((double)l); // no log16...
    //stringSize = 2 + numSz;
    format = "%u";
    break;
    
  case 16:
    //int numSz = (x == 0) ? 1 : (int) log10((double)l);
    //stringSize = 4 + numSz; 
    format = "%#x";
    break;

  default:
    DIAG_Die(DIAG_Unimplemented);
  }
  
  sprintf(buf, format, x);
  return string(buf);
}
示例#3
0
Unique::Unique(const char* theClassName)
  : className((theClassName) ? theClassName : "")
{
  if (classNameSet.count(className) != 0) { 
    DIAG_Die("Trying to create another " + className + " instance");
  }
  else {
    classNameSet.insert(className); 
  }
}
int
ANodeSortedIterator::cmpByDynInfo(const void* a, const void* b)
{
  ANode* x = (*(ANode**)a);
  ANode* y = (*(ANode**)b);

  // 0. test for equality
  if (x == y) {
    return 0;
  }

  // INVARIANT: x != y, so never return 0

  ADynNode* x_dyn = dynamic_cast<ADynNode*>(x);
  ADynNode* y_dyn = dynamic_cast<ADynNode*>(y);

  // 1. distinguish by dynamic info
  if (x_dyn && y_dyn) {
    return cmpByDynInfoSpecial(x_dyn, y_dyn);
  }

  // 2. distinguish by structure ids
  uint x_id = x->structureId();
  uint y_id = y->structureId();
  if (x_id != Prof::Struct::ANode::Id_NULL
      && y_id != Prof::Struct::ANode::Id_NULL) {
    int cmp_sid = cmp(x_id, y_id);
    if (cmp_sid != 0) {
      return cmp_sid;
    }
  }

  // 3. distinguish by type
  int cmp_ty = (int)x->type() - (int)y->type();
  if (cmp_ty != 0) {
    return cmp_ty;
  }


#if 1
  // 4. distinguish by id
  int cmp_id = (int)x->id() - (int)y->id();
  if (cmp_id != 0) {
    return cmp_id;
  }
#endif

  // *. Could compare childCount() and other aspects of children.
  DIAG_Die("Prof::CCT::ANodeSortedIterator::cmpByDynInfo: cannot compare:"
	   << "\n\tx: " << x->toStringMe(Prof::CCT::Tree::OFlg_Debug)
	   << "\n\ty: " << y->toStringMe(Prof::CCT::Tree::OFlg_Debug));
}
示例#5
0
bool IteratorStack::IterationIsForward() const
{
  switch(clientTraversalOrder) {
  case PreOrder:
  case PostOrder: 
  case PreAndPostOrder:
    return true;
  case ReversePreOrder:
  case ReversePostOrder:
//case ReversePreAndPostOrder:
    return false;
  default:
    DIAG_Die("");
  }
  return false;  // bogus return--not reached
}
示例#6
0
string
toStr(const int64_t x, int base)
{
  const char* format = NULL;
  
  switch (base) {
  case 10:
    format = "%" PRId64;
    break;
    
  default:
    DIAG_Die(DIAG_Unimplemented);
  }
  
  sprintf(buf, format, x);
  return string(buf);
}
int
ANodeSortedIterator::cmpByStructureInfo(const void* a, const void* b)
{
  ANode* x = (*(ANode**)a);
  ANode* y = (*(ANode**)b);

  if (x && y) {
    // 0. test for equality
    if (x == y) {
      return 0;
    }

    // INVARIANT: x != y, so never return 0
    
    // 1. distinguish by structure ids
    uint x_id = x->structureId();
    uint y_id = y->structureId();
    int cmp_sid = cmp(x_id, y_id);
    if (cmp_sid != 0) {
      return cmp_sid;
    }

    // 2. distinguish by types
    int cmp_ty = (int)x->type() - (int)y->type();
    if (cmp_ty != 0) {
      return cmp_ty;
    }

    // 3. distinguish by dynamic info (unnormalized CCTs)
    //    (for determinism, ensure x and y are both ADynNodes)
    ADynNode* x_dyn = dynamic_cast<ADynNode*>(x);
    ADynNode* y_dyn = dynamic_cast<ADynNode*>(y);
    if (x_dyn && y_dyn) {
      int cmp_dyn = cmpByDynInfoSpecial(x_dyn, y_dyn);
      if (cmp_dyn != 0) {
	return cmp_dyn;
      }
    }
    
    
    // 5. distinguish by id
    int cmp_id = (int)x->id() - (int)y->id();
    if (cmp_id != 0) {
      return cmp_id;
    }

    // 4. distinguish by tree context
    ANode* x_parent = x->parent();
    ANode* y_parent = y->parent();
    if (x_parent != y_parent) {
      int cmp_ctxt = cmpByStructureInfo(&x_parent, &y_parent);
      if (cmp_ctxt != 0) {
	return cmp_ctxt;
      }
    }
    // *. Could compare childCount() and other aspects of children.
    DIAG_Die("Prof::CCT::ANodeSortedIterator::cmpByStructureInfo: cannot compare:"
		<< "\n\tx: " << x->toStringMe(Prof::CCT::Tree::OFlg_Debug)
		<< "\n\ty: " << y->toStringMe(Prof::CCT::Tree::OFlg_Debug));
    return 0;
  }
  else if (x) {
    return 1; // x > y=NULL (only used for recursive case)
  }
  else if (y) {
    return -1; // x=NULL < y (only used for recursive case)
  }
  else {
    DIAG_Die(DIAG_UnexpectedInput);
  }
}
示例#8
0
Metric::DerivedIncrDesc*
Mgr::makeSummaryMetricIncr(const string mDrvdTy, const Metric::ADesc* mSrc)
{
  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::AExprIncr* expr = NULL;
  if (mDrvdTy.find("Sum", 0) == 0) {
    expr = new Metric::SumIncr(Metric::IData::npos, mSrc->id());
  }
  else if (mDrvdTy.find("Mean", 0) == 0) {
    expr = new Metric::MeanIncr(Metric::IData::npos, mSrc->id());
    doDispPercent = false;
  }
  else if (mDrvdTy.find("StdDev", 0) == 0) {
    expr = new Metric::StdDevIncr(Metric::IData::npos, 0, mSrc->id());
    doDispPercent = false;
  }
  else if (mDrvdTy.find("CfVar", 0) == 0) {
    expr = new Metric::CoefVarIncr(Metric::IData::npos, 0, mSrc->id());
    doDispPercent = false;
  }
  else if (mDrvdTy.find("%CfVar", 0) == 0) {
    expr = new Metric::RStdDevIncr(Metric::IData::npos, 0, mSrc->id());
    isPercent = true;
  }
  else if (mDrvdTy.find("Min", 0) == 0) {
    expr = new Metric::MinIncr(Metric::IData::npos, mSrc->id());
    doDispPercent = false;
  }
  else if (mDrvdTy.find("Max", 0) == 0) {
    expr = new Metric::MaxIncr(Metric::IData::npos, mSrc->id());
    doDispPercent = false;
  }
  else {
    DIAG_Die(DIAG_UnexpectedInput);
  }
  
  string mNmFmt = mSrc->nameToFmt();
  string mNmBase = mSrc->nameBase() + ":" + mDrvdTy;
  const string& mDesc = mSrc->description();

  DerivedIncrDesc* m =
    new DerivedIncrDesc(mNmFmt, mDesc, expr, isVisible,
			true/*isSortKey*/, doDispPercent, isPercent);
  m->nameBase(mNmBase);
  m->zeroDBInfo(); // clear
  insert(m);
  expr->accumId(m->id());

  if (expr->hasAccum2()) {
    string m2NmBase = mNmBase + ":accum2";
    DerivedIncrDesc* m2 =
      new DerivedIncrDesc(mNmFmt, mDesc, NULL/*expr*/, false/*isVisible*/,
			  false/*isSortKey*/, false/*doDispPercent*/,
			  false/*isPercent*/);
    m2->nameBase(m2NmBase);
    m2->zeroDBInfo(); // clear
    insert(m2);

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

  if (expr->hasNumSrcVar()) {
    string m3NmBase = mNmBase + ":num-src";
    Metric::NumSourceIncr* m3Expr = new Metric::NumSourceIncr(0, mSrc->id());
    DerivedIncrDesc* m3 =
      new DerivedIncrDesc(mNmFmt, mDesc, m3Expr, false/*isVisible*/,
			  false/*isSortKey*/, false/*doDispPercent*/,
			  false/*isPercent*/);
    m3->nameBase(m3NmBase);
    m3->zeroDBInfo(); // clear
    insert(m3);
    m3Expr->accumId(m3->id());

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

  return m;
}
示例#9
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;
}