Program: 195495
Project: 195495
Buggy source:
void updateCpuStatsNow(){
synchronized (mProcessCpuTracker) {
    mProcessCpuMutexFree.set(false);
    final long now=SystemClock.uptimeMillis();
    boolean haveNewCpuStats=false;
    if (MONITOR_CPU_USAGE && mLastCpuTime.get() < (now - MONITOR_CPU_MIN_TIME)) {
      mLastCpuTime.set(now);
      mProcessCpuTracker.update();
      if (mProcessCpuTracker.hasGoodLastStats()) {
        haveNewCpuStats=true;
        if ("String_Node_Str".equals(SystemProperties.get("String_Node_Str"))) {
          int user=mProcessCpuTracker.getLastUserTime();
          int system=mProcessCpuTracker.getLastSystemTime();
          int iowait=mProcessCpuTracker.getLastIoWaitTime();
          int irq=mProcessCpuTracker.getLastIrqTime();
          int softIrq=mProcessCpuTracker.getLastSoftIrqTime();
          int idle=mProcessCpuTracker.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=mProcessCpuTracker.getLastCpuSpeedTimes();
    final BatteryStatsImpl bstats=mBatteryStatsService.getActiveStatistics();
synchronized (bstats) {
synchronized (mPidsSelfLocked) {
        if (haveNewCpuStats) {
          final int perc=bstats.startAddingCpuLocked();
          if (perc >= 0) {
            int remainUTime=0;
            int remainSTime=0;
            int totalUTime=0;
            int totalSTime=0;
            final int N=mProcessCpuTracker.countStats();
            for (int i=0; i < N; i++) {
              ProcessCpuTracker.Stats st=mProcessCpuTracker.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;
              remainUTime+=otherUTime;
              remainSTime+=otherSTime;
              totalUTime+=st.rel_utime;
              totalSTime+=st.rel_stime;
              if (pr != null) {
                BatteryStatsImpl.Uid.Proc ps=pr.curProcBatteryStats;
                if (ps == null || !ps.isActive()) {
                  pr.curProcBatteryStats=ps=bstats.getProcessStatsLocked(pr.info.uid,pr.processName);
                }
                ps.addCpuTimeLocked(st.rel_utime - otherUTime,st.rel_stime - otherSTime,cpuSpeedTimes);
                pr.curCpuTime+=(st.rel_utime + st.rel_stime) * 10;
              }
 else {
                BatteryStatsImpl.Uid.Proc ps=st.batteryStats;
                if (ps == null || !ps.isActive()) {
                  st.batteryStats=ps=bstats.getProcessStatsLocked(bstats.mapUid(st.uid),st.name);
                }
                ps.addCpuTimeLocked(st.rel_utime - otherUTime,st.rel_stime - otherSTime,cpuSpeedTimes);
              }
            }
            final int userTime=mProcessCpuTracker.getLastUserTime();
            final int systemTime=mProcessCpuTracker.getLastSystemTime();
            final int iowaitTime=mProcessCpuTracker.getLastIoWaitTime();
            final int irqTime=mProcessCpuTracker.getLastIrqTime();
            final int softIrqTime=mProcessCpuTracker.getLastSoftIrqTime();
            final int idleTime=mProcessCpuTracker.getLastIdleTime();
            bstats.finishAddingCpuLocked(perc,remainUTime,remainSTime,totalUTime,totalSTime,userTime,systemTime,iowaitTime,irqTime,softIrqTime,idleTime,cpuSpeedTimes);
          }
        }
      }
      if (mLastWriteTime < (now - BATTERY_STATS_TIME)) {
        mLastWriteTime=now;
        mBatteryStatsService.getActiveStatistics().writeAsyncLocked();
      }
    }
  }
}

Fixed version (ground truth):
void updateCpuStatsNow(){
synchronized (mProcessCpuTracker) {
    mProcessCpuMutexFree.set(false);
    final long now=SystemClock.uptimeMillis();
    boolean haveNewCpuStats=false;
    if (MONITOR_CPU_USAGE && mLastCpuTime.get() < (now - MONITOR_CPU_MIN_TIME)) {
      mLastCpuTime.set(now);
      mProcessCpuTracker.update();
      if (mProcessCpuTracker.hasGoodLastStats()) {
        haveNewCpuStats=true;
        if ("String_Node_Str".equals(SystemProperties.get("String_Node_Str"))) {
          int user=mProcessCpuTracker.getLastUserTime();
          int system=mProcessCpuTracker.getLastSystemTime();
          int iowait=mProcessCpuTracker.getLastIoWaitTime();
          int irq=mProcessCpuTracker.getLastIrqTime();
          int softIrq=mProcessCpuTracker.getLastSoftIrqTime();
          int idle=mProcessCpuTracker.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=mProcessCpuTracker.getLastCpuSpeedTimes();
    final BatteryStatsImpl bstats=mBatteryStatsService.getActiveStatistics();
synchronized (bstats) {
synchronized (mPidsSelfLocked) {
        if (haveNewCpuStats) {
          final int perc=bstats.startAddingCpuLocked();
          if (perc >= 0) {
            int remainUTime=0;
            int remainSTime=0;
            int totalUTime=0;
            int totalSTime=0;
            final int N=mProcessCpuTracker.countStats();
            for (int i=0; i < N; i++) {
              ProcessCpuTracker.Stats st=mProcessCpuTracker.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;
              remainUTime+=otherUTime;
              remainSTime+=otherSTime;
              totalUTime+=st.rel_utime;
              totalSTime+=st.rel_stime;
              if (pr != null) {
                BatteryStatsImpl.Uid.Proc ps=pr.curProcBatteryStats;
                if (ps == null || !ps.isActive()) {
                  pr.curProcBatteryStats=ps=bstats.getProcessStatsLocked(pr.info.uid,pr.processName);
                }
                ps.addCpuTimeLocked(st.rel_utime - otherUTime,st.rel_stime - otherSTime,cpuSpeedTimes);
                pr.curCpuTime+=st.rel_utime + st.rel_stime;
              }
 else {
                BatteryStatsImpl.Uid.Proc ps=st.batteryStats;
                if (ps == null || !ps.isActive()) {
                  st.batteryStats=ps=bstats.getProcessStatsLocked(bstats.mapUid(st.uid),st.name);
                }
                ps.addCpuTimeLocked(st.rel_utime - otherUTime,st.rel_stime - otherSTime,cpuSpeedTimes);
              }
            }
            final int userTime=mProcessCpuTracker.getLastUserTime();
            final int systemTime=mProcessCpuTracker.getLastSystemTime();
            final int iowaitTime=mProcessCpuTracker.getLastIoWaitTime();
            final int irqTime=mProcessCpuTracker.getLastIrqTime();
            final int softIrqTime=mProcessCpuTracker.getLastSoftIrqTime();
            final int idleTime=mProcessCpuTracker.getLastIdleTime();
            bstats.finishAddingCpuLocked(perc,remainUTime,remainSTime,totalUTime,totalSTime,userTime,systemTime,iowaitTime,irqTime,softIrqTime,idleTime,cpuSpeedTimes);
          }
        }
      }
      if (mLastWriteTime < (now - BATTERY_STATS_TIME)) {
        mLastWriteTime=now;
        mBatteryStatsService.getActiveStatistics().writeAsyncLocked();
      }
    }
  }
}