@Override public void initialize(Configuration conf, ResourceUsageMetrics metrics, ResourceCalculatorPlugin monitor, Progressive progress) { this.monitor = monitor; this.progress = progress; // get the target CPU usage targetCpuUsage = metrics.getCumulativeCpuUsage(); if (targetCpuUsage <= 0 ) { enabled = false; return; } else { enabled = true; } emulationInterval = conf.getFloat(CPU_EMULATION_PROGRESS_INTERVAL, DEFAULT_EMULATION_FREQUENCY); // calibrate the core cpu-usage utility emulatorCore.calibrate(monitor, targetCpuUsage); // initialize the states lastSeenProgress = 0; lastSeenCpuUsage = 0; }
@Override public void initialize(Configuration conf, ResourceUsageMetrics metrics, ResourceCalculatorPlugin monitor, Progressive progress) { this.progress = progress; // get the target heap usage targetHeapUsageInMB = metrics.getHeapUsage() / ONE_MB; if (targetHeapUsageInMB <= 0 ) { enabled = false; return; } else { // calibrate the core heap-usage utility emulatorCore.initialize(monitor, targetHeapUsageInMB); enabled = true; } emulationInterval = conf.getFloat(HEAP_EMULATION_PROGRESS_INTERVAL, DEFAULT_EMULATION_PROGRESS_INTERVAL); minFreeHeapRatio = conf.getFloat(MIN_HEAP_FREE_RATIO, DEFAULT_MIN_FREE_HEAP_RATIO); heapLoadRatio = conf.getFloat(HEAP_LOAD_RATIO, DEFAULT_HEAP_LOAD_RATIO); prevEmulationProgress = 0; }
/** * Configure the {@link ResourceUsageMatcher} to load the configured plugins * and initialize them. */ @SuppressWarnings("unchecked") public void configure(Configuration conf, ResourceCalculatorPlugin monitor, ResourceUsageMetrics metrics, Progressive progress) { Class[] plugins = conf.getClasses(RESOURCE_USAGE_EMULATION_PLUGINS); if (plugins == null) { System.out.println("No resource usage emulator plugins configured."); } else { for (Class clazz : plugins) { if (clazz != null) { if (ResourceUsageEmulatorPlugin.class.isAssignableFrom(clazz)) { ResourceUsageEmulatorPlugin plugin = (ResourceUsageEmulatorPlugin) ReflectionUtils.newInstance(clazz, conf); emulationPlugins.add(plugin); } else { throw new RuntimeException("Misconfigured resource usage plugins. " + "Class " + clazz.getClass().getName() + " is not a resource " + "usage plugin as it does not extend " + ResourceUsageEmulatorPlugin.class.getName()); } } } } // initialize the emulators once all the configured emulator plugins are // loaded for (ResourceUsageEmulatorPlugin emulator : emulationPlugins) { emulator.initialize(conf, metrics, monitor, progress); } }
/** * Initialize the plugin. This might involve * - initializing the variables * - calibrating the plugin */ void initialize(Configuration conf, ResourceUsageMetrics metrics, ResourceCalculatorPlugin monitor, Progressive progress);