Пример #1
0
  public static void premain(String agentArgs, Instrumentation inst) throws FileNotFoundException {
    Config config = Config.readFromFile(Config.DEFAULT_FILE_CONFIG_LOCATION);
    globalInst = inst;

    inst.addTransformer(new BasicClassFileTransformer(config));

    ResourceMonitor rm = config.getResourceMonitor();
    if (rm.isActive() && hardwareThread == null) {
      //            installGCMonitoring();
      List<HardwareDaemonWriter> writers = new ArrayList<HardwareDaemonWriter>();

      if (rm.isDebug()) {
        System.out.println("use debug");
        writers.add(new HardwareDaemonWriterMockImpl());
      } else {
        System.out.println("not using debug");
      }
      if (rm.isSendToCollector())
        try {
          writers.add(new HardwareDaemonWriterCollectorImpl(config));
        } catch (IOException e) {
          e.printStackTrace();
        }
      hardwareThread = new HardwareDaemon(config, writers);
      hardwareThread.start();
    }
  }
Пример #2
0
 public static long getObjectSize(Object object) {
   if (globalInst == null) {
     throw new IllegalStateException("Agent not initialized");
   }
   if (object == null) {
     return 0;
   } else {
     long totalSize = globalInst.getObjectSize(object);
     if (object instanceof List) {
       List list = (List) object;
       for (int i = 0; i < list.size(); i++) {
         if (list.get(i) != null) {
           totalSize += globalInst.getObjectSize(list.get(i));
         }
       }
     }
     globalInst.getObjectSize(object);
     return totalSize;
   }
 }