<commit_before><?php
/**
 * Class for preprocessing callgrind files.
 * 
 * Information from the callgrind file is extracted and written in a binary format for 
 * fast random access.
 * 
 * @see http://code.google.com/p/webgrind/wiki/PreprocessedFormat
 * @see http://valgrind.org/docs/manual/cl-format.html
 * @package Webgrind
 * @author <NAME>
 **/
class Webgrind_Preprocessor
{

	/**
	 * Fileformat version. Embedded in the output for parsers to use.
	 */
	const FILE_FORMAT_VERSION = 6;

	/**
	 * Binary number format used.
	 * @see http://php.net/pack
	 */
	const NR_FORMAT = 'V';

	/**
	 * Size, in bytes, of the above number format
	 */
	const NR_SIZE = 4;

	/**
	 * String name of main function
	 */
	const ENTRY_POINT = '{main}';


	/**
	 * Extract information from $inFile and store in preprocessed form in $outFile
	 *
	 * @param string $inFile Callgrind file to read
	 * @param string $outFile File to write preprocessed data to
	 * @return void
	 **/
	static function parse($inFile, $outFile)
	{
		$in = @fopen($inFile, 'rb');
		if(!$in)
			throw new Exception('Could not open '.$inFile.' for reading.');
		$out = @fopen($outFile, 'w+b');
		if(!$out)
			throw new Exception('Could not open '.$outFile.' for writing.');
		
		$nextFuncNr = 0;
		$functions = array();
		$headers = array();
		$calls = array();
		
		
		// Read information into memory
		while(($line = fgets($in))){
			if(substr($line,0,3)==='fl='){
				// Found invocation of function. Read functionname
				list($function) = fscanf($in,"fn=%s");
				if(!isset($functions[$function])){
					$functions[$function] = array('filename'=>substr(trim($line),3), 'invocationCount'=>0,'nr'=>$nextFuncNr++,'count'=>0,'summedSelfCost'=>0,'summedInclusiveCost'=>0,'calledFromInformation'=>array(),'subCallInformation'=>array());
				} 
				$functions[$function]['invocationCount']++;
				// Special case for ENTRY_POINT - it contains summary header
				if(self::ENTRY_POINT == $function){
					fgets($in);				<commit_msg>[FIXED] Fix for issue #34 Problems with spaces in requires of files with spaces in their path.<commit_after><?php
/**
 * Class for preprocessing callgrind files.
 * 
 * Information from the callgrind file is extracted and written in a binary format for 
 * fast random access.
 * 
 * @see http://code.google.com/p/webgrind/wiki/PreprocessedFormat
 * @see http://valgrind.org/docs/manual/cl-format.html
 * @package Webgrind
 * @author <NAME>
 **/
class Webgrind_Preprocessor
{

	/**
	 * Fileformat version. Embedded in the output for parsers to use.
	 */
	const FILE_FORMAT_VERSION = 6;

	/**
	 * Binary number format used.
	 * @see http://php.net/pack
	 */
	const NR_FORMAT = 'V';

	/**
	 * Size, in bytes, of the above number format
	 */
	const NR_SIZE = 4;

	/**
	 * String name of main function
	 */
	const ENTRY_POINT = '{main}';


	/**
	 * Extract information from $inFile and store in preprocessed form in $outFile
	 *
	 * @param string $inFile Callgrind file to read
	 * @param string $outFile File to write preprocessed data to
	 * @return void
	 **/
	static function parse($inFile, $outFile)
	{
		$in = @fopen($inFile, 'rb');
		if(!$in)
			throw new Exception('Could not open '.$inFile.' for reading.');
		$out = @fopen($outFile, 'w+b');
		if(!$out)
			throw new Exception('Could not open '.$outFile.' for writing.');
		
		$nextFuncNr = 0;
		$functions = array();
		$headers = array();
		$calls = array();
		
		
		// Read information into memory
		while(($line = fgets($in))){
			if(substr($line,0,3)==='fl='){
				// Found invocation of function. Read functionname
				list($function) = fscanf($in,"fn=%[^\n]s");
				if(!isset($functions[$function])){
					$functions[$function] = array('filename'=>substr(trim($line),3), 'invocationCount'=>0,'nr'=>$nextFuncNr++,'count'=>0,'summedSelfCost'=>0,'summedInclusiveCost'=>0,'calledFromInformation'=>array(),'subCallInformation'=>array());
				} 
				$functions[$function]['invocationCount']++;
				// Special case for ENTRY_POINT - it contains summary header
				if(self::ENTRY_POINT == $function){
					fgets($in);				
{'fraction_non_alphanumeric': 0.16395864106351551, 'fraction_numerical': 0.0054160512063023145, 'mean_word_length': 3.808284023668639, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '4406279', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1276, 'n_words': 356}