コード例 #1
0
QVariant SensorBrowserModel::data( const QModelIndex & index, int role) const { //virtual
    if(!index.isValid()) return QVariant();
    switch(role) {
        case Qt::DisplayRole: {
            if(index.column()==0) {
                uint id = index.internalId();
                if(mSensorInfoMap.contains(id)) {
                    Q_ASSERT(mSensorInfoMap.value(id));
                    SensorInfo *sensorInfo = mSensorInfoMap.value(id);
                    return QString(sensorInfo->description() + " (" + KSGRD::SensorMgr->translateSensorType(sensorInfo->type()) + ')' );
                }
                if(mTreeNodeNames.contains(id)) return mTreeNodeNames.value(id);
                if(mHostInfoMap.contains(id)) {
                    Q_ASSERT(mHostInfoMap.value(id));
                    return mHostInfoMap.value(id)->hostName();
                }
            }
            return QString();
        }
        case Qt::DecorationRole: {
            if(index.column() == 0) {
                HostInfo *host = getHostInfo(index.internalId());
                KSGRD::SensorAgent *agent;
                if(host != NULL && (agent = host->sensorAgent())) {
                    if(agent->daemonOnLine())
                        return KIcon("computer");
                    else
                        return KIcon("dialog-warning");
                } else
                    return QIcon();
            } else
                return QIcon();
            break;
        }
        case Qt::ToolTipRole: {
            if(index.column() == 0) {
                HostInfo *host = getHostInfo(index.internalId());
                KSGRD::SensorAgent *agent;
                if(host != NULL && (agent = host->sensorAgent())) {
                    if(agent->daemonOnLine())
                        return agent->hostName();
                    else
                        return agent->reasonForOffline();
                }
            }
            break;
        }

    } //switch
    return QVariant();
}
コード例 #2
0
void LowMemoryDetector::process_sensor_changes(TRAPS) {
  ResourceMark rm(THREAD);
  HandleMark hm(THREAD);

  // No need to hold Service_lock to call out to Java
  int num_memory_pools = MemoryService::num_memory_pools();
  for (int i = 0; i < num_memory_pools; i++) {
    MemoryPool* pool = MemoryService::get_memory_pool(i);
    SensorInfo* sensor = pool->usage_sensor();
    SensorInfo* gc_sensor = pool->gc_usage_sensor();
    if (sensor != NULL && sensor->has_pending_requests()) {
      sensor->process_pending_requests(CHECK);
    }
    if (gc_sensor != NULL && gc_sensor->has_pending_requests()) {
      gc_sensor->process_pending_requests(CHECK);
    }
  }
}
コード例 #3
0
bool LowMemoryDetector::has_pending_requests() {
  assert(Service_lock->owned_by_self(), "Must own Service_lock");
  bool has_requests = false;
  int num_memory_pools = MemoryService::num_memory_pools();
  for (int i = 0; i < num_memory_pools; i++) {
    MemoryPool* pool = MemoryService::get_memory_pool(i);
    SensorInfo* sensor = pool->usage_sensor();
    if (sensor != NULL) {
      has_requests = has_requests || sensor->has_pending_requests();
    }

    SensorInfo* gc_sensor = pool->gc_usage_sensor();
    if (gc_sensor != NULL) {
      has_requests = has_requests || gc_sensor->has_pending_requests();
    }
  }
  return has_requests;
}
コード例 #4
0
void LowMemoryDetector::low_memory_detector_thread_entry(JavaThread* jt, TRAPS) {
  while (true) {
    bool   sensors_changed = false;

    {
      // _no_safepoint_check_flag is used here as LowMemory_lock is a
      // special lock and the VMThread may acquire this lock at safepoint.
      // Need state transition ThreadBlockInVM so that this thread
      // will be handled by safepoint correctly when this thread is
      // notified at a safepoint.

      // This ThreadBlockInVM object is not also considered to be
      // suspend-equivalent because LowMemoryDetector threads are
      // not visible to external suspension.

      ThreadBlockInVM tbivm(jt);

      MutexLockerEx ml(LowMemory_lock, Mutex::_no_safepoint_check_flag);
      while (!(sensors_changed = has_pending_requests())) {
        // wait until one of the sensors has pending requests
        LowMemory_lock->wait(Mutex::_no_safepoint_check_flag);
      }
    }

    {
      ResourceMark rm(THREAD);
      HandleMark hm(THREAD);

      // No need to hold LowMemory_lock to call out to Java
      int num_memory_pools = MemoryService::num_memory_pools();
      for (int i = 0; i < num_memory_pools; i++) {
        MemoryPool* pool = MemoryService::get_memory_pool(i);
        SensorInfo* sensor = pool->usage_sensor();
        SensorInfo* gc_sensor = pool->gc_usage_sensor();
        if (sensor != NULL && sensor->has_pending_requests()) {
          sensor->process_pending_requests(CHECK);
        }
        if (gc_sensor != NULL && gc_sensor->has_pending_requests()) {
          gc_sensor->process_pending_requests(CHECK);
        }
      }
    }
  }
}
コード例 #5
0
// Only called by VMThread at GC time
void LowMemoryDetector::detect_after_gc_memory(MemoryPool* pool) {
  SensorInfo* sensor = pool->gc_usage_sensor();
  if (sensor == NULL ||
      !pool->gc_usage_threshold()->is_high_threshold_supported() ||
      pool->gc_usage_threshold()->high_threshold() == 0) {
    return;
  }

  {
    MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);

    MemoryUsage usage = pool->get_last_collection_usage();
    sensor->set_counter_sensor_level(usage, pool->gc_usage_threshold());

    if (sensor->has_pending_requests()) {
      // notify sensor state update
      Service_lock->notify_all();
    }
  }
}
コード例 #6
0
// This method could be called from any Java threads
// and also VMThread.
void LowMemoryDetector::detect_low_memory() {
  MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);

  bool has_pending_requests = false;
  int num_memory_pools = MemoryService::num_memory_pools();
  for (int i = 0; i < num_memory_pools; i++) {
    MemoryPool* pool = MemoryService::get_memory_pool(i);
    SensorInfo* sensor = pool->usage_sensor();
    if (sensor != NULL &&
        pool->usage_threshold()->is_high_threshold_supported() &&
        pool->usage_threshold()->high_threshold() != 0) {
      MemoryUsage usage = pool->get_memory_usage();
      sensor->set_gauge_sensor_level(usage,
                                     pool->usage_threshold());
      has_pending_requests = has_pending_requests || sensor->has_pending_requests();
    }
  }

  if (has_pending_requests) {
    Service_lock->notify_all();
  }
}
コード例 #7
0
void SensorBrowserModel::removeAllSensorUnderBranch(HostInfo* hostInfo, int parentId)  {

    QList<int> children = mTreeMap.value(parentId);

    for (int i = 0; i < children.size(); i++) {

        if (mTreeMap.contains(children[i]))  {
            //well our children is not a sensor so remove what is under him
            removeAllSensorUnderBranch(hostInfo,children[i]);

        } else  {
            //well this should be a sensor so remove it
            if (mSensorInfoMap.contains(children[i])) {
                SensorInfo* sensorToRemove = mSensorInfoMap.value(children[i]);
                Q_ASSERT(sensorToRemove);
                removeSensor(hostInfo, parentId, sensorToRemove->name());
            }
        }
    }


}
コード例 #8
0
QMimeData * SensorBrowserModel::mimeData ( const QModelIndexList & indexes ) const { //virtual
    QMimeData *mimeData = new QMimeData();
    if(indexes.size() != 1) return mimeData;
    SensorInfo *sensor = getSensorInfo(indexes[0]);
    if(!sensor) return mimeData;
    // Create text drag object as
    // "<hostname> <sensorname> <sensortype> <sensordescription>".
    // Only the description may contain blanks.
    Q_ASSERT(sensor);
    Q_ASSERT(sensor->hostInfo());
    QString mDragText = sensor->hostInfo()->hostName() + ' ' +
        sensor->name() + ' ' +
        sensor->type()+ ' ' +
        sensor->description();


    mimeData->setData( "application/x-ksysguard", mDragText.toUtf8() );
    return mimeData;
}
コード例 #9
0
ファイル: memoryPool.cpp プロジェクト: guanxiaohua/TransGC
static void set_sensor_obj_at(SensorInfo** sensor_ptr, instanceHandle sh) {
  assert(*sensor_ptr == NULL, "Should be called only once");
  SensorInfo* sensor = new SensorInfo();
  sensor->set_sensor(sh());
  *sensor_ptr = sensor;
}