close
The Wayback Machine - https://web.archive.org/web/20200814010156/https://github.com/KwaiAppTeam/KOOM/wiki/Advanced-Custom-Feature
Skip to content

Advanced Custom Feature

李锐 edited this page Aug 11, 2020 · 3 revisions

Adjusting Monitor params

 //Example of how to set custom config.
public void customConfig() {
    KConfig kConfig = new KConfig.KConfigBuilder()
            .heapRatio(85.0f) //heap occupied ration in percent, 85.0f means use 85% memory of max heap
            .rootDir(this.getCacheDir().getAbsolutePath()) //root dir stores report and hprof files
            .heapOverTimes(3) //heap max times of over heap's used threshold
            .build();
    KOOM.getInstance().setKConfig(kConfig);
}

Setting custom logger

//Example of how to set custom logger.
public void customLogger() {
    KOOM.getInstance().setLogger(new KLog.KLogger() {
      @Override
      public void i(String TAG, String msg) {
        //get the log of info level
      }

      @Override
      public void d(String TAG, String msg) {
        //get the log of debug level
      }

      @Override
      public void e(String TAG, String msg) {
        //get the log of error level
      }
    });
}

Manually Dump Hprof

//Example of dump hprof directly
public void customDump() {
  //Same with StandardHeapDumper StripHprofHeapDumper
  new ForkJvmHeapDumper().dump("absolute-path");
}
You can’t perform that action at this time.