<commit_before>/**
 * @license Copyright (c) 2010 <NAME>
 * LICENSE: see the LICENSE.txt file. If file is missing, this file is subject
 * to the MIT License at: http://www.opensource.org/licenses/mit-license.php.
 */

/*
	File: debug.js
	wire plugin that logs timing and debug information about wiring context and object
	lifecycle events (e.g. creation, properties set, initialized, etc.).
*/
define([], function() {
	var timer = createTimer();

    function msg(text) {
		return "DEBUG: " + text;
	}

	function time(text, contextTimer) {
		return msg(text) + " (total: " + timer() + (contextTimer ? ", context: " + contextTimer() + ")" : ")");
	}

	/*
		Function: createTimer
		Creates a timer function that, when called, returns an object containing
		the total elapsed time since the timer was created, and the split time
		since the last time the timer was called.  All times in milliseconds

		Returns:
		Timer function
	*/
	function createTimer() {
		var start = new Date().getTime(),
			split = start;

		/*
			Function: getTime
			Returns the total elapsed time since this timer was created, and the
			split time since this getTime was last called.

			Returns:
			Object containing total and split times in milliseconds, plus a
			toString() function that is useful in logging the time.
		*/
		return function getTime() {
			var now = new Date().getTime(),
				total = now - start,
				splitTime = now - split;
			split = now;

			return {
				total: total,
				split: splitTime,
				toString: function() {
					return '' + splitTime + 'ms / ' + total + 'ms';
				}
			};
		};
	}
	
	/*
		Function: logProgress
		Logs progress info to the console
		
		Parameters:
			progress - progress Object with status, target, and spec
				- target - Object - object whose status is being reported
				- status - String - current status of object
				- spec: Any - wiring spec
	*/
	function logProgress(progress, contextTimer) {
		console.log(time('Object ' + progress.status, contextTimer), progress.target, progress.spec);
	}
	
	return {
		/*
			Function: wire$init
			Does any initialization for this plugin as soon as it is loaded. This is only
			called once when the plugin is loaded, and never again.
		*/
		wire$init: function() {
			console.log(time("All modules loaded"));
		},
		/*
			Function: wire$wire
			Invoked when wiring starts and provides two promises: one for wiring the context,
			and one for destroying the context.  Plugins should register resolve, reject, and
			promise handlers as necessary to do their work.
			
			Parameters:
				ready - promise that will be resolved when the context has been wired, rejected
					if there is an error during the wiring process, and will receive progress
					events for object creation, property setting, and initialization.
				destroy - promise that will be resolved when the context has been destroyed,
					rejected if there is an error while destroying the context, and will
					receive progress events for objects being destroyed.
		*/
		wire$wire: function(ready, destroy) {
			var contextTimer = createTimer();
			
			function contextTime(msg) {
				return time(msg, contextTimer);
			}
			
			function logContextProgress(progress) {
				logProgress(progress, contextTimer);
			}
			
			console.log(contextTime("Context init"));
			
			ready.then(
				function onContextReady(context) {
					console.log(contextTime("Context ready"), context);
				},
				function onContextError(err) {
					console.log(contextTime("Context ERROR: "), err);
				},
				logContextProgress
			);
			
			destroy.then(
				function onContextDestroyed() {
					// Do any context-specific plugin cleanup here
					console.log(contextTime("Context destroyed"));
				},
				function onContextDestroyError(err) {
					// Do any object-specific plugin cleanup here
					console.log(contextTime("Context destroy ERROR"), err);
				},
				logContextProgress
			);
		}
	};
	
});<commit_msg>Nicer formatting for debug timing, don't need to show per-operation time in total if context time is being logged<commit_after>/**
 * @license Copyright (c) 2010 <NAME>
 * LICENSE: see the LICENSE.txt file. If file is missing, this file is subject
 * to the MIT License at: http://www.opensource.org/licenses/mit-license.php.
 */

/*
	File: debug.js
	wire plugin that logs timing and debug information about wiring context and object
	lifecycle events (e.g. creation, properties set, initialized, etc.).
*/
define([], function() {
	var timer = createTimer();

    function msg(text) {
		return "DEBUG: " + text;
	}

	function time(text, contextTimer) {
		var all = timer(),
			timing = " (total: " + 
				(contextTimer
					? all.total + "ms, context: " + contextTimer()
					: all)
				+ ")";
		return msg(text) + timing;
	}

	/*
		Function: createTimer
		Creates a timer function that, when called, returns an object containing
		the total elapsed time since the timer was created, and the split time
		since the last time the timer was called.  All times in milliseconds

		Returns:
		Timer function
	*/
	function createTimer() {
		var start = new Date().getTime(),
			split = start;

		/*
			Function: getTime
			Returns the total elapsed time since this timer was created, and the
			split time since this getTime was last called.

			Returns:
			Object containing total and split times in milliseconds, plus a
			toString() function that is useful in logging the time.
		*/
		return function getTime() {
			var now = new Date().getTime(),
				total = now - start,
				splitTime = now - split;
			split = now;

			return {
				total: total,
				split: splitTime,
				toString: function() {
					return '' + splitTime + 'ms / ' + total + 'ms';
				}
			};
		};
	}
	
	/*
		Function: logProgress
		Logs progress info to the console
		
		Parameters:
			progress - progress Object with status, target, and spec
				- target - Object - object whose status is being reported
				- status - String - current status of object
				- spec: Any - wiring spec
	*/
	function logProgress(progress, contextTimer) {
		console.log(time('Object ' + progress.status, contextTimer), progress.target, progress.spec);
	}
	
	return {
		/*
			Function: wire$init
			Does any initialization for this plugin as soon as it is loaded. This is only
			called once when the plugin is loaded, and never again.
		*/
		wire$init: function() {
			console.log(time("All modules loaded"));
		},
		/*
			Function: wire$wire
			Invoked when wiring starts and provides two promises: one for wiring the context,
			and one for destroying the context.  Plugins should register resolve, reject, and
			promise handlers as necessary to do their work.
			
			Parameters:
				ready - promise that will be resolved when the context has been wired, rejected
					if there is an error during the wiring process, and will receive progress
					events for object creation, property setting, and initialization.
				destroy - promise that will be resolved when the context has been destroyed,
					rejected if there is an error while destroying the context, and will
					receive progress events for objects being destroyed.
		*/
		wire$wire: function(ready, destroy) {
			var contextTimer = createTimer();
			
			function contextTime(msg) {
				return time(msg, contextTimer);
			}
			
			function logContextProgress(progress) {
				logProgress(progress, contextTimer);
			}
			
			console.log(contextTime("Context init"));
			
			ready.then(
				function onContextReady(context) {
					console.log(contextTime("Context ready"), context);
				},
				function onContextError(err) {
					console.log(contextTime("Context ERROR: "), err);
				},
				logContextProgress
			);
			
			destroy.then(
				function onContextDestroyed() {
					// Do any context-specific plugin cleanup here
					console.log(contextTime("Context destroyed"));
				},
				function onContextDestroyError(err) {
					// Do any object-specific plugin cleanup here
					console.log(contextTime("Context destroy ERROR"), err);
				},
				logContextProgress
			);
		}
	};
	
});
{'fraction_non_alphanumeric': 0.09427148194271481, 'fraction_numerical': 0.00099626400996264, 'mean_word_length': 3.131172839506173, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3655956', 'n_tokens_mistral': 2663, 'n_tokens_neox': 2145, 'n_words': 857}