public double durationRatio(State ratioState, long now) {
            if (state == null) {
                return 0.0d;
            }
            long durationCurrent = now - startTime; // since last state change
            long durationDesired = ratioState == state ? durationCurrent : 0L;
            switch (ratioState) {
                case UNASSIGNED:
                    durationDesired += unassignedTotalTimeMs;
                    break;
                case RUNNING:
                    durationDesired += runningTotalTimeMs;
                    break;
                case PAUSED:
                    durationDesired += pausedTotalTimeMs;
                    break;
                case STOPPED:
                    durationDesired += stoppedTotalTimeMs;
                    break;
                case FAILED:
                    durationDesired += failedTotalTimeMs;
                    break;
                case DESTROYED:
                    durationDesired += destroyedTotalTimeMs;
                    break;
                case RESTARTING:
                    durationDesired += restartingTotalTimeMs;
                    break;
            }
            long total = durationCurrent + unassignedTotalTimeMs + runningTotalTimeMs + pausedTotalTimeMs +
                                 failedTotalTimeMs + destroyedTotalTimeMs + restartingTotalTimeMs;
            return total == 0.0d ? 0.0d : (double) durationDesired / total;
        }
Calculate the ratio of time spent in the specified state.

@param ratioState the state for which the ratio is to be calculated; may not be null
@param now        the current time in milliseconds
@return the ratio of time spent in the specified state to the time spent in all states
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/StateTracker.java