@Override
    public int compare(MetricsSource o1, MetricsSource o2) {
      if (o1 != null && o2 != null
          && o1 instanceof LockMetricSource && o2 instanceof LockMetricSource) {
        LockMetricSource lms1 = (LockMetricSource)o1;
        LockMetricSource lms2 = (LockMetricSource)o2;

        long totalMs1 = (lms1.readLockWaitTimeTotal.value() / 1000000L)
                        + (lms1.writeLockWaitTimeTotal.value() / 1000000L);
        long totalMs2 = (lms2.readLockWaitTimeTotal.value() / 1000000L)
                        + (lms2.writeLockWaitTimeTotal.value() / 1000000L);

        // sort descending by total lock time
        if (totalMs1 < totalMs2) {
          return 1;
        }

        if (totalMs1 > totalMs2) {
          return -1;
        }

        // sort by label (ascending) if lock time is the same
        return lms1.lockLabel.compareTo(lms2.lockLabel);
      }

      return 0;
    }
Helper class to compare two <code>LockMetricSource</code> instances.
This <code>Comparator</code> class can be used to sort a list of <code>
LockMetricSource</code> instances in descending order by their total lock
wait time.
llap-common/src/java/org/apache/hadoop/hive/llap/metrics/ReadWriteLockMetrics.java