java.lang.Object
net.i2p.router.Tuner.ThreadCpuTable
- Enclosing class:
Tuner
Thread-id keyed sample state for
Tuner.sampleStageCpu(): per live thread, which Tuner.CPU_STAGES entry its name matched and the CPU nanoseconds recorded at the previous sample.Open addressed with linear probing. Entries are never deleted one by one: a cycle republishes the still-live ids into a spare table and swaps it in, so a dead thread's stage and baseline leave together.
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final longNo CPU baseline recorded for this id yet.(package private) static final intName read, and it matches noTuner.CPU_STAGESprefix.(package private) static final intName not read yet; needs aThreadInfolookup next cycle.Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescription(package private) voidbeginCycle(long[] ids, int count) Start a sample cycle: carry stage and CPU baseline forward for the given live thread ids and make them the table's contents.(package private) longcpuOf(long id) CPU nanoseconds recorded at the previous sample.(package private) voidsetCpu(long id, long cpu) Record the CPU nanoseconds for this sample.(package private) voidsetStage(long id, int stage) Record the stage a thread id belongs to.(package private) intsize()Number of live threads currently tracked.(package private) intstageOf(long id) Stage recorded for a thread id.
Field Details
NO_STAGE
static final int NO_STAGEName read, and it matches noTuner.CPU_STAGESprefix.- See Also:
UNRESOLVED
NO_CPU
Constructor Details
ThreadCpuTable
ThreadCpuTable()Empty table; threads are admitted by the firstbeginCycle(long[], int).
Method Details
beginCycle
void beginCycle(long[] ids, int count) Start a sample cycle: carry stage and CPU baseline forward for the given live thread ids and make them the table's contents.An id the previous generation did not hold enters
UNRESOLVEDwithNO_CPU; an id no longer reported drops out. A reused id whose predecessor was still live one cycle ago does carry a stale entry forward —Tuner.sampleStageCpu()spots it as a backwards CPU counter and resets the stage.- Parameters:
ids- live thread ids from the MXBeancount- number of valid entries inids
stageOf
int stageOf(long id) Stage recorded for a thread id.- Parameters:
id- 1-based MXBean thread id from the current sample- Returns:
- index into
Tuner.CPU_STAGES, orNO_STAGE/UNRESOLVED
setStage
void setStage(long id, int stage) Record the stage a thread id belongs to.- Parameters:
id- 1-based MXBean thread id from the current samplestage-Tuner.CPU_STAGESindex,NO_STAGEorUNRESOLVED
cpuOf
long cpuOf(long id) CPU nanoseconds recorded at the previous sample.- Parameters:
id- 1-based MXBean thread id from the current sample- Returns:
- the baseline, or
NO_CPUwhen there is none
setCpu
void setCpu(long id, long cpu) Record the CPU nanoseconds for this sample.- Parameters:
id- 1-based MXBean thread id from the current samplecpu- nanoseconds, as returned by the MXBean
size
int size()Number of live threads currently tracked.- Returns:
- count of occupied slots in the live generation