Example #1
0
  // return hashmap of IEModel keyed by process name
  public static HashMap<String, IEModel> getIEModelsForProcesses(
      AIDSDBHelper aidsDBHelper, long fromTimeMillis, long toTimeMillis) {
    // hashmap keyed by process name and then attributes
    HashMap<String, IEModel> processMap = new HashMap<String, IEModel>();

    // get processes for specified period
    List<Process> processListForPeriod = aidsDBHelper.getProcesses(fromTimeMillis, toTimeMillis);

    // i have to iterate over them all because some could have different
    // PIDs
    // so i group them under process name
    for (Process p : processListForPeriod) {
      if (!processMap.containsKey(p.Name)) {
        processMap.put(p.Name, new IEModel());
      }

      IEModel pIEModel = processMap.get(p.Name);

      // get cpuusage for each process
      List<CPUUsage> cpuUsageForProcessList =
          aidsDBHelper.getCPUUsage(p.Pid, fromTimeMillis, toTimeMillis);
      Log.i("hash", "" + cpuUsageForProcessList.size());
      for (CPUUsage cpu : cpuUsageForProcessList) {
        int cpuUsageInt = Integer.parseInt(cpu.CPUUsage);

        if (cpuUsageInt < 30) {
          pIEModel.CPULow = pIEModel.CPULow + 1;
        } else if (cpuUsageInt < 60) {
          pIEModel.CPUMid = pIEModel.CPUMid + 1;
        } else {
          pIEModel.CPUHigh = pIEModel.CPUHigh + 1;
        }

        pIEModel.CPUCounter = pIEModel.CPUCounter + 1;
      }

      // bandwidth usage for each process
      HashMap<String, String> bandwidthUse =
          aidsDBHelper.getBandwidthUsage(p.Uid, fromTimeMillis, toTimeMillis);
      // bandwidth is calculated per uid not pid, so its already
      // cumulative
      pIEModel.RxBytes = Integer.parseInt(bandwidthUse.get("rx"));
      pIEModel.TxBytes = Integer.parseInt(bandwidthUse.get("tx"));
    }

    return processMap;
  }