@Override
    public void run() {
      int lastCreateTime = Integer.MAX_VALUE;
      int loadedEntries = 0;
      try {
        do {
          List<RuntimeStat> rs = Hive.get().getMSC().getRuntimeStats(batchSize, lastCreateTime);
          if (rs.size() == 0) {
            break;
          }
          for (RuntimeStat thriftStat : rs) {
            loadedEntries += thriftStat.getWeight();
            lastCreateTime = Math.min(lastCreateTime, thriftStat.getCreateTime() - 1);
            try {
              ss.load(decode(thriftStat));
            } catch (IOException e) {
              logException("Exception while loading runtime stats", e);
            }
          }
        } while (batchSize > 0 && loadedEntries < maxEntriesToLoad);
      } catch (TException | HiveException e) {
        logException("Exception while reading metastore runtime stats", e);
      }
    }
Decorates a StatSource to be loaded and persisted in the metastore as well.
ql/src/java/org/apache/hadoop/hive/ql/plan/mapper/MetastoreStatsConnector.java