计算平均异常率，如果调用次数小于leastWindowCount则不参与计算。 如果所有调用次数均为0则返回-1

@param invocationStats List<InvocationStat>
@param leastWindowCount leastWindowCount
@return The average exception rate of all invocation statics
512573
private double calculateAverageExceptionRate(List<InvocationStat> invocationStats, long leastWindowCount) {
        long sumException = 0;
        long sumCall = 0;
        for (InvocationStat invocationStat : invocationStats) {

            long invocationLeastWindowCount = getInvocationLeastWindowCount(invocationStat,
                ProviderInfoWeightManager.getWeight(invocationStat.getDimension().getProviderInfo()),
                leastWindowCount);

            if (invocationLeastWindowCount != -1
                && invocationStat.getInvokeCount() >= invocationLeastWindowCount) {
                sumException += invocationStat.getExceptionCount();
                sumCall += invocationStat.getInvokeCount();
            }
        }
        if (sumCall == 0) {
            return -1;
        }
        return CalculateUtils.divide(sumException, sumCall);
    }
388312
protected int countedSize() throws PersistenceBrokerException
    {
        Query countQuery = getBroker().serviceBrokerHelper().getCountQuery(getQueryObject().getQuery());
        ResultSetAndStatement rsStmt;
        ClassDescriptor cld = getQueryObject().getClassDescriptor();
        int count = 0;

        // BRJ: do not use broker.getCount() because it's extent-aware
        // the count we need here must not include extents !
        if (countQuery instanceof QueryBySQL)
        {
            String countSql = ((QueryBySQL) countQuery).getSql();
            rsStmt = getBroker().serviceJdbcAccess().executeSQL(countSql, cld, Query.NOT_SCROLLABLE);
        }
        else
        {
            rsStmt = getBroker().serviceJdbcAccess().executeQuery(countQuery, cld);
        }

        try
        {
            if (rsStmt.m_rs.next())
            {
                count = rsStmt.m_rs.getInt(1);
            }
        }
        catch (SQLException e)
        {
            throw new PersistenceBrokerException(e);
        }
        finally
        {
            rsStmt.close();
        }

        return count;
    }
603597
private VoltTable[] aggregateProcedureProfileStats(VoltTable[] baseStats)
    {
        if (baseStats == null || baseStats.length != 1) {
            return baseStats;
        }

        StatsProcProfTable timeTable = new StatsProcProfTable();
        baseStats[0].resetRowPosition();
        while (baseStats[0].advanceRow()) {
            // Skip non-transactional procedures for some of these rollups until
            // we figure out how to make them less confusing.
            // NB: They still show up in the raw PROCEDURE stata.
            boolean transactional = baseStats[0].getLong("TRANSACTIONAL") == 1;
            if (!transactional) {
                continue;
            }

            if ( ! baseStats[0].getString("STATEMENT").equalsIgnoreCase("<ALL>")) {
                continue;
            }
            String pname = baseStats[0].getString("PROCEDURE");

            timeTable.updateTable(!isReadOnlyProcedure(pname),
                    baseStats[0].getLong("TIMESTAMP"),
                    pname,
                    baseStats[0].getLong("PARTITION_ID"),
                    baseStats[0].getLong("INVOCATIONS"),
                    baseStats[0].getLong("MIN_EXECUTION_TIME"),
                    baseStats[0].getLong("MAX_EXECUTION_TIME"),
                    baseStats[0].getLong("AVG_EXECUTION_TIME"),
                    baseStats[0].getLong("FAILURES"),
                    baseStats[0].getLong("ABORTS"));
        }
        return new VoltTable[] { timeTable.sortByAverage("EXECUTION_TIME") };
    }
1278916
public int getAppContextSessionCount(PageContext pc) {
	ApplicationContext appContext = pc.getApplicationContext();
	if (pc.getSessionType() == Config.SESSION_TYPE_JEE) return 0;

	Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());
	return getCount(context);
    }
242823
protected int getCount(int type, Collection<ConnectionListener> listeners)
   {
      int count = 0;

      for (ConnectionListener cl : listeners)
      {
         if (cl.getState() == type)
            count++;
      }

      return count;
   }
720778
private static int getBugPriority(String methodName, MethodInfo mi) {
		if (Values.STATIC_INITIALIZER.equals(methodName)) {
			return LOW_PRIORITY;
		}

		if ((mi.getNumBytes() >= highByteCountLimit) || (mi.getNumMethodCalls() >= highMethodCallLimit)) {
			return HIGH_PRIORITY;
		}

		if ((mi.getNumBytes() >= normalByteCountLimit) || (mi.getNumMethodCalls() >= normalMethodCallLimit)) {
			return NORMAL_PRIORITY;
		}

		if ((mi.getNumBytes() >= lowByteCountLimit) || (mi.getNumMethodCalls() >= lowMethodCallLimit)) {
			return LOW_PRIORITY;
		}

		return EXP_PRIORITY;
	}
