<commit_before>package tools.descartes.petsupplystore.dockermemoryconfigurator;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;

/**
 * Configures the Tomcat heap space inside a docker container.
 * Implemented in Java to compensate for potentially missing GNU/Linux tools
 * inside the container when running this using bash.
 * @author <NAME>
 *
 */
public final class Configurator {
    
	private static final long DEFAULT_PERCENTAGE = 80;
	private static final String CATALINA_SH_PATH = "/usr/local/tomcat/bin/catalina.sh";
	
	private Configurator() {
		
	}
	
	/**
	 * Runs the configurator.
	 * @param args Percentage of total memory to be used for heap as the only parameter.
	 */
	public static void main(String[] args) {
        long percentage = readPercentage(args);
        long totalkb = readTotalMemoryInKB();
        long cgroupkb = readCGroupMemoryInKB();
        
        System.out.println("Total Host Memory = " + totalkb + " KiB");
        System.out.println("Container CGroup Limit = " + cgroupkb + " KiB");
        
        if (cgroupkb != 0 && totalkb != 0 && cgroupkb < totalkb) {
        	long heapkb = (cgroupkb * 100L) / percentage;
        	System.out.println("Setting heap space to " + heapkb + " KiB");
        	modifyCatalinash(heapkb);
        	
        }
    }
	
	
	private static long readPercentage(String[] args) {
		long percentage = DEFAULT_PERCENTAGE;
		if (args.length > 0) {
			String arg0 = args[0].trim();<commit_msg>fixed a stupid percentage error<commit_after>package tools.descartes.petsupplystore.dockermemoryconfigurator;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;

/**
 * Configures the Tomcat heap space inside a docker container.
 * Implemented in Java to compensate for potentially missing GNU/Linux tools
 * inside the container when running this using bash.
 * @author <NAME>
 *
 */
public final class Configurator {
    
	private static final long DEFAULT_PERCENTAGE = 80;
	private static final String CATALINA_SH_PATH = "/usr/local/tomcat/bin/catalina.sh";
	
	private Configurator() {
		
	}
	
	/**
	 * Runs the configurator.
	 * @param args Percentage of total memory to be used for heap as the only parameter.
	 */
	public static void main(String[] args) {
        long percentage = readPercentage(args);
        long totalkb = readTotalMemoryInKB();
        long cgroupkb = readCGroupMemoryInKB();
        
        System.out.println("Total Host Memory = " + totalkb + " KiB");
        System.out.println("Container CGroup Limit = " + cgroupkb + " KiB");
        
        if (cgroupkb != 0 && totalkb != 0 && cgroupkb < totalkb) {
        	long heapkb = (cgroupkb * percentage) / 100L;
        	System.out.println("Setting heap space to " + heapkb + " KiB");
        	modifyCatalinash(heapkb);
        	
        }
    }
	
	
	private static long readPercentage(String[] args) {
		long percentage = DEFAULT_PERCENTAGE;
		if (args.length > 0) {
			String arg0 = args[0].trim();
{'fraction_non_alphanumeric': 0.1009009009009009, 'fraction_numerical': 0.006006006006006006, 'mean_word_length': 3.2325285895806863, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6278883', 'n_tokens_mistral': 1065, 'n_tokens_neox': 988, 'n_words': 283}