traceperf 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +31 -0
  2. package/dist/browser.d.ts +9 -3
  3. package/dist/browser.js +28 -8
  4. package/dist/browser.js.map +1 -1
  5. package/dist/esm/browser.d.ts +73 -0
  6. package/dist/esm/browser.js +275 -0
  7. package/dist/esm/browser.js.map +1 -0
  8. package/dist/esm/core/config.d.ts +77 -0
  9. package/dist/esm/core/config.js +112 -0
  10. package/dist/esm/core/config.js.map +1 -0
  11. package/dist/esm/core/constants.d.ts +78 -0
  12. package/dist/esm/core/constants.js +106 -0
  13. package/dist/esm/core/constants.js.map +1 -0
  14. package/dist/esm/core/index.d.ts +3 -0
  15. package/dist/esm/core/index.js +4 -0
  16. package/dist/esm/core/index.js.map +1 -0
  17. package/dist/esm/core/logger.d.ts +84 -0
  18. package/dist/esm/core/logger.js +170 -0
  19. package/dist/esm/core/logger.js.map +1 -0
  20. package/dist/esm/formatters/ascii.d.ts +52 -0
  21. package/dist/esm/formatters/ascii.js +100 -0
  22. package/dist/esm/formatters/ascii.js.map +1 -0
  23. package/dist/esm/formatters/cli.d.ts +50 -0
  24. package/dist/esm/formatters/cli.js +96 -0
  25. package/dist/esm/formatters/cli.js.map +1 -0
  26. package/dist/esm/formatters/index.d.ts +3 -0
  27. package/dist/esm/formatters/index.js +4 -0
  28. package/dist/esm/formatters/index.js.map +1 -0
  29. package/dist/esm/formatters/json.d.ts +45 -0
  30. package/dist/esm/formatters/json.js +85 -0
  31. package/dist/esm/formatters/json.js.map +1 -0
  32. package/dist/esm/index.d.ts +10 -0
  33. package/dist/esm/index.js +29 -0
  34. package/dist/esm/index.js.map +1 -0
  35. package/dist/esm/trackers/execution.d.ts +72 -0
  36. package/dist/esm/trackers/execution.js +143 -0
  37. package/dist/esm/trackers/execution.js.map +1 -0
  38. package/dist/esm/trackers/index.d.ts +2 -0
  39. package/dist/esm/trackers/index.js +3 -0
  40. package/dist/esm/trackers/index.js.map +1 -0
  41. package/dist/esm/trackers/performance.d.ts +82 -0
  42. package/dist/esm/trackers/performance.js +106 -0
  43. package/dist/esm/trackers/performance.js.map +1 -0
  44. package/dist/esm/types/config.d.ts +110 -0
  45. package/dist/esm/types/config.js +2 -0
  46. package/dist/esm/types/config.js.map +1 -0
  47. package/dist/esm/types/index.d.ts +2 -0
  48. package/dist/esm/types/index.js +3 -0
  49. package/dist/esm/types/index.js.map +1 -0
  50. package/dist/esm/types/logger.d.ts +127 -0
  51. package/dist/esm/types/logger.js +2 -0
  52. package/dist/esm/types/logger.js.map +1 -0
  53. package/dist/esm/utils/colors.d.ts +87 -0
  54. package/dist/esm/utils/colors.js +134 -0
  55. package/dist/esm/utils/colors.js.map +1 -0
  56. package/dist/esm/utils/index.d.ts +3 -0
  57. package/dist/esm/utils/index.js +4 -0
  58. package/dist/esm/utils/index.js.map +1 -0
  59. package/dist/esm/utils/stack.d.ts +63 -0
  60. package/dist/esm/utils/stack.js +110 -0
  61. package/dist/esm/utils/stack.js.map +1 -0
  62. package/dist/esm/utils/timing.d.ts +65 -0
  63. package/dist/esm/utils/timing.js +99 -0
  64. package/dist/esm/utils/timing.js.map +1 -0
  65. package/dist/index.js +13 -0
  66. package/dist/index.js.map +1 -1
  67. package/dist/types/config.js +2 -1
  68. package/dist/types/index.js +18 -2
  69. package/dist/types/index.js.map +1 -1
  70. package/dist/types/logger.js +2 -1
  71. package/package.json +16 -2
