Commit ac86dc19 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

load and parse swap file

parent 6c65cc6a
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ class Metric(key: MetricKey) {
      return lst.toList

    // start searching the swapfile backwards from the last write position
    var swap_chunk = ListBuffer[(Long, Double)]()
    var swap_pos = swap.write_pos

    // we skip at least as many values as we've already seen in the rbuf. but
@@ -146,18 +147,19 @@ class Metric(key: MetricKey) {
    swap_pos -= (rbuf_seek_pos * swap.BLOCK_SIZE)

    while (swap_pos > 0) {
      println("LOAD_SWAP")
      var nxt = ListBuffer[(Long, Double)]()
      swap_chunk.clear

      // load the next chunk of samples from the swapfile
      swap_pos = swap.load_chunk(swap_pos, nxt)
      swap_pos = swap.load_chunk(swap_pos, swap_chunk)

      for (cur <- nxt)
      for (cur <- swap_chunk) {

        // skip if we already saw this sample in the rbuf search
        if (cur._1 < rbuf_last) {
          println("LOAD_SWAP", cur)
        }

      }
    }

    lst.toList
+13 −6
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ class SwapFile(metric_key: MetricKey) {

  // reads a chunk of of values from the swapfile at position into
  // the specified destionation list buffer
  def load_chunk(position: Int, dest: ListBuffer[(Long, Double)]) : Int = {
  def load_chunk(position: Int, dst: ListBuffer[(Long, Double)]) : Int = {
    var read_pos = 0
    println("load_chunk", position)

@@ -80,13 +80,20 @@ class SwapFile(metric_key: MetricKey) {
      }
    }

    println(javax.xml.bind.DatatypeConverter.printHexBinary(buffer.array))
    read_pos = chunk_size - BLOCK_SIZE

    buffer.limit(chunk_size)
    while (read_pos >= 0) {
      buffer.position(read_pos)

    while (buffer.remaining > 0) {
      // FIXPAUL: load the next chunk into lst
      println(buffer.getShort, buffer.getLong, buffer.getLong)
      if (buffer.getShort != 0x1717) {
        FnordMetric.error("file corrupted: " + file_name, false)
        return position - chunk_size
      }

      dst += ((buffer.getLong,
        java.lang.Double.longBitsToDouble(buffer.getLong)))

      read_pos -= BLOCK_SIZE
    }

    position - chunk_size