java.lang.Object
net.i2p.router.Tuner.ThreadCpuTable
Enclosing class:
Tuner

static final class Tuner.ThreadCpuTableextends Object
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

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final long
    No CPU baseline recorded for this id yet.
    (package private) static final int
    Name read, and it matches no Tuner.CPU_STAGES prefix.
    (package private) static final int
    Name not read yet; needs a ThreadInfo lookup next cycle.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Empty table; threads are admitted by the first beginCycle(long[], int).
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    (package private) 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.
    (package private) long
    cpuOf(long id)
    CPU nanoseconds recorded at the previous sample.
    (package private) void
    setCpu(long id, long cpu)
    Record the CPU nanoseconds for this sample.
    (package private) void
    setStage(long id, int stage)
    Record the stage a thread id belongs to.
    (package private) int
    Number of live threads currently tracked.
    (package private) int
    stageOf(long id)
    Stage recorded for a thread id.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • 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 UNRESOLVED with NO_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 MXBean
      count - number of valid entries in ids
    • 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, or NO_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 sample
      stage - Tuner.CPU_STAGES index, NO_STAGE or UNRESOLVED
    • 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_CPU when 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 sample
      cpu - nanoseconds, as returned by the MXBean
    • size

      int size()
      Number of live threads currently tracked.
      Returns:
      count of occupied slots in the live generation