Ejemplo n.º 1
0
bool BucketAgg::collect(void* process, void *thread) {
  Process::const_ptr process_ptr = *(Process::const_ptr*)process;
  Thread::const_ptr thread_ptr = *(Thread::const_ptr*)thread;

  if(!process_ptr) {
    return DYSECTVERBOSE(false, "Process object not available");
    return false;
  }

  // Get the rank of the process
  Probe *owner = getOwner();
  if (!owner) {
    return DYSECTVERBOSE(false, "Could not find Probe owner");
  }

  Domain *dom = owner->getDomain();
  if (!dom) {
    return DYSECTVERBOSE(false, "Could not find Domain");
  }

  std::map<int, Dyninst::ProcControlAPI::Process::ptr> *mpiRankToProcessMap;
  mpiRankToProcessMap = dom->getMpiRankToProcessMap();
  if (!mpiRankToProcessMap) {
    return DYSECTVERBOSE(false, "Could not find MPI rank map");
  }

  int rank = -1;
  std::map<int, Dyninst::ProcControlAPI::Process::ptr>::iterator iter;
  for (iter = mpiRankToProcessMap->begin(); iter != mpiRankToProcessMap->end(); iter++) {
    if (iter->second == process_ptr) {
      rank = iter->first;
      break;
    }
  }

  if (rank == -1) {
    return DYSECTVERBOSE(false, "Failed to determine Rank");
  }

  // Read the value of the variable
  ProcDebug* pDebug;
  Walker* proc = (Walker*)process_ptr->getData();

  if(!proc) {
    return DYSECTVERBOSE(false, "Could not get walker from process");
  }

  bool wasRunning;
  if (process_ptr->allThreadsRunning()) {
    wasRunning = true;

    pDebug = dynamic_cast<ProcDebug *>(proc->getProcessState());

    if (pDebug == NULL) {
      return DYSECTWARN(false, "Failed to dynamic_cast ProcDebug pointer");
    }

    if (pDebug->isTerminated()) {
      return DYSECTWARN(false, "Process is terminated");
    }

    if (pDebug->pause() == false) {
      return DYSECTWARN(false, "Failed to pause process");
    }
  }

  DataRef ref(Value::floatType, variableName.c_str());

  TargetVar var(variableName.c_str());
  ConditionResult condRes;
  Value val;

  DysectErrorCode readStatus = var.getValue(condRes, val, process_ptr, thread_ptr->getTID());

  if (wasRunning == true) {
    if (pDebug->resume() == false) {
      return DYSECTWARN(false, "Failed to resume process");
    }
  }

  if (readStatus != OK) {
    return DYSECTWARN(false, "Could not read value from reference");
  }

  if (condRes != Resolved) {
    return DYSECTINFO(false, "Value not available - could be optimized out!");
  }

  if (variableType == Value::noType) {
    variableType = val.getType();
  }

  int bucket = getBucketFromValue(val);
  buckets[bucket] += 1;

  string valStr;
  val.getStr(valStr);
  DYSECTVERBOSE(true, "Rank %d read the value %s and will place it in bucket %d", rank, valStr.c_str(), bucket);

  return true;
}