コード例 #1
0
  private void printInUse(boolean verbose) {
    if (DEBUG_PRINT_MEM) {

      System.out.print(
          "DIRECT: given="
              + bytesOut / 1024 / 1024
              + "MB, returned="
              + bytesIn / 1024 / 1024
              + "MB, ");

      long in_use = bytesOut - bytesIn;
      if (in_use < 1024 * 1024) System.out.print("in use=" + in_use + "B, ");
      else System.out.print("in use=" + in_use / 1024 / 1024 + "MB, ");

      long free = bytesFree();
      if (free < 1024 * 1024) System.out.print("free=" + free + "B");
      else System.out.print("free=" + free / 1024 / 1024 + "MB");

      System.out.println();

      CacheFileManager cm = null;

      try {
        cm = CacheFileManagerFactory.getSingleton();

      } catch (Throwable e) {

        Debug.printStackTrace(e);
      }

      synchronized (handed_out) {
        Iterator it = handed_out.values().iterator();

        Map cap_map = new TreeMap();
        Map alloc_map = new TreeMap();

        while (it.hasNext()) {

          DirectByteBuffer db = (DirectByteBuffer) it.next();

          if (verbose) {
            String trace = db.getTraceString();

            if (trace != null) {

              System.out.println(trace);
            }
          }

          Integer cap = new Integer(db.getBufferInternal().capacity());
          Byte alloc = new Byte(db.getAllocator());

          myInteger c = (myInteger) cap_map.get(cap);

          if (c == null) {

            c = new myInteger();

            cap_map.put(cap, c);
          }

          c.value++;

          myInteger a = (myInteger) alloc_map.get(alloc);

          if (a == null) {

            a = new myInteger();

            alloc_map.put(alloc, a);
          }

          a.value++;
        }

        it = cap_map.keySet().iterator();

        while (it.hasNext()) {

          Integer key = (Integer) it.next();
          myInteger count = (myInteger) cap_map.get(key);

          if (key.intValue() < 1024) {

            System.out.print("[" + key.intValue() + " x " + count.value + "] ");

          } else {

            System.out.print("[" + key.intValue() / 1024 + "K x " + count.value + "] ");
          }
        }

        System.out.println();

        it = alloc_map.keySet().iterator();

        while (it.hasNext()) {

          Byte key = (Byte) it.next();
          myInteger count = (myInteger) alloc_map.get(key);

          System.out.print(
              "[" + DirectByteBuffer.AL_DESCS[key.intValue()] + " x " + count.value + "] ");
        }

        if (cm != null) {

          CacheFileManagerStats stats = cm.getStats();

          System.out.print(" - Cache: ");

          System.out.print("sz=" + stats.getSize());
          System.out.print(",us=" + stats.getUsedSize());
          System.out.print(",cw=" + stats.getBytesWrittenToCache());
          System.out.print(",cr=" + stats.getBytesReadFromCache());
          System.out.print(",fw=" + stats.getBytesWrittenToFile());
          System.out.print(",fr=" + stats.getBytesReadFromFile());
        }

        System.out.println();

        if (DEBUG_HANDOUT_SIZES) {
          it = size_counts.entrySet().iterator();

          String str = "";

          while (it.hasNext()) {

            Map.Entry entry = (Map.Entry) it.next();

            str += (str.length() == 0 ? "" : ",") + entry.getKey() + "=" + entry.getValue();
          }

          System.out.println(str);
        }

        String str = "";

        for (int i = 0; i < slice_entries.length; i++) {

          boolean[] allocs = slice_allocs[i];
          int alloc_count = 0;
          for (int j = 0; j < allocs.length; j++) {
            if (allocs[j]) {
              alloc_count++;
            }
          }
          str +=
              (i == 0 ? "" : ",")
                  + "["
                  + SLICE_ENTRY_SIZES[i]
                  + "]f="
                  + slice_entries[i].size()
                  + ",a="
                  + (alloc_count * SLICE_ENTRY_ALLOC_SIZES[i])
                  + ",u="
                  + slice_use_count[i];
        }

        System.out.println("slices: " + str);
      }

      if (DEBUG_FREE_SIZES) {
        System.out.print("free block sizes: ");

        synchronized (poolsLock) {
          Iterator it = buffersMap.keySet().iterator();
          while (it.hasNext()) {
            Integer keyVal = (Integer) it.next();
            ArrayList bufferPool = (ArrayList) buffersMap.get(keyVal);

            int blocksize = keyVal.intValue();
            int blockfootprint = keyVal.intValue() * bufferPool.size();
            if (blockfootprint == 0) continue;
            String blocksuffix = "";
            if (blocksize > 1024) {
              blocksize /= 1024;
              blocksuffix = "k";
            }
            if (blocksize > 1024) {
              blocksize /= 1024;
              blocksuffix = "M";
            }
            String footsuffix = "";
            if (blockfootprint > 1024) {
              blockfootprint /= 1024;
              footsuffix = "k";
            }
            if (blockfootprint > 1024) {
              blockfootprint /= 1024;
              footsuffix = "M";
            }

            System.out.print(
                "[" + blocksize + blocksuffix + ":" + blockfootprint + footsuffix + "] ");
          }
        }

        System.out.println();
      }

      long free_mem = Runtime.getRuntime().freeMemory() / 1024 / 1024;
      long max_mem = Runtime.getRuntime().maxMemory() / 1024 / 1024;
      long total_mem = Runtime.getRuntime().totalMemory() / 1024 / 1024;
      System.out.println(
          "HEAP: max=" + max_mem + "MB, total=" + total_mem + "MB, free=" + free_mem + "MB");
      System.out.println();
    }
  }