Program: 1841
Project: 1841
Buggy source:
void updateCpuStatsNow(){
synchronized (mProcessStatsThread) {
    mProcessStatsMutexFree.set(false);
    final long now=SystemClock.uptimeMillis();
    boolean haveNewCpuStats=false;
    if (MONITOR_CPU_USAGE && mLastCpuTime.get() < (now - MONITOR_CPU_MIN_TIME)) {
      mLastCpuTime.set(now);
      haveNewCpuStats=true;
      mProcessStats.update();
      if ("String_Node_Str".equals(SystemProperties.get("String_Node_Str"))) {
        int user=mProcessStats.getLastUserTime();
        int system=mProcessStats.getLastSystemTime();
        int iowait=mProcessStats.getLastIoWaitTime();
        int irq=mProcessStats.getLastIrqTime();
        int softIrq=mProcessStats.getLastSoftIrqTime();
        int idle=mProcessStats.getLastIdleTime();
        int total=user + system + iowait+ irq+ softIrq+ idle;
        if (total == 0)         total=1;
        EventLog.writeEvent(EventLogTags.CPU,((user + system + iowait+ irq+ softIrq) * 100) / total,(user * 100) / total,(system * 100) / total,(iowait * 100) / total,(irq * 100) / total,(softIrq * 100) / total);
      }
    }
    long[] cpuSpeedTimes=mProcessStats.getLastCpuSpeedTimes();
    final BatteryStatsImpl bstats=mBatteryStatsService.getActiveStatistics();
synchronized (bstats) {
synchronized (mPidsSelfLocked) {
        if (haveNewCpuStats) {
          if (mOnBattery) {
            int perc=bstats.startAddingCpuLocked();
            int totalUTime=0;
            int totalSTime=0;
            final int N=mProcessStats.countStats();
            for (int i=0; i < N; i++) {
              ProcessStats.Stats st=mProcessStats.getStats(i);
              if (!st.working) {
                continue;
              }
              ProcessRecord pr=mPidsSelfLocked.get(st.pid);
              int otherUTime=(st.rel_utime * perc) / 100;
              int otherSTime=(st.rel_stime * perc) / 100;
              totalUTime+=otherUTime;
              totalSTime+=otherSTime;
              if (pr != null) {
                BatteryStatsImpl.Uid.Proc ps=pr.batteryStats;
                ps.addCpuTimeLocked(st.rel_utime - otherUTime,st.rel_stime - otherSTime);
                ps.addSpeedStepTimes(cpuSpeedTimes);
                pr.curCpuTime+=(st.rel_utime + st.rel_stime) * 10;
              }
 else               if (st.uid >= Process.FIRST_APPLICATION_UID) {
                BatteryStatsImpl.Uid.Proc ps=st.batteryStats;
                if (ps == null) {
                  st.batteryStats=ps=bstats.getProcessStatsLocked(st.uid,"String_Node_Str");
                }
                ps.addCpuTimeLocked(st.rel_utime - otherUTime,st.rel_stime - otherSTime);
                ps.addSpeedStepTimes(cpuSpeedTimes);
                pr.curCpuTime+=(st.rel_utime + st.rel_stime) * 10;
              }
 else {
                BatteryStatsImpl.Uid.Proc ps=bstats.getProcessStatsLocked(st.name,st.pid);
                if (ps != null) {
                  ps.addCpuTimeLocked(st.rel_utime - otherUTime,st.rel_stime - otherSTime);
                  ps.addSpeedStepTimes(cpuSpeedTimes);
                }
              }
            }
            bstats.finishAddingCpuLocked(perc,totalUTime,totalSTime,cpuSpeedTimes);
          }
        }
      }
      if (mLastWriteTime < (now - BATTERY_STATS_TIME)) {
        mLastWriteTime=now;
        mBatteryStatsService.getActiveStatistics().writeAsyncLocked();
      }
    }
  }
}

Fixed version (ground truth):
void updateCpuStatsNow(){
synchronized (mProcessStatsThread) {
    mProcessStatsMutexFree.set(false);
    final long now=SystemClock.uptimeMillis();
    boolean haveNewCpuStats=false;
    if (MONITOR_CPU_USAGE && mLastCpuTime.get() < (now - MONITOR_CPU_MIN_TIME)) {
      mLastCpuTime.set(now);
      haveNewCpuStats=true;
      mProcessStats.update();
      if ("String_Node_Str".equals(SystemProperties.get("String_Node_Str"))) {
        int user=mProcessStats.getLastUserTime();
        int system=mProcessStats.getLastSystemTime();
        int iowait=mProcessStats.getLastIoWaitTime();
        int irq=mProcessStats.getLastIrqTime();
        int softIrq=mProcessStats.getLastSoftIrqTime();
        int idle=mProcessStats.getLastIdleTime();
        int total=user + system + iowait+ irq+ softIrq+ idle;
        if (total == 0)         total=1;
        EventLog.writeEvent(EventLogTags.CPU,((user + system + iowait+ irq+ softIrq) * 100) / total,(user * 100) / total,(system * 100) / total,(iowait * 100) / total,(irq * 100) / total,(softIrq * 100) / total);
      }
    }
    long[] cpuSpeedTimes=mProcessStats.getLastCpuSpeedTimes();
    final BatteryStatsImpl bstats=mBatteryStatsService.getActiveStatistics();
synchronized (bstats) {
synchronized (mPidsSelfLocked) {
        if (haveNewCpuStats) {
          if (mOnBattery) {
            int perc=bstats.startAddingCpuLocked();
            int totalUTime=0;
            int totalSTime=0;
            final int N=mProcessStats.countStats();
            for (int i=0; i < N; i++) {
              ProcessStats.Stats st=mProcessStats.getStats(i);
              if (!st.working) {
                continue;
              }
              ProcessRecord pr=mPidsSelfLocked.get(st.pid);
              int otherUTime=(st.rel_utime * perc) / 100;
              int otherSTime=(st.rel_stime * perc) / 100;
              totalUTime+=otherUTime;
              totalSTime+=otherSTime;
              if (pr != null) {
                BatteryStatsImpl.Uid.Proc ps=pr.batteryStats;
                ps.addCpuTimeLocked(st.rel_utime - otherUTime,st.rel_stime - otherSTime);
                ps.addSpeedStepTimes(cpuSpeedTimes);
                pr.curCpuTime+=(st.rel_utime + st.rel_stime) * 10;
              }
 else               if (st.uid >= Process.FIRST_APPLICATION_UID) {
                BatteryStatsImpl.Uid.Proc ps=st.batteryStats;
                if (ps == null) {
                  st.batteryStats=ps=bstats.getProcessStatsLocked(st.uid,"String_Node_Str");
                }
                ps.addCpuTimeLocked(st.rel_utime - otherUTime,st.rel_stime - otherSTime);
                ps.addSpeedStepTimes(cpuSpeedTimes);
              }
 else {
                BatteryStatsImpl.Uid.Proc ps=bstats.getProcessStatsLocked(st.name,st.pid);
                if (ps != null) {
                  ps.addCpuTimeLocked(st.rel_utime - otherUTime,st.rel_stime - otherSTime);
                  ps.addSpeedStepTimes(cpuSpeedTimes);
                }
              }
            }
            bstats.finishAddingCpuLocked(perc,totalUTime,totalSTime,cpuSpeedTimes);
          }
        }
      }
      if (mLastWriteTime < (now - BATTERY_STATS_TIME)) {
        mLastWriteTime=now;
        mBatteryStatsService.getActiveStatistics().writeAsyncLocked();
      }
    }
  }
}