@@ -0,0 +1,100 @@
1
+ import { BOX_CHARS, PERFORMANCE_ICONS } from '../core/constants';
2
+ import { formatDuration } from '../utils/timing';
3
+ /**
4
+ * ASCII art generator for execution flow charts
5
+ */
6
+ export class AsciiArtGenerator {
7
+ /**
8
+ * Create a new AsciiArtGenerator instance
9
+ *
10
+ * @param options - Generator options
11
+ */
12
+ constructor(options = {}) {
13
+ var _a;
14
+ this._boxWidth = (_a = options.boxWidth) !== null && _a !== void 0 ? _a : 30;
15
+ }
16
+ /**
17
+ * Generate a flow chart for a sequence of function executions
18
+ *
19
+ * @param executions - Array of execution data
20
+ * @returns ASCII art flow chart
21
+ */
22
+ generateFlowChart(executions) {
23
+ let chart = '';
24
+ for (let i = 0; i < executions.length; i++) {
25
+ const execution = executions[i];
26
+ // Generate box for function
27
+ chart += this.generateFunctionBox(execution);
28
+ // Add arrow to next function if not the last one
29
+ if (i < executions.length - 1) {
30
+ chart += this.generateArrow(executions[i + 1].level - execution.level);
31
+ }
32
+ }
33
+ return chart;
34
+ }
35
+ /**
36
+ * Generate a box for a function execution
37
+ *
38
+ * @param execution - The execution data
39
+ * @returns ASCII art box
40
+ */
41
+ generateFunctionBox(execution) {
42
+ const { name, duration, isSlow, memoryUsage } = execution;
43
+ // Calculate padding for the function name
44
+ const nameLength = name.length;
45
+ const padding = Math.max(0, this._boxWidth - nameLength - 2);
46
+ const leftPadding = Math.floor(padding / 2);
47
+ const rightPadding = padding - leftPadding;
48
+ // Generate the box
49
+ let box = '';
50
+ // Top border
51
+ box += BOX_CHARS.topLeft + BOX_CHARS.horizontal.repeat(this._boxWidth) + BOX_CHARS.topRight + '\n';
52
+ // Function name
53
+ box += BOX_CHARS.vertical + ' '.repeat(leftPadding) + name + ' '.repeat(rightPadding) + BOX_CHARS.vertical;
54
+ // Performance metrics
55
+ box += ` ${PERFORMANCE_ICONS.timer} ${formatDuration(duration)}`;
56
+ if (isSlow) {
57
+ box += ` ${PERFORMANCE_ICONS.slow} SLOW`;
58
+ }
59
+ if (memoryUsage !== undefined) {
60
+ box += ` ${PERFORMANCE_ICONS.memory} ${this.formatMemory(memoryUsage)}`;
61
+ }
62
+ box += '\n';
63
+ // Bottom border
64
+ box += BOX_CHARS.bottomLeft + BOX_CHARS.horizontal.repeat(this._boxWidth) + BOX_CHARS.bottomRight + '\n';
65
+ return box;
66
+ }
67
+ /**
68
+ * Generate an arrow between function boxes
69
+ *
70
+ * @param levelDiff - Difference in nesting level
71
+ * @returns ASCII art arrow
72
+ */
73
+ generateArrow(levelDiff) {
74
+ let arrow = '';
75
+ // Indent based on level difference
76
+ const indent = ' '.repeat(Math.max(0, levelDiff));
77
+ // Vertical line
78
+ arrow += indent + ' '.repeat(this._boxWidth / 2) + BOX_CHARS.vertical + '\n';
79
+ // Arrow
80
+ arrow += indent + ' '.repeat(this._boxWidth / 2) + BOX_CHARS.downArrow + '\n';
81
+ return arrow;
82
+ }
83
+ /**
84
+ * Format memory usage in a human-readable format
85
+ *
86
+ * @param bytes - Memory usage in bytes
87
+ * @returns Formatted memory usage
88
+ */
89
+ formatMemory(bytes) {
90
+ const units = ['B', 'KB', 'MB', 'GB'];
91
+ let size = bytes;
92
+ let unitIndex = 0;
93
+ while (size >= 1024 && unitIndex < units.length - 1) {
94
+ size /= 1024;
95
+ unitIndex++;
96
+ }
97
+ return `${size.toFixed(2)}${units[unitIndex]}`;
98
+ }
99
+ }
100
+ //# sourceMappingURL=ascii.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ascii.js","sourceRoot":"","sources":["../../../src/formatters/ascii.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAajD;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAG5B;;;;OAIG;IACH,YAAY,UAAiC,EAAE;;QAC7C,IAAI,CAAC,SAAS,GAAG,MAAA,OAAO,CAAC,QAAQ,mCAAI,EAAE,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACI,iBAAiB,CAAC,UAA2B;QAClD,IAAI,KAAK,GAAG,EAAE,CAAC;QAEf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YAEhC,4BAA4B;YAC5B,KAAK,IAAI,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AI,IAAI,IAAI,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpD,IAAI,IAAI,IAAI,CAAC;YACb,SAAS,EAAE,CAAC;QACd,CAAC;QAED,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;IACjD,CAAC;CACF"}
@@ -0,0 +1,50 @@
1
+ import { IFormatter, LogLevel, LogMeta } from '../types';
2
+ /**
3
+ * CLI formatter for console output
4
+ * Formats log entries with colors, icons, and indentation
5
+ */
6
+ export declare class CliFormatter implements IFormatter {
7
+ private _colorEnabled;
8
+ private _indentSize;
9
+ /**
10
+ * Create a new CliFormatter instance
11
+ *
12
+ * @param options - Formatter options
13
+ */
14
+ constructor(options?: {
15
+ colorEnabled?: boolean;
16
+ indentSize?: number;
17
+ });
18
+ /**
19
+ * Format a log entry for CLI output
20
+ *
21
+ * @param level - The log level
22
+ * @param message - The log message
23
+ * @param args - Additional arguments
24
+ * @param meta - Metadata for the log entry
25
+ * @returns The formatted log entry
26
+ */
27
+ format(level: LogLevel, message: string | object, args: any[], meta: LogMeta): string;
28
+ /**
29
+ * Format a timestamp
30
+ *
31
+ * @param date - The date to format
32
+ * @returns The formatted timestamp
33
+ */
34
+ private formatTimestamp;
35
+ /**
36
+ * Format a log level
37
+ *
38
+ * @param level - The log level
39
+ * @returns The formatted log level
40
+ */
41
+ private formatLevel;
42
+ /**
43
+ * Format a message and its arguments
44
+ *
45
+ * @param message - The message to format
46
+ * @param args - Additional arguments
47
+ * @returns The formatted message
48
+ */
49
+ private formatMessage;
50
+ }
@@ -0,0 +1,96 @@
1
+ import { LEVEL_COLORS, LEVEL_ICONS } from '../core/constants';
2
+ import { colorize, dim, supportsColor } from '../utils/colors';
3
+ /**
4
+ * CLI formatter for console output
5
+ * Formats log entries with colors, icons, and indentation
6
+ */
7
+ export class CliFormatter {
8
+ /**
9
+ * Create a new CliFormatter instance
10
+ *
11
+ * @param options - Formatter options
12
+ */
13
+ constructor(options = {}) {
14
+ var _a, _b;
15
+ this._colorEnabled = (_a = options.colorEnabled) !== null && _a !== void 0 ? _a : supportsColor();
16
+ this._indentSize = (_b = options.indentSize) !== null && _b !== void 0 ? _b : 2;
17
+ }
18
+ /**
19
+ * Format a log entry for CLI output
20
+ *
21
+ * @param level - The log level
22
+ * @param message - The log message
23
+ * @param args - Additional arguments
24
+ * @param meta - Metadata for the log entry
25
+ * @returns The formatted log entry
26
+ */
27
+ format(level, message, args, meta) {
28
+ const timestamp = this.formatTimestamp(meta.timestamp);
29
+ const levelStr = this.formatLevel(level);
30
+ const indent = ' '.repeat(meta.indentLevel * this._indentSize);
31
+ const formattedMessage = this.formatMessage(message, args);
32
+ return `${timestamp} ${levelStr} ${indent}${formattedMessage}`;
33
+ }
34
+ /**
35
+ * Format a timestamp
36
+ *
37
+ * @param date - The date to format
38
+ * @returns The formatted timestamp
39
+ */
40
+ formatTimestamp(date) {
41
+ const timeStr = date.toISOString().replace(/T/, ' ').replace(/\..+/, '');
42
+ return this._colorEnabled ? dim(`[${timeStr}]`) : `[${timeStr}]`;
43
+ }
44
+ /**
45
+ * Format a log level
46
+ *
47
+ * @param level - The log level
48
+ * @returns The formatted log level
49
+ */
50
+ formatLevel(level) {
51
+ const icon = LEVEL_ICONS[level];
52
+ const text = level.toUpperCase();
53
+ if (this._colorEnabled) {
54
+ return colorize(`${icon} ${text}`, LEVEL_COLORS[level]);
55
+ }
56
+ return `${icon} ${text}`;
57
+ }
58
+ /**
59
+ * Format a message and its arguments
60
+ *
61
+ * @param message - The message to format
62
+ * @param args - Additional arguments
63
+ * @returns The formatted message
64
+ */
65
+ formatMessage(message, args) {
66
+ let formattedMessage;
67
+ if (typeof message === 'string') {
68
+ formattedMessage = message;
69
+ }
70
+ else {
71
+ try {
72
+ formattedMessage = JSON.stringify(message, null, 2);
73
+ }
74
+ catch (error) {
75
+ formattedMessage = String(message);
76
+ }
77
+ }
78
+ // Format additional arguments
79
+ if (args.length > 0) {
80
+ const formattedArgs = args.map(arg => {
81
+ if (typeof arg === 'object' && arg !== null) {
82
+ try {
83
+ return JSON.stringify(arg, null, 2);
84
+ }
85
+ catch (error) {
86
+ return String(arg);
87
+ }
88
+ }
89
+ return String(arg);
90
+ }).join(' ');
91
+ formattedMessage = `${formattedMessage} ${formattedArgs}`;
92
+ }
93
+ return formattedMessage;
94
+ }
95
+ }
96
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/formatters/cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE/D;;;GAGG;AACH,MAAM,OAAO,YAAY;IAIvB;;;;OAIG;IACH,YAAY,UAA2D,EAAE;;QACvE,IAAI,CAAC,aAAa,GAAG,MAAA,OAAO,CAAC,YAAY,mCAAI,aAAa,EAAE,CAAC;QAC7D,IAAI,CAAC,WAAW,GAAG,MAAA,OAAO,CAAC,UAAU,mCAAI,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAe,EAAE,OAAwB,EAAE,IAAW,EAAE,IAAa;QACjF,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvD,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;QAC/D,MAAM,gBAAgB,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAE3D,OAAO,GAAG,SAAS,IAAI,QAAQ,IAAI,MAAM,GAAG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,GAAG,CAAC,EAAE;gBACnC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;oBAC5C,IAAI,CAAC;wBACH,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;oBACtC,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;oBACrB,CAAC;gBACH,CAAC;gBACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;YACrB,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAEb,gBAAgB,GAAG,GAAG,gBAAgB,IAAI,aAAa,EAAE,CAAC;QAC5D,CAAC;QAED,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export * from './cli';
2
+ export * from './json';
3
+ export * from './ascii';
@@ -0,0 +1,4 @@
1
+ export * from './cli';
2
+ export * from './json';
3
+ export * from './ascii';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/formatters/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,45 @@
1
+ import { IFormatter, LogLevel, LogMeta } from '../types';
2
+ /**
3
+ * JSON formatter for structured output
4
+ * Formats log entries as JSON objects
5
+ */
6
+ export declare class JsonFormatter implements IFormatter {
7
+ /**
8
+ * Format a log entry as JSON
9
+ *
10
+ * @param level - The log level
11
+ * @param message - The log message
12
+ * @param args - Additional arguments
13
+ * @param meta - Metadata for the log entry
14
+ * @returns The formatted log entry as a JSON string
15
+ */
16
+ format(level: LogLevel, message: string | object, args: any[], meta: LogMeta): string;
17
+ /**
18
+ * Format a message for JSON output
19
+ *
20
+ * @param message - The message to format
21
+ * @returns The formatted message
22
+ */
23
+ private formatMessage;
24
+ /**
25
+ * Format arguments for JSON output
26
+ *
27
+ * @param args - The arguments to format
28
+ * @returns The formatted arguments
29
+ */
30
+ private formatArgs;
31
+ /**
32
+ * Sanitize an object for JSON serialization
33
+ *
34
+ * @param obj - The object to sanitize
35
+ * @returns A sanitized version of the object
36
+ */
37
+ private sanitizeObject;
38
+ /**
39
+ * Extract additional metadata from the log meta object
40
+ *
41
+ * @param meta - The log metadata
42
+ * @returns Additional metadata as an object
43
+ */
44
+ private extractExtraMeta;
45
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * JSON formatter for structured output
3
+ * Formats log entries as JSON objects
4
+ */
5
+ export class JsonFormatter {
6
+ /**
7
+ * Format a log entry as JSON
8
+ *
9
+ * @param level - The log level
10
+ * @param message - The log message
11
+ * @param args - Additional arguments
12
+ * @param meta - Metadata for the log entry
13
+ * @returns The formatted log entry as a JSON string
14
+ */
15
+ format(level, message, args, meta) {
16
+ const logEntry = {
17
+ timestamp: meta.timestamp.toISOString(),
18
+ level,
19
+ indentLevel: meta.indentLevel,
20
+ message: this.formatMessage(message),
21
+ args: this.formatArgs(args),
22
+ ...this.extractExtraMeta(meta),
23
+ };
24
+ return JSON.stringify(logEntry);
25
+ }
26
+ /**
27
+ * Format a message for JSON output
28
+ *
29
+ * @param message - The message to format
30
+ * @returns The formatted message
31
+ */
32
+ formatMessage(message) {
33
+ if (typeof message === 'string') {
34
+ return message;
35
+ }
36
+ return this.sanitizeObject(message);
37
+ }
38
+ /**
39
+ * Format arguments for JSON output
40
+ *
41
+ * @param args - The arguments to format
42
+ * @returns The formatted arguments
43
+ */
44
+ formatArgs(args) {
45
+ return args.map(arg => {
46
+ if (typeof arg === 'object' && arg !== null) {
47
+ return this.sanitizeObject(arg);
48
+ }
49
+ return arg;
50
+ });
51
+ }
52
+ /**
53
+ * Sanitize an object for JSON serialization
54
+ *
55
+ * @param obj - The object to sanitize
56
+ * @returns A sanitized version of the object
57
+ */
58
+ sanitizeObject(obj) {
59
+ try {
60
+ // Use JSON.parse(JSON.stringify()) to remove non-serializable values
61
+ return JSON.parse(JSON.stringify(obj));
62
+ }
63
+ catch (error) {
64
+ // If serialization fails, return a simplified object
65
+ return { value: String(obj) };
66
+ }
67
+ }
68
+ /**
69
+ * Extract additional metadata from the log meta object
70
+ *
71
+ * @param meta - The log metadata
72
+ * @returns Additional metadata as an object
73
+ */
74
+ extractExtraMeta(meta) {
75
+ const result = {};
76
+ // Copy all properties except the standard ones
77
+ Object.keys(meta).forEach(key => {
78
+ if (!['timestamp', 'level', 'indentLevel'].includes(key)) {
79
+ result[key] = meta[key];
80
+ }
81
+ });
82
+ return result;
83
+ }
84
+ }
85
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/formatters/json.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,OAAO,aAAa;IACxB;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAe,EAAE,OAAwB,EAAE,IAAW,EAAE,IAAa;QACjF,MAAM,QAAQ,GAAG;YACf,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;YACvC,KAAK;YACL,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;YACpC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YAC3B,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;SAC/B,CAAC;QAEF,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED;;;;;OAKG;IACK,aAAa,CAAC,OAAwB;QAC5C,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACK,UAAU,CAAC,IAAW;QAC5B,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACpB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;gBAC5C,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;YAClC,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACK,cAAc,CAAC,GAAW;QAChC,IAAI,CAAC;YACH,qEAAqE;YACrE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,qDAAqD;YACrD,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACK,gBAAgB,CAAC,IAAa;QACpC,MAAM,MAAM,GAAwB,EAAE,CAAC;QAEvC,+CAA+C;QAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YAC9B,IAAI,CAAC,CAAC,WAAW,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzD,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import { Logger } from './core/logger';
2
+ import { ILoggerConfig } from './types';
3
+ declare const defaultLogger: Logger;
4
+ export default defaultLogger;
5
+ export declare function createLogger(config?: Partial<ILoggerConfig>): Logger;
6
+ export * from './types';
7
+ export * from './core';
8
+ export * from './formatters';
9
+ export * from './trackers';
10
+ export * from './utils';
@@ -0,0 +1,29 @@
1
+ import { Logger } from './core/logger';
2
+ // Create a singleton instance of the logger
3
+ const defaultLogger = new Logger();
4
+ // Export the singleton instance as the default export
5
+ export default defaultLogger;
6
+ // Export a function to create a new logger instance
7
+ export function createLogger(config = {}) {
8
+ return new Logger(config);
9
+ }
10
+ // Export types and classes for advanced usage
11
+ export * from './types';
12
+ export * from './core';
13
+ export * from './formatters';
14
+ export * from './trackers';
15
+ export * from './utils';
16
+ // Add CommonJS compatibility
17
+ if (typeof module !== 'undefined' && module.exports) {
18
+ module.exports = Object.assign(defaultLogger, {
19
+ default: defaultLogger,
20
+ createLogger,
21
+ // Re-export everything from the modules
22
+ ...require('./types'),
23
+ ...require('./core'),
24
+ ...require('./formatters'),
25
+ ...require('./trackers'),
26
+ ...require('./utils')
27
+ });
28
+ }
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGvC,4CAA4C;AAC5C,MAAM,aAAa,GAAG,IAAI,MAAM,EAAE,CAAC;AAEnC,sDAAsD;AACtD,eAAe,aAAa,CAAC;AAE7B,oDAAoD;AACpD,MAAM,UAAU,YAAY,CAAC,SAAiC,EAAE;IAC9D,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AAED,8CAA8C;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AAExB,6BAA6B;AAC7B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;IACpD,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE;QAC5C,OAAO,EAAE,aAAa;QACtB,YAAY;QACZ,wCAAwC;QACxC,GAAG,OAAO,CAAC,SAAS,CAAC;QACrB,GAAG,OAAO,CAAC,QAAQ,CAAC;QACpB,GAAG,OAAO,CAAC,cAAc,CAAC;QAC1B,GAAG,OAAO,CAAC,YAAY,CAAC;QACxB,GAAG,OAAO,CAAC,SAAS,CAAC;KACtB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,72 @@
1
+ import { IExecutionTracker, ITrackOptions } from '../types';
2
+ /**
3
+ * Execution record for a function call
4
+ */
5
+ interface ExecutionRecord {
6
+ name: string;
7
+ duration: number;
8
+ isSlow: boolean;
9
+ memoryUsage?: number;
10
+ level: number;
11
+ startTime: [number, number];
12
+ endTime?: [number, number];
13
+ children: ExecutionRecord[];
14
+ parent?: ExecutionRecord;
15
+ }
16
+ /**
17
+ * Execution tracker for tracking function calls and generating flow charts
18
+ */
19
+ export declare class ExecutionTracker implements IExecutionTracker {
20
+ private _callStack;
21
+ private _executions;
22
+ private _currentExecution;
23
+ private _asciiGenerator;
24
+ private _defaultThreshold;
25
+ /**
26
+ * Create a new ExecutionTracker instance
27
+ *
28
+ * @param options - Tracker options
29
+ */
30
+ constructor(options?: {
31
+ defaultThreshold?: number;
32
+ boxWidth?: number;
33
+ });
34
+ /**
35
+ * Track the execution of a function
36
+ *
37
+ * @param fn - The function to track
38
+ * @param options - Options for tracking
39
+ * @returns The return value of the tracked function
40
+ */
41
+ track<T>(fn: () => T, options?: ITrackOptions): T;
42
+ /**
43
+ * Get the current call stack
44
+ *
45
+ * @returns The current call stack
46
+ */
47
+ getCallStack(): string[];
48
+ /**
49
+ * Generate a visual representation of the execution flow
50
+ *
51
+ * @returns ASCII flow chart of the execution
52
+ */
53
+ generateFlowChart(): string;
54
+ /**
55
+ * Clear all execution records
56
+ */
57
+ clear(): void;
58
+ /**
59
+ * Get all execution records
60
+ *
61
+ * @returns All execution records
62
+ */
63
+ getExecutions(): ExecutionRecord[];
64
+ /**
65
+ * Flatten the execution tree into a list
66
+ *
67
+ * @param executions - The execution records to flatten
68
+ * @returns A flat list of execution data
69
+ */
70
+ private flattenExecutions;
71
+ }
72
+ export {};
@@ -0,0 +1,143 @@
1
+ import { CallStackManager, getFunctionName } from '../utils/stack';
2
+ import { getHighResTime, getDuration } from '../utils/timing';
3
+ import { AsciiArtGenerator } from '../formatters/ascii';
4
+ /**
5
+ * Execution tracker for tracking function calls and generating flow charts
6
+ */
7
+ export class ExecutionTracker {
8
+ /**
9
+ * Create a new ExecutionTracker instance
10
+ *
11
+ * @param options - Tracker options
12
+ */
13
+ constructor(options = {}) {
14
+ var _a;
15
+ this._executions = [];
16
+ this._currentExecution = null;
17
+ this._callStack = new CallStackManager();
18
+ this._asciiGenerator = new AsciiArtGenerator({ boxWidth: options.boxWidth });
19
+ this._defaultThreshold = (_a = options.defaultThreshold) !== null && _a !== void 0 ? _a : 100; // ms
20
+ }
21
+ /**
22
+ * Track the execution of a function
23
+ *
24
+ * @param fn - The function to track
25
+ * @param options - Options for tracking
26
+ * @returns The return value of the tracked function
27
+ */
28
+ track(fn, options) {
29
+ var _a, _b;
30
+ const fnName = (options === null || options === void 0 ? void 0 : options.label) || getFunctionName(fn);
31
+ const threshold = (_a = options === null || options === void 0 ? void 0 : options.threshold) !== null && _a !== void 0 ? _a : this._defaultThreshold;
32
+ const includeMemory = (_b = options === null || options === void 0 ? void 0 : options.includeMemory) !== null && _b !== void 0 ? _b : true;
33
+ // Get memory usage before execution
34
+ const startMemory = includeMemory ? process.memoryUsage().heapUsed : undefined;
35
+ // Start timing
36
+ const startTime = getHighResTime();
37
+ // Add to call stack
38
+ const level = this._callStack.push(fnName);
39
+ // Create execution record
40
+ const execution = {
41
+ name: fnName,
42
+ duration: 0,
43
+ isSlow: false,
44
+ level: level - 1, // 0-based level
45
+ startTime,
46
+ children: [],
47
+ };
48
+ // Set parent-child relationship
49
+ if (this._currentExecution) {
50
+ execution.parent = this._currentExecution;
51
+ this._currentExecution.children.push(execution);
52
+ }
53
+ else {
54
+ // This is a root execution
55
+ this._executions.push(execution);
56
+ }
57
+ // Save the previous current execution
58
+ const previousExecution = this._currentExecution;
59
+ // Set this as the current execution
60
+ this._currentExecution = execution;
61
+ try {
62
+ // Execute the function
63
+ return fn();
64
+ }
65
+ finally {
66
+ // End timing
67
+ const endTime = getHighResTime();
68
+ execution.endTime = endTime;
69
+ // Calculate duration
70
+ execution.duration = getDuration(startTime);
71
+ // Check if it's a bottleneck
72
+ execution.isSlow = execution.duration > threshold;
73
+ // Calculate memory usage
74
+ if (includeMemory && startMemory !== undefined) {
75
+ execution.memoryUsage = process.memoryUsage().heapUsed - startMemory;
76
+ }
77
+ // Restore the previous current execution
78
+ this._currentExecution = previousExecution;
79
+ // Remove from call stack
80
+ this._callStack.pop();
81
+ }
82
+ }
83
+ /**
84
+ * Get the current call stack
85
+ *
86
+ * @returns The current call stack
87
+ */
88
+ getCallStack() {
89
+ return this._callStack.getStack();
90
+ }
91
+ /**
92
+ * Generate a visual representation of the execution flow
93
+ *
94
+ * @returns ASCII flow chart of the execution
95
+ */
96
+ generateFlowChart() {
97
+ // Convert execution records to execution data for the ASCII generator
98
+ const flatExecutions = this.flattenExecutions(this._executions);
99
+ // Generate the flow chart
100
+ return this._asciiGenerator.generateFlowChart(flatExecutions);
101
+ }
102
+ /**
103
+ * Clear all execution records
104
+ */
105
+ clear() {
106
+ this._executions = [];
107
+ this._currentExecution = null;
108
+ this._callStack.clear();
109
+ }
110
+ /**
111
+ * Get all execution records
112
+ *
113
+ * @returns All execution records
114
+ */
115
+ getExecutions() {
116
+ return [...this._executions];
117
+ }
118
+ /**
119
+ * Flatten the execution tree into a list
120
+ *
121
+ * @param executions - The execution records to flatten
122
+ * @returns A flat list of execution data
123
+ */
124
+ flattenExecutions(executions) {
125
+ const result = [];
126
+ // Helper function to recursively flatten the tree
127
+ const flatten = (record) => {
128
+ result.push({
129
+ name: record.name,
130
+ duration: record.duration,
131
+ isSlow: record.isSlow,
132
+ memoryUsage: record.memoryUsage,
133
+ level: record.level,
134
+ });
135
+ // Process children
136
+ record.children.forEach(child => flatten(child));
137
+ };
138
+ // Flatten each root execution
139
+ executions.forEach(execution => flatten(execution));
140
+ return result;
141
+ }
142
+ }
143
+ //# sourceMappingURL=execution.js.map