<commit_before><?php
abstract class f_util_MemoryUtils
{

    public static $limit = null;

    public static function getLimit()
    {
	if (is_null(self::$limit))
	{
	    $limit = trim(ini_get('memory_limit'));
	    switch (strtolower($limit{strlen($limit) - 1}))
	    {
	       case 'g':
		   $limit *= 1024;
	       case 'm':
		   $limit *= 1024;
	       case 'k':
		   $limit *= 1024;
	    }
	    self::$limit = $limit;
	}
	return self::$limit;
    }

    public static function getUsage($unit = null, $round = 2)
    {
	$usage = memory_get_usage();
	if (!is_null($unit))
	{
	    switch (strtolower($unit))
	    {
	       case 'g':
		   $usage /= 1024;
	       case 'm':
		   $usage /= 1024;
	       case 'k':
		   $usage /= 1024;
	    }
	    $usage = round($usage, $round) . $unit;
	}
	return $usage;
    }

    public static function getLoad($asPercentage = false)
    {
	$load = self::getUsage() / self::getLimit();
	if ($asPercentage)
	{
	    return round($load * 100, 2);
	}
	return round($load, 2);
    }

    public static function hasExceeded($threshold, $asPercentage = false)
    {
	return (self::getLoad($asPercentage) > $threshold);
    }

    public static function seeGlobalMemoryConsumption()
    {
	    //http://www.procata.com/blog/archives/2004/05/27/rephlux-and-php-memory-usage/
	    foreach (array_keys($GLOBALS) as $key) {
		    echo "$key=" . strlen(serialize($GLOBALS[$key]))."<br>";
	    }
    }<commit_msg>[FIX #25421] MemoryUtils getLoad()<commit_after><?php
abstract class f_util_MemoryUtils
{

    public static $limit = null;

    public static function getLimit()
    {
	if (is_null(self::$limit))
	{
	    $limit = trim(ini_get('memory_limit'));
	    switch (strtolower($limit{strlen($limit) - 1}))
	    {
	       case 'g':
		   $limit *= 1024;
	       case 'm':
		   $limit *= 1024;
	       case 'k':
		   $limit *= 1024;
	    }
	    self::$limit = $limit;
	}
	return self::$limit;
    }

    public static function getUsage($unit = null, $round = 2)
    {
	$usage = memory_get_usage();
	if (!is_null($unit))
	{
	    switch (strtolower($unit))
	    {
	       case 'g':
		   $usage /= 1024;
	       case 'm':
		   $usage /= 1024;
	       case 'k':
		   $usage /= 1024;
	    }
	    $usage = round($usage, $round) . $unit;
	}
	return $usage;
    }

    public static function getLoad($asPercentage = false)
    {
    	$limit = self::getLimit();
    	if ($limit == -1)
    	{
    		return -1;
    	}
	$load = self::getUsage() / self::getLimit();
	if ($asPercentage)
	{
	    return round($load * 100, 2);
	}
	return round($load, 2);
    }

    public static function hasExceeded($threshold, $asPercentage = false)
    {
    	$load = self::getLoad($asPercentage);
    	if ($load == -1)
    	{
    		return false;
    	}
	return $load > $threshold;
    }

    public static function seeGlobalMemoryConsumption()
    {
	    //http://www.procata.com/blog/archives/2004/05/27/rephlux-and-php-memory-usage/
	    foreach (array_keys($GLOBALS) as $key) {
		    echo "$key=" . strlen(serialize($GLOBALS[$key]))."<br>";
	    }
    }
{'fraction_non_alphanumeric': 0.16672125777923355, 'fraction_numerical': 0.028169014084507043, 'mean_word_length': 2.412290502793296, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7629486', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1059, 'n_words': 225}