1137470
public double getAnomalyScore(Instance inst)
	{
		if(this.referenceWindow)
			return 0.5;
		else
		{
			double accumulatedScore = 0.0;
			int massLimit = (int) (Math.ceil(this.sizeLimit*this.windowSize));
			double maxScore = this.windowSize * Math.pow(2.0, this.maxDepth);

			for(int i = 0 ; i < this.numTrees ; i++)
			{
				accumulatedScore += (forest[i].score(inst, massLimit) / maxScore);
			}

			accumulatedScore = accumulatedScore / (((double) this.numTrees));

			return 0.5 - accumulatedScore + this.anomalyThreshold;
		}
	}
759241
public int getFailureCount() {
    int count = 0;
    for (AggregatedTestResultEvent t : getTests()) {
      if (t.getStatus() == TestStatus.FAILURE)
        count++;
    }
    for (FailureMirror m : getFailures()) {
      if (m.isAssertionViolation())
        count++;
    }
    return count;
  }
821251
public int getErrorCount() {
    int count = 0;
    for (AggregatedTestResultEvent t : getTests()) {
      if (t.getStatus() == TestStatus.ERROR)
        count++;
    }
    
    for (FailureMirror m : getFailures()) {
      if (m.isErrorViolation())
        count++;
    }
    return count;
  }
382876
@SuppressWarnings("deprecation")
	private static int calculateNumberOfNetworkBuffers(Configuration configuration, long maxJvmHeapMemory) {
		final int numberOfNetworkBuffers;
		if (!hasNewNetworkConfig(configuration)) {
			// fallback: number of network buffers
			numberOfNetworkBuffers = configuration.getInteger(TaskManagerOptions.NETWORK_NUM_BUFFERS);

			checkOldNetworkConfig(numberOfNetworkBuffers);
		} else {
			if (configuration.contains(TaskManagerOptions.NETWORK_NUM_BUFFERS)) {
				LOG.info("Ignoring old (but still present) network buffer configuration via {}.",
					TaskManagerOptions.NETWORK_NUM_BUFFERS.key());
			}

			final long networkMemorySize = calculateNewNetworkBufferMemory(configuration, maxJvmHeapMemory);

			// tolerate offcuts between intended and allocated memory due to segmentation (will be available to the user-space memory)
			long numberOfNetworkBuffersLong = networkMemorySize / getPageSize(configuration);
			if (numberOfNetworkBuffersLong > Integer.MAX_VALUE) {
				throw new IllegalArgumentException("The given number of memory bytes (" + networkMemorySize
					+ ") corresponds to more than MAX_INT pages.");
			}
			numberOfNetworkBuffers = (int) numberOfNetworkBuffersLong;
		}

		return numberOfNetworkBuffers;
	}
1263171
public Long getTotalTargetCountByStatus(final Status status) {
        final Long count = statusTotalCountMap.get(status);
        return count == null ? 0L : count;
    }
1086691
public SchedulerStats stats() {
		int activeThreads = threadPoolExecutor.getActiveCount();
		return SchedulerStats.of(ThreadPoolStats.of(
			threadPoolExecutor.getCorePoolSize(),
			threadPoolExecutor.getMaximumPoolSize(),
			activeThreads,
			threadPoolExecutor.getPoolSize() - activeThreads,
			threadPoolExecutor.getLargestPoolSize()
		));
	}
892331
@Override
    public double getLoadExceptionRate() {
        long totalLoadCount = loadSuccessCount.get() + loadExceptionCount.get();
        return (totalLoadCount == 0) ? 0.0 : (double) loadExceptionCount.get() / totalLoadCount;
    }
928777
public int compareByAvg(ProcProfRow lhs, ProcProfRow rhs)
    {
        if (lhs.avg * lhs.invocations > rhs.avg * rhs.invocations) {
            return 1;
        } else if (lhs.avg * lhs.invocations < rhs.avg * rhs.invocations) {
            return -1;
        } else {
            return 0;
        }
    }
