public static int calcHertz()

in metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/meter/os/cpu/CpuUtils.java [78:182]


  public static int calcHertz() {
    double up1, up2, seconds;
    double jiffies;

    for (; ; ) {
      try {
        up1 = readUptimeTotal();
        jiffies = readProcStatTotal();
        up2 = readUptimeTotal();
      } catch (Throwable e) {
        LOGGER.error("Failed to calc hertz, should never happened, try again.", e);
        continue;
      }

      if (0 == (long) ((up2 - up1) * 1000.0 / up1)) {
        break;
      }
    }

    seconds = (up1 + up2) / 2;
    long hz = Math.round(jiffies / seconds / Runtime.getRuntime().availableProcessors());
    /* S/390 (sometimes) */
    if (isBetween(hz, 9, 11)) {
      return 10;
    }

    /* user-mode Linux */
    if (isBetween(hz, 18, 22)) {
      return 20;
    }

    /* ia64 emulator */
    if (isBetween(hz, 30, 34)) {
      return 32;
    }

    if (isBetween(hz, 48, 52)) {
      return 50;
    }

    if (isBetween(hz, 58, 61)) {
      return 60;
    }

    /* StrongARM /Shark */
    if (isBetween(hz, 62, 65)) {
      return 64;
    }

    /* normal Linux */
    if (isBetween(hz, 95, 105)) {
      return 100;
    }

    /* MIPS, ARM */
    if (isBetween(hz, 124, 132)) {
      return 128;
    }

    /* normal << 1 */
    if (isBetween(hz, 195, 204)) {
      return 200;
    }

    if (isBetween(hz, 247, 252)) {
      return 250;
    }

    if (isBetween(hz, 253, 260)) {
      return 256;
    }

    /* normal << 2 */
    if (isBetween(hz, 393, 408)) {
      return 400;
    }

    /* SMP WinNT */
    if (isBetween(hz, 410, 600)) {
      return 500;
    }

    /* normal << 3 */
    if (isBetween(hz, 790, 808)) {
      return 800;
    }

    /* ARM */
    if (isBetween(hz, 990, 1010)) {
      return 1000;
    }

    /* Alpha, ia64 */
    if (isBetween(hz, 1015, 1035)) {
      return 1024;
    }

    /* Alpha */
    if (isBetween(hz, 1180, 1220)) {
      return 1200;
    }

    LOGGER.warn("Unknown HZ value! ({}) Assume {}.\n", hz, 100);
    return 100;
  }