use of java.math.BigInteger in project hadoop by apache.
the class ProcfsBasedProcessTree method getCpuUsagePercent.
/**
* Get the CPU usage by all the processes in the process-tree in Unix.
* Note: UNAVAILABLE will be returned in case when CPU usage is not
* available. It is NOT advised to return any other error code.
*
* @return percentage CPU usage since the process-tree was created,
* {@link #UNAVAILABLE} if CPU usage cannot be calculated or not available.
*/
@Override
public float getCpuUsagePercent() {
BigInteger processTotalJiffies = getTotalProcessJiffies();
cpuTimeTracker.updateElapsedJiffies(processTotalJiffies, clock.getTime());
return cpuTimeTracker.getCpuTrackerUsagePercent();
}
use of java.math.BigInteger in project hadoop by apache.
the class ProcfsBasedProcessTree method getTotalProcessJiffies.
private BigInteger getTotalProcessJiffies() {
BigInteger totalStime = BigInteger.ZERO;
long totalUtime = 0;
for (ProcessInfo p : processTree.values()) {
if (p != null) {
totalUtime += p.getUtime();
totalStime = totalStime.add(p.getStime());
}
}
return totalStime.add(BigInteger.valueOf(totalUtime));
}
use of java.math.BigInteger in project hadoop by apache.
the class WindowsBasedProcessTree method getCpuUsagePercent.
/**
* Get the CPU usage by all the processes in the process-tree in Windows.
* Note: UNAVAILABLE will be returned in case when CPU usage is not
* available. It is NOT advised to return any other error code.
*
* @return percentage CPU usage since the process-tree was created,
* {@link #UNAVAILABLE} if CPU usage cannot be calculated or not available.
*/
@Override
public float getCpuUsagePercent() {
BigInteger processTotalMs = getTotalProcessMs();
cpuTimeTracker.updateElapsedJiffies(processTotalMs, clock.getTime());
return cpuTimeTracker.getCpuTrackerUsagePercent();
}
use of java.math.BigInteger in project hbase by apache.
the class Bytes method iterateOnSplits.
/**
* Iterate over keys within the passed range.
*/
public static Iterable<byte[]> iterateOnSplits(final byte[] a, final byte[] b, boolean inclusive, final int num) {
byte[] aPadded;
byte[] bPadded;
if (a.length < b.length) {
aPadded = padTail(a, b.length - a.length);
bPadded = b;
} else if (b.length < a.length) {
aPadded = a;
bPadded = padTail(b, a.length - b.length);
} else {
aPadded = a;
bPadded = b;
}
if (compareTo(aPadded, bPadded) >= 0) {
throw new IllegalArgumentException("b <= a");
}
if (num <= 0) {
throw new IllegalArgumentException("num cannot be <= 0");
}
byte[] prependHeader = { 1, 0 };
final BigInteger startBI = new BigInteger(add(prependHeader, aPadded));
final BigInteger stopBI = new BigInteger(add(prependHeader, bPadded));
BigInteger diffBI = stopBI.subtract(startBI);
if (inclusive) {
diffBI = diffBI.add(BigInteger.ONE);
}
final BigInteger splitsBI = BigInteger.valueOf(num + 1);
//when diffBI < splitBI, use an additional byte to increase diffBI
if (diffBI.compareTo(splitsBI) < 0) {
byte[] aPaddedAdditional = new byte[aPadded.length + 1];
byte[] bPaddedAdditional = new byte[bPadded.length + 1];
for (int i = 0; i < aPadded.length; i++) {
aPaddedAdditional[i] = aPadded[i];
}
for (int j = 0; j < bPadded.length; j++) {
bPaddedAdditional[j] = bPadded[j];
}
aPaddedAdditional[aPadded.length] = 0;
bPaddedAdditional[bPadded.length] = 0;
return iterateOnSplits(aPaddedAdditional, bPaddedAdditional, inclusive, num);
}
final BigInteger intervalBI;
try {
intervalBI = diffBI.divide(splitsBI);
} catch (Exception e) {
LOG.error("Exception caught during division", e);
return null;
}
final Iterator<byte[]> iterator = new Iterator<byte[]>() {
private int i = -1;
@Override
public boolean hasNext() {
return i < num + 1;
}
@Override
public byte[] next() {
i++;
if (i == 0)
return a;
if (i == num + 1)
return b;
BigInteger curBI = startBI.add(intervalBI.multiply(BigInteger.valueOf(i)));
byte[] padded = curBI.toByteArray();
if (padded[1] == 0)
padded = tail(padded, padded.length - 2);
else
padded = tail(padded, padded.length - 1);
return padded;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
return new Iterable<byte[]>() {
@Override
public Iterator<byte[]> iterator() {
return iterator;
}
};
}
use of java.math.BigInteger in project hbase by apache.
the class ByteBufferUtils method toBigDecimal.
/**
* Reads a BigDecimal value at the given buffer's offset.
* @param buffer
* @param offset
* @return BigDecimal value at offset
*/
public static BigDecimal toBigDecimal(ByteBuffer buffer, int offset, int length) {
if (buffer == null || length < Bytes.SIZEOF_INT + 1 || (offset + length > buffer.limit())) {
return null;
}
int scale = toInt(buffer, offset);
byte[] tcBytes = new byte[length - Bytes.SIZEOF_INT];
copyFromBufferToArray(tcBytes, buffer, offset + Bytes.SIZEOF_INT, 0, length - Bytes.SIZEOF_INT);
return new BigDecimal(new BigInteger(tcBytes), scale);
}
Aggregations