496351
public static CheckpointStatistics generateCheckpointStatistics(AbstractCheckpointStats checkpointStats, boolean includeTaskCheckpointStatistics) {
		Preconditions.checkNotNull(checkpointStats);

		Map<JobVertexID, TaskCheckpointStatistics> checkpointStatisticsPerTask;

		if (includeTaskCheckpointStatistics) {
			Collection<TaskStateStats> taskStateStats = checkpointStats.getAllTaskStateStats();

			checkpointStatisticsPerTask = new HashMap<>(taskStateStats.size());

			for (TaskStateStats taskStateStat : taskStateStats) {
				checkpointStatisticsPerTask.put(
					taskStateStat.getJobVertexId(),
					new TaskCheckpointStatistics(
							checkpointStats.getCheckpointId(),
							checkpointStats.getStatus(),
						taskStateStat.getLatestAckTimestamp(),
						taskStateStat.getStateSize(),
						taskStateStat.getEndToEndDuration(checkpointStats.getTriggerTimestamp()),
						taskStateStat.getAlignmentBuffered(),
						taskStateStat.getNumberOfSubtasks(),
						taskStateStat.getNumberOfAcknowledgedSubtasks()));
			}
		} else {
			checkpointStatisticsPerTask = Collections.emptyMap();
		}

		if (checkpointStats instanceof CompletedCheckpointStats) {
			final CompletedCheckpointStats completedCheckpointStats = ((CompletedCheckpointStats) checkpointStats);

			return new CheckpointStatistics.CompletedCheckpointStatistics(
				completedCheckpointStats.getCheckpointId(),
				completedCheckpointStats.getStatus(),
				completedCheckpointStats.getProperties().isSavepoint(),
				completedCheckpointStats.getTriggerTimestamp(),
				completedCheckpointStats.getLatestAckTimestamp(),
				completedCheckpointStats.getStateSize(),
				completedCheckpointStats.getEndToEndDuration(),
				completedCheckpointStats.getAlignmentBuffered(),
				completedCheckpointStats.getNumberOfSubtasks(),
				completedCheckpointStats.getNumberOfAcknowledgedSubtasks(),
				checkpointStatisticsPerTask,
				completedCheckpointStats.getExternalPath(),
				completedCheckpointStats.isDiscarded());
		} else if (checkpointStats instanceof FailedCheckpointStats) {
			final FailedCheckpointStats failedCheckpointStats = ((FailedCheckpointStats) checkpointStats);

			return new CheckpointStatistics.FailedCheckpointStatistics(
				failedCheckpointStats.getCheckpointId(),
				failedCheckpointStats.getStatus(),
				failedCheckpointStats.getProperties().isSavepoint(),
				failedCheckpointStats.getTriggerTimestamp(),
				failedCheckpointStats.getLatestAckTimestamp(),
				failedCheckpointStats.getStateSize(),
				failedCheckpointStats.getEndToEndDuration(),
				failedCheckpointStats.getAlignmentBuffered(),
				failedCheckpointStats.getNumberOfSubtasks(),
				failedCheckpointStats.getNumberOfAcknowledgedSubtasks(),
				checkpointStatisticsPerTask,
				failedCheckpointStats.getFailureTimestamp(),
				failedCheckpointStats.getFailureMessage());
		} else if (checkpointStats instanceof PendingCheckpointStats) {
			final PendingCheckpointStats pendingCheckpointStats = ((PendingCheckpointStats) checkpointStats);

			return new CheckpointStatistics.PendingCheckpointStatistics(
				pendingCheckpointStats.getCheckpointId(),
				pendingCheckpointStats.getStatus(),
				pendingCheckpointStats.getProperties().isSavepoint(),
				pendingCheckpointStats.getTriggerTimestamp(),
				pendingCheckpointStats.getLatestAckTimestamp(),
				pendingCheckpointStats.getStateSize(),
				pendingCheckpointStats.getEndToEndDuration(),
				pendingCheckpointStats.getAlignmentBuffered(),
				pendingCheckpointStats.getNumberOfSubtasks(),
				pendingCheckpointStats.getNumberOfAcknowledgedSubtasks(),
				checkpointStatisticsPerTask
			);
		} else {
			throw new IllegalArgumentException("Given checkpoint stats object of type "
				+ checkpointStats.getClass().getName() + " cannot be converted.");
		}
	}
1123687
public void statistic(InstanceSet instSet){	
		int numSamples = instSet.size();
		for(int i=0;i<numSamples;i++){
			if(i%1000==0)
				System.out.println((i+0.0)/numSamples);
			Instance inst=instSet.get(i);
			oneStepStatistic(inst);
		}
	}
285525
private static long invokeStatisticsMethod(Object statistics, String methodName) {
		try {
			// getInMemoryHits, getCacheHits et getCacheMisses existent en v1.2.1 et v1.2.3
			// mais avec int comme résultat et existent depuis v1.2.4 avec long comme résultat
			// donc on cast en Number et non en Integer ou en Long
			final Number result = (Number) Statistics.class.getMethod(methodName, (Class<?>[]) null)
					.invoke(statistics, (Object[]) null);
			return result.longValue();
		} catch (final NoSuchMethodException e) {
			throw new IllegalArgumentException(e);
		} catch (final InvocationTargetException e) {
			throw new IllegalStateException(e.getCause());
		} catch (final IllegalAccessException e) {
			throw new IllegalStateException(e);
		}
	}