Java Memory Information prettyPrintMemoryPerSecond(long rate)

Here you can find the source of prettyPrintMemoryPerSecond(long rate)

Description

pretty Print Memory Per Second

License

Apache License

Declaration

public static String prettyPrintMemoryPerSecond(long rate) 

Method Source Code

//package com.java2s;
/*//w w  w.  j  a v a  2 s.co m
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    public static String prettyPrintMemoryPerSecond(long rate) {
        if (rate >= 1 << 30)
            return String.format("%.3fGiB/s", rate / (double) (1 << 30));
        if (rate >= 1 << 20)
            return String.format("%.3fMiB/s", rate / (double) (1 << 20));
        return String.format("%.3fKiB/s", rate / (double) (1 << 10));
    }

    public static String prettyPrintMemoryPerSecond(long bytes, long timeInNano) {
        // We can't sanely calculate a rate over 0 nanoseconds
        if (timeInNano == 0)
            return "NaN  KiB/s";

        long rate = (long) (((double) bytes / timeInNano) * 1000 * 1000 * 1000);

        return prettyPrintMemoryPerSecond(rate);
    }
}

Related

  1. getSummaryMemoryReportHeader()
  2. getTotalMemoryStringInMb()
  3. parseMemory(String s, int def)
  4. parseMemorySize(String arg)
  5. prettyPrintMemory(long size, boolean includeSpace)
  6. printMemory()
  7. printMemory()
  8. printMemory(String label)
  9. printMemory(String str)