@lexmata/micropdf 0.4.0

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 (170) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +985 -0
  3. package/binding.gyp +73 -0
  4. package/dist/annot.d.ts +458 -0
  5. package/dist/annot.d.ts.map +1 -0
  6. package/dist/annot.js +697 -0
  7. package/dist/annot.js.map +1 -0
  8. package/dist/archive.d.ts +128 -0
  9. package/dist/archive.d.ts.map +1 -0
  10. package/dist/archive.js +268 -0
  11. package/dist/archive.js.map +1 -0
  12. package/dist/buffer.d.ts +572 -0
  13. package/dist/buffer.d.ts.map +1 -0
  14. package/dist/buffer.js +971 -0
  15. package/dist/buffer.js.map +1 -0
  16. package/dist/colorspace.d.ts +287 -0
  17. package/dist/colorspace.d.ts.map +1 -0
  18. package/dist/colorspace.js +542 -0
  19. package/dist/colorspace.js.map +1 -0
  20. package/dist/context.d.ts +184 -0
  21. package/dist/context.d.ts.map +1 -0
  22. package/dist/context.js +320 -0
  23. package/dist/context.js.map +1 -0
  24. package/dist/cookie.d.ts +164 -0
  25. package/dist/cookie.d.ts.map +1 -0
  26. package/dist/cookie.js +306 -0
  27. package/dist/cookie.js.map +1 -0
  28. package/dist/device.d.ts +169 -0
  29. package/dist/device.d.ts.map +1 -0
  30. package/dist/device.js +350 -0
  31. package/dist/device.js.map +1 -0
  32. package/dist/display-list.d.ts +202 -0
  33. package/dist/display-list.d.ts.map +1 -0
  34. package/dist/display-list.js +410 -0
  35. package/dist/display-list.js.map +1 -0
  36. package/dist/document.d.ts +637 -0
  37. package/dist/document.d.ts.map +1 -0
  38. package/dist/document.js +902 -0
  39. package/dist/document.js.map +1 -0
  40. package/dist/easy.d.ts +423 -0
  41. package/dist/easy.d.ts.map +1 -0
  42. package/dist/easy.js +644 -0
  43. package/dist/easy.js.map +1 -0
  44. package/dist/enhanced.d.ts +226 -0
  45. package/dist/enhanced.d.ts.map +1 -0
  46. package/dist/enhanced.js +368 -0
  47. package/dist/enhanced.js.map +1 -0
  48. package/dist/filter.d.ts +51 -0
  49. package/dist/filter.d.ts.map +1 -0
  50. package/dist/filter.js +381 -0
  51. package/dist/filter.js.map +1 -0
  52. package/dist/font.d.ts +222 -0
  53. package/dist/font.d.ts.map +1 -0
  54. package/dist/font.js +381 -0
  55. package/dist/font.js.map +1 -0
  56. package/dist/form.d.ts +214 -0
  57. package/dist/form.d.ts.map +1 -0
  58. package/dist/form.js +497 -0
  59. package/dist/form.js.map +1 -0
  60. package/dist/geometry.d.ts +469 -0
  61. package/dist/geometry.d.ts.map +1 -0
  62. package/dist/geometry.js +780 -0
  63. package/dist/geometry.js.map +1 -0
  64. package/dist/image.d.ts +172 -0
  65. package/dist/image.d.ts.map +1 -0
  66. package/dist/image.js +348 -0
  67. package/dist/image.js.map +1 -0
  68. package/dist/index.d.ts +171 -0
  69. package/dist/index.d.ts.map +1 -0
  70. package/dist/index.js +339 -0
  71. package/dist/index.js.map +1 -0
  72. package/dist/link.d.ts +168 -0
  73. package/dist/link.d.ts.map +1 -0
  74. package/dist/link.js +343 -0
  75. package/dist/link.js.map +1 -0
  76. package/dist/micropdf.d.ts +40 -0
  77. package/dist/micropdf.d.ts.map +1 -0
  78. package/dist/micropdf.js +45 -0
  79. package/dist/micropdf.js.map +1 -0
  80. package/dist/nanopdf.d.ts +40 -0
  81. package/dist/nanopdf.d.ts.map +1 -0
  82. package/dist/nanopdf.js +45 -0
  83. package/dist/nanopdf.js.map +1 -0
  84. package/dist/native.d.ts +242 -0
  85. package/dist/native.d.ts.map +1 -0
  86. package/dist/native.js +509 -0
  87. package/dist/native.js.map +1 -0
  88. package/dist/output.d.ts +166 -0
  89. package/dist/output.d.ts.map +1 -0
  90. package/dist/output.js +365 -0
  91. package/dist/output.js.map +1 -0
  92. package/dist/path.d.ts +420 -0
  93. package/dist/path.d.ts.map +1 -0
  94. package/dist/path.js +687 -0
  95. package/dist/path.js.map +1 -0
  96. package/dist/pdf/object.d.ts +489 -0
  97. package/dist/pdf/object.d.ts.map +1 -0
  98. package/dist/pdf/object.js +1045 -0
  99. package/dist/pdf/object.js.map +1 -0
  100. package/dist/pixmap.d.ts +315 -0
  101. package/dist/pixmap.d.ts.map +1 -0
  102. package/dist/pixmap.js +590 -0
  103. package/dist/pixmap.js.map +1 -0
  104. package/dist/profiler.d.ts +159 -0
  105. package/dist/profiler.d.ts.map +1 -0
  106. package/dist/profiler.js +380 -0
  107. package/dist/profiler.js.map +1 -0
  108. package/dist/render-options.d.ts +227 -0
  109. package/dist/render-options.d.ts.map +1 -0
  110. package/dist/render-options.js +130 -0
  111. package/dist/render-options.js.map +1 -0
  112. package/dist/resource-tracking.d.ts +332 -0
  113. package/dist/resource-tracking.d.ts.map +1 -0
  114. package/dist/resource-tracking.js +653 -0
  115. package/dist/resource-tracking.js.map +1 -0
  116. package/dist/simple.d.ts +276 -0
  117. package/dist/simple.d.ts.map +1 -0
  118. package/dist/simple.js +343 -0
  119. package/dist/simple.js.map +1 -0
  120. package/dist/stext.d.ts +290 -0
  121. package/dist/stext.d.ts.map +1 -0
  122. package/dist/stext.js +312 -0
  123. package/dist/stext.js.map +1 -0
  124. package/dist/stream.d.ts +174 -0
  125. package/dist/stream.d.ts.map +1 -0
  126. package/dist/stream.js +476 -0
  127. package/dist/stream.js.map +1 -0
  128. package/dist/text.d.ts +337 -0
  129. package/dist/text.d.ts.map +1 -0
  130. package/dist/text.js +454 -0
  131. package/dist/text.js.map +1 -0
  132. package/dist/typed-arrays.d.ts +127 -0
  133. package/dist/typed-arrays.d.ts.map +1 -0
  134. package/dist/typed-arrays.js +410 -0
  135. package/dist/typed-arrays.js.map +1 -0
  136. package/dist/types.d.ts +358 -0
  137. package/dist/types.d.ts.map +1 -0
  138. package/dist/types.js +216 -0
  139. package/dist/types.js.map +1 -0
  140. package/native/annot.cc +557 -0
  141. package/native/buffer.cc +204 -0
  142. package/native/colorspace.cc +166 -0
  143. package/native/context.cc +84 -0
  144. package/native/cookie.cc +179 -0
  145. package/native/device.cc +179 -0
  146. package/native/display_list.cc +179 -0
  147. package/native/document.cc +268 -0
  148. package/native/enhanced.cc +70 -0
  149. package/native/font.cc +282 -0
  150. package/native/form.cc +523 -0
  151. package/native/geometry.cc +255 -0
  152. package/native/image.cc +216 -0
  153. package/native/include/micropdf/enhanced.h +38 -0
  154. package/native/include/micropdf/types.h +36 -0
  155. package/native/include/micropdf.h +106 -0
  156. package/native/include/mupdf-ffi.h +39 -0
  157. package/native/include/mupdf.h +11 -0
  158. package/native/include/mupdf_minimal.h +381 -0
  159. package/native/lib/linux-x64/libmicropdf.a +0 -0
  160. package/native/link.cc +234 -0
  161. package/native/micropdf.cc +71 -0
  162. package/native/output.cc +229 -0
  163. package/native/page.cc +572 -0
  164. package/native/path.cc +259 -0
  165. package/native/pixmap.cc +240 -0
  166. package/native/stext.cc +610 -0
  167. package/native/stream.cc +239 -0
  168. package/package.json +120 -0
  169. package/scripts/build-from-rust.js +97 -0
  170. package/scripts/install.js +184 -0
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Memory Profiler - Detailed memory leak detection for MicroPDF
3
+ *
4
+ * Provides comprehensive memory profiling capabilities:
5
+ * - Handle allocation tracking with stack traces
6
+ * - Leak detection for unreleased handles
7
+ * - Memory usage statistics by type
8
+ * - WeakRef-based leak detection
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { enableProfiling, getLeakReport } from 'micropdf/profiler';
13
+ *
14
+ * enableProfiling(true);
15
+ * // ... use MicroPDF ...
16
+ * const report = getLeakReport(60000); // Leaks older than 60s
17
+ * console.log(report.toString());
18
+ * ```
19
+ */
20
+ /** Resource types being tracked */
21
+ export declare enum ResourceType {
22
+ Context = 0,
23
+ Buffer = 1,
24
+ Stream = 2,
25
+ Pixmap = 3,
26
+ Document = 4,
27
+ Page = 5,
28
+ Font = 6,
29
+ Image = 7,
30
+ Path = 8,
31
+ Text = 9,
32
+ Device = 10,
33
+ DisplayList = 11,
34
+ Colorspace = 12,
35
+ PdfObject = 13,
36
+ Outline = 14,
37
+ Link = 15,
38
+ Annotation = 16,
39
+ StextPage = 17,
40
+ Cookie = 18,
41
+ Archive = 19,
42
+ Other = 255
43
+ }
44
+ export declare function getResourceTypeName(type: ResourceType): string;
45
+ /** Record of a single allocation */
46
+ export interface AllocationRecord {
47
+ handle: number;
48
+ resourceType: ResourceType;
49
+ sizeBytes: number;
50
+ allocatedAt: Date;
51
+ stackTrace?: string;
52
+ tag?: string;
53
+ }
54
+ /** Statistics for a specific resource type */
55
+ export interface TypeStats {
56
+ currentCount: number;
57
+ currentBytes: number;
58
+ totalAllocated: number;
59
+ totalDeallocated: number;
60
+ totalBytesAllocated: number;
61
+ totalBytesDeallocated: number;
62
+ peakCount: number;
63
+ peakBytes: number;
64
+ }
65
+ /** Global statistics snapshot */
66
+ export interface GlobalStats {
67
+ totalHandlesCreated: number;
68
+ totalHandlesDestroyed: number;
69
+ currentHandles: number;
70
+ currentBytes: number;
71
+ peakHandles: number;
72
+ peakBytes: number;
73
+ uptimeMs: number;
74
+ }
75
+ /** Leak detection report */
76
+ export interface LeakReport {
77
+ generatedAt: Date;
78
+ minAgeThresholdMs: number;
79
+ totalPotentialLeaks: number;
80
+ leaksByType: Map<ResourceType, AllocationRecord[]>;
81
+ globalStats: GlobalStats;
82
+ }
83
+ /**
84
+ * Memory profiler for tracking handle allocations and detecting leaks
85
+ */
86
+ export declare class MemoryProfiler {
87
+ private enabled;
88
+ private captureStackTraces;
89
+ private allocations;
90
+ private statsByType;
91
+ private startTime;
92
+ private totalCreated;
93
+ private totalDestroyed;
94
+ private currentHandles;
95
+ private currentBytes;
96
+ private peakHandles;
97
+ private peakBytes;
98
+ private readonly _registry?;
99
+ constructor();
100
+ /** Enable or disable profiling */
101
+ setEnabled(enabled: boolean): void;
102
+ /** Enable or disable stack trace capture */
103
+ setStackTraceCapture(enabled: boolean): void;
104
+ /** Check if profiling is enabled */
105
+ isEnabled(): boolean;
106
+ /** Record a new allocation */
107
+ recordAllocation(handle: number, resourceType: ResourceType, sizeBytes: number, tag?: string): void;
108
+ /** Record a deallocation */
109
+ recordDeallocation(handle: number): AllocationRecord | undefined;
110
+ /** Register an object for GC tracking */
111
+ registerForGCTracking(target: object, handle: number, resourceType: ResourceType): void;
112
+ /** Get all currently live allocations */
113
+ getLiveAllocations(): AllocationRecord[];
114
+ /** Get allocations older than minAgeMs (potential leaks) */
115
+ getPotentialLeaks(minAgeMs: number): AllocationRecord[];
116
+ /** Get statistics by resource type */
117
+ getStatsByType(): Map<ResourceType, TypeStats>;
118
+ /** Get global statistics */
119
+ getGlobalStats(): GlobalStats;
120
+ /** Reset all profiling data */
121
+ reset(): void;
122
+ /** Generate a leak report */
123
+ generateLeakReport(minAgeMs: number): LeakReport;
124
+ }
125
+ /** Get the global memory profiler instance */
126
+ export declare function getProfiler(): MemoryProfiler;
127
+ /** Enable or disable memory profiling */
128
+ export declare function enableProfiling(enabled: boolean): void;
129
+ /** Enable or disable stack trace capture */
130
+ export declare function enableStackTraces(enabled: boolean): void;
131
+ /** Check if profiling is enabled */
132
+ export declare function isProfilingEnabled(): boolean;
133
+ /** Track an allocation */
134
+ export declare function trackAllocation(handle: number, resourceType: ResourceType, sizeBytes: number, tag?: string): void;
135
+ /** Track a deallocation */
136
+ export declare function trackDeallocation(handle: number): void;
137
+ /** Get a leak report */
138
+ export declare function getLeakReport(minAgeMs?: number): LeakReport;
139
+ /** Print a leak report to console */
140
+ export declare function printLeakReport(minAgeMs?: number): void;
141
+ /** Reset the profiler */
142
+ export declare function resetProfiler(): void;
143
+ /** Format a leak report as a string */
144
+ export declare function formatLeakReport(report: LeakReport): string;
145
+ /** Get Node.js process memory usage */
146
+ export declare function getProcessMemory(): {
147
+ heapUsed: number;
148
+ heapTotal: number;
149
+ external: number;
150
+ rss: number;
151
+ arrayBuffers: number;
152
+ };
153
+ /** Print Node.js process memory statistics */
154
+ export declare function printProcessMemory(): void;
155
+ /** Force garbage collection if available (requires --expose-gc flag) */
156
+ export declare function forceGC(): boolean;
157
+ /** Take a heap snapshot if v8 is available */
158
+ export declare function takeHeapSnapshot(filename: string): Promise<boolean>;
159
+ //# sourceMappingURL=profiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiler.d.ts","sourceRoot":"","sources":["../src/profiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,mCAAmC;AACnC,oBAAY,YAAY;IACtB,OAAO,IAAI;IACX,MAAM,IAAI;IACV,MAAM,IAAI;IACV,MAAM,IAAI;IACV,QAAQ,IAAI;IACZ,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,MAAM,KAAK;IACX,WAAW,KAAK;IAChB,UAAU,KAAK;IACf,SAAS,KAAK;IACd,OAAO,KAAK;IACZ,IAAI,KAAK;IACT,UAAU,KAAK;IACf,SAAS,KAAK;IACd,MAAM,KAAK;IACX,OAAO,KAAK;IACZ,KAAK,MAAM;CACZ;AA0BD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAE9D;AAED,oCAAoC;AACpC,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,IAAI,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,8CAA8C;AAC9C,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,C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AAED,yBAAyB;AACzB,wBAAgB,aAAa,IAAI,IAAI,CAEpC;AAED,uCAAuC;AACvC,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAyD3D;AAED,uCAAuC;AACvC,wBAAgB,gBAAgB,IAAI;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;CACtB,CASA;AAED,8CAA8C;AAC9C,wBAAgB,kBAAkB,IAAI,IAAI,CAQzC;AAED,wEAAwE;AACxE,wBAAgB,OAAO,IAAI,OAAO,CAMjC;AAED,8CAA8C;AAC9C,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAczE"}
@@ -0,0 +1,380 @@
1
+ /**
2
+ * Memory Profiler - Detailed memory leak detection for MicroPDF
3
+ *
4
+ * Provides comprehensive memory profiling capabilities:
5
+ * - Handle allocation tracking with stack traces
6
+ * - Leak detection for unreleased handles
7
+ * - Memory usage statistics by type
8
+ * - WeakRef-based leak detection
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { enableProfiling, getLeakReport } from 'micropdf/profiler';
13
+ *
14
+ * enableProfiling(true);
15
+ * // ... use MicroPDF ...
16
+ * const report = getLeakReport(60000); // Leaks older than 60s
17
+ * console.log(report.toString());
18
+ * ```
19
+ */
20
+ /** Resource types being tracked */
21
+ export var ResourceType;
22
+ (function (ResourceType) {
23
+ ResourceType[ResourceType["Context"] = 0] = "Context";
24
+ ResourceType[ResourceType["Buffer"] = 1] = "Buffer";
25
+ ResourceType[ResourceType["Stream"] = 2] = "Stream";
26
+ ResourceType[ResourceType["Pixmap"] = 3] = "Pixmap";
27
+ ResourceType[ResourceType["Document"] = 4] = "Document";
28
+ ResourceType[ResourceType["Page"] = 5] = "Page";
29
+ ResourceType[ResourceType["Font"] = 6] = "Font";
30
+ ResourceType[ResourceType["Image"] = 7] = "Image";
31
+ ResourceType[ResourceType["Path"] = 8] = "Path";
32
+ ResourceType[ResourceType["Text"] = 9] = "Text";
33
+ ResourceType[ResourceType["Device"] = 10] = "Device";
34
+ ResourceType[ResourceType["DisplayList"] = 11] = "DisplayList";
35
+ ResourceType[ResourceType["Colorspace"] = 12] = "Colorspace";
36
+ ResourceType[ResourceType["PdfObject"] = 13] = "PdfObject";
37
+ ResourceType[ResourceType["Outline"] = 14] = "Outline";
38
+ ResourceType[ResourceType["Link"] = 15] = "Link";
39
+ ResourceType[ResourceType["Annotation"] = 16] = "Annotation";
40
+ ResourceType[ResourceType["StextPage"] = 17] = "StextPage";
41
+ ResourceType[ResourceType["Cookie"] = 18] = "Cookie";
42
+ ResourceType[ResourceType["Archive"] = 19] = "Archive";
43
+ ResourceType[ResourceType["Other"] = 255] = "Other";
44
+ })(ResourceType || (ResourceType = {}));
45
+ const resourceTypeNames = {
46
+ [ResourceType.Context]: 'Context',
47
+ [ResourceType.Buffer]: 'Buffer',
48
+ [ResourceType.Stream]: 'Stream',
49
+ [ResourceType.Pixmap]: 'Pixmap',
50
+ [ResourceType.Document]: 'Document',
51
+ [ResourceType.Page]: 'Page',
52
+ [ResourceType.Font]: 'Font',
53
+ [ResourceType.Image]: 'Image',
54
+ [ResourceType.Path]: 'Path',
55
+ [ResourceType.Text]: 'Text',
56
+ [ResourceType.Device]: 'Device',
57
+ [ResourceType.DisplayList]: 'DisplayList',
58
+ [ResourceType.Colorspace]: 'Colorspace',
59
+ [ResourceType.PdfObject]: 'PdfObject',
60
+ [ResourceType.Outline]: 'Outline',
61
+ [ResourceType.Link]: 'Link',
62
+ [ResourceType.Annotation]: 'Annotation',
63
+ [ResourceType.StextPage]: 'StextPage',
64
+ [ResourceType.Cookie]: 'Cookie',
65
+ [ResourceType.Archive]: 'Archive',
66
+ [ResourceType.Other]: 'Other'
67
+ };
68
+ export function getResourceTypeName(type) {
69
+ return resourceTypeNames[type] ?? `Unknown(${type})`;
70
+ }
71
+ /**
72
+ * Memory profiler for tracking handle allocations and detecting leaks
73
+ */
74
+ export class MemoryProfiler {
75
+ enabled = false;
76
+ captureStackTraces = false;
77
+ allocations = new Map();
78
+ statsByType = new Map();
79
+ startTime = Date.now();
80
+ // Statistics
81
+ totalCreated = 0;
82
+ totalDestroyed = 0;
83
+ currentHandles = 0;
84
+ currentBytes = 0;
85
+ peakHandles = 0;
86
+ peakBytes = 0;
87
+ // WeakRef registry for detecting GC'd objects
88
+ _registry;
89
+ constructor() {
90
+ // Set up FinalizationRegistry if available (Node.js 14+)
91
+ if (typeof FinalizationRegistry !== 'undefined') {
92
+ this._registry = new FinalizationRegistry((heldValue) => {
93
+ // Object was GC'd without being explicitly deallocated
94
+ if (this.enabled && this.allocations.has(heldValue.handle)) {
95
+ console.warn(`[MicroPDF] Handle ${heldValue.handle} (${getResourceTypeName(heldValue.type)}) ` +
96
+ 'was garbage collected without being explicitly freed. This may indicate a leak.');
97
+ }
98
+ });
99
+ }
100
+ }
101
+ /** Enable or disable profiling */
102
+ setEnabled(enabled) {
103
+ this.enabled = enabled;
104
+ }
105
+ /** Enable or disable stack trace capture */
106
+ setStackTraceCapture(enabled) {
107
+ this.captureStackTraces = enabled;
108
+ }
109
+ /** Check if profiling is enabled */
110
+ isEnabled() {
111
+ return this.enabled;
112
+ }
113
+ /** Record a new allocation */
114
+ recordAllocation(handle, resourceType, sizeBytes, tag) {
115
+ if (!this.enabled)
116
+ return;
117
+ const record = {
118
+ handle,
119
+ resourceType,
120
+ sizeBytes,
121
+ allocatedAt: new Date()
122
+ };
123
+ if (tag !== undefined) {
124
+ record.tag = tag;
125
+ }
126
+ if (this.captureStackTraces) {
127
+ const stack = new Error().stack;
128
+ if (stack !== undefined) {
129
+ record.stackTrace = stack;
130
+ }
131
+ }
132
+ this.allocations.set(handle, record);
133
+ // Update type stats
134
+ let stats = this.statsByType.get(resourceType);
135
+ if (!stats) {
136
+ stats = {
137
+ currentCount: 0,
138
+ currentBytes: 0,
139
+ totalAllocated: 0,
140
+ totalDeallocated: 0,
141
+ totalBytesAllocated: 0,
142
+ totalBytesDeallocated: 0,
143
+ peakCount: 0,
144
+ peakBytes: 0
145
+ };
146
+ this.statsByType.set(resourceType, stats);
147
+ }
148
+ stats.currentCount++;
149
+ stats.currentBytes += sizeBytes;
150
+ stats.totalAllocated++;
151
+ stats.totalBytesAllocated += sizeBytes;
152
+ stats.peakCount = Math.max(stats.peakCount, stats.currentCount);
153
+ stats.peakBytes = Math.max(stats.peakBytes, stats.currentBytes);
154
+ // Update global stats
155
+ this.totalCreated++;
156
+ this.currentHandles++;
157
+ this.currentBytes += sizeBytes;
158
+ this.peakHandles = Math.max(this.peakHandles, this.currentHandles);
159
+ this.peakBytes = Math.max(this.peakBytes, this.currentBytes);
160
+ }
161
+ /** Record a deallocation */
162
+ recordDeallocation(handle) {
163
+ if (!this.enabled)
164
+ return undefined;
165
+ const record = this.allocations.get(handle);
166
+ if (!record)
167
+ return undefined;
168
+ this.allocations.delete(handle);
169
+ // Update type stats
170
+ const stats = this.statsByType.get(record.resourceType);
171
+ if (stats) {
172
+ stats.currentCount--;
173
+ stats.currentBytes -= record.sizeBytes;
174
+ stats.totalDeallocated++;
175
+ stats.totalBytesDeallocated += record.sizeBytes;
176
+ }
177
+ // Update global stats
178
+ this.totalDestroyed++;
179
+ this.currentHandles--;
180
+ this.currentBytes -= record.sizeBytes;
181
+ return record;
182
+ }
183
+ /** Register an object for GC tracking */
184
+ registerForGCTracking(target, handle, resourceType) {
185
+ if (this._registry && this.enabled) {
186
+ this._registry.register(target, { handle, type: resourceType });
187
+ }
188
+ }
189
+ /** Get all currently live allocations */
190
+ getLiveAllocations() {
191
+ return Array.from(this.allocations.values());
192
+ }
193
+ /** Get allocations older than minAgeMs (potential leaks) */
194
+ getPotentialLeaks(minAgeMs) {
195
+ const cutoff = Date.now() - minAgeMs;
196
+ return this.getLiveAllocations().filter((r) => r.allocatedAt.getTime() < cutoff);
197
+ }
198
+ /** Get statistics by resource type */
199
+ getStatsByType() {
200
+ return new Map(this.statsByType);
201
+ }
202
+ /** Get global statistics */
203
+ getGlobalStats() {
204
+ return {
205
+ totalHandlesCreated: this.totalCreated,
206
+ totalHandlesDestroyed: this.totalDestroyed,
207
+ currentHandles: this.currentHandles,
208
+ currentBytes: this.currentBytes,
209
+ peakHandles: this.peakHandles,
210
+ peakBytes: this.peakBytes,
211
+ uptimeMs: Date.now() - this.startTime
212
+ };
213
+ }
214
+ /** Reset all profiling data */
215
+ reset() {
216
+ this.allocations.clear();
217
+ this.statsByType.clear();
218
+ this.totalCreated = 0;
219
+ this.totalDestroyed = 0;
220
+ this.currentHandles = 0;
221
+ this.currentBytes = 0;
222
+ this.peakHandles = 0;
223
+ this.peakBytes = 0;
224
+ this.startTime = Date.now();
225
+ }
226
+ /** Generate a leak report */
227
+ generateLeakReport(minAgeMs) {
228
+ const leaks = this.getPotentialLeaks(minAgeMs);
229
+ const leaksByType = new Map();
230
+ for (const leak of leaks) {
231
+ const existing = leaksByType.get(leak.resourceType) ?? [];
232
+ existing.push(leak);
233
+ leaksByType.set(leak.resourceType, existing);
234
+ }
235
+ return {
236
+ generatedAt: new Date(),
237
+ minAgeThresholdMs: minAgeMs,
238
+ totalPotentialLeaks: leaks.length,
239
+ leaksByType,
240
+ globalStats: this.getGlobalStats()
241
+ };
242
+ }
243
+ }
244
+ // Global profiler instance
245
+ let globalProfiler = null;
246
+ /** Get the global memory profiler instance */
247
+ export function getProfiler() {
248
+ if (!globalProfiler) {
249
+ globalProfiler = new MemoryProfiler();
250
+ }
251
+ return globalProfiler;
252
+ }
253
+ /** Enable or disable memory profiling */
254
+ export function enableProfiling(enabled) {
255
+ getProfiler().setEnabled(enabled);
256
+ }
257
+ /** Enable or disable stack trace capture */
258
+ export function enableStackTraces(enabled) {
259
+ getProfiler().setStackTraceCapture(enabled);
260
+ }
261
+ /** Check if profiling is enabled */
262
+ export function isProfilingEnabled() {
263
+ return getProfiler().isEnabled();
264
+ }
265
+ /** Track an allocation */
266
+ export function trackAllocation(handle, resourceType, sizeBytes, tag) {
267
+ getProfiler().recordAllocation(handle, resourceType, sizeBytes, tag);
268
+ }
269
+ /** Track a deallocation */
270
+ export function trackDeallocation(handle) {
271
+ getProfiler().recordDeallocation(handle);
272
+ }
273
+ /** Get a leak report */
274
+ export function getLeakReport(minAgeMs = 60000) {
275
+ return getProfiler().generateLeakReport(minAgeMs);
276
+ }
277
+ /** Print a leak report to console */
278
+ export function printLeakReport(minAgeMs = 60000) {
279
+ const report = getLeakReport(minAgeMs);
280
+ console.log(formatLeakReport(report));
281
+ }
282
+ /** Reset the profiler */
283
+ export function resetProfiler() {
284
+ getProfiler().reset();
285
+ }
286
+ /** Format a leak report as a string */
287
+ export function formatLeakReport(report) {
288
+ const lines = [];
289
+ lines.push('=== MicroPDF Memory Leak Report (Node.js) ===');
290
+ lines.push('');
291
+ lines.push(`Generated: ${report.generatedAt.toISOString()}`);
292
+ lines.push(`Min age threshold: ${report.minAgeThresholdMs}ms`);
293
+ lines.push(`Total potential leaks: ${report.totalPotentialLeaks}`);
294
+ lines.push('');
295
+ lines.push('--- Global Statistics ---');
296
+ lines.push(`Handles created: ${report.globalStats.totalHandlesCreated}`);
297
+ lines.push(`Handles destroyed: ${report.globalStats.totalHandlesDestroyed}`);
298
+ lines.push(`Current handles: ${report.globalStats.currentHandles}`);
299
+ lines.push(`Current memory: ${report.globalStats.currentBytes} bytes`);
300
+ lines.push(`Peak handles: ${report.globalStats.peakHandles}`);
301
+ lines.push(`Peak memory: ${report.globalStats.peakBytes} bytes`);
302
+ lines.push(`Uptime: ${report.globalStats.uptimeMs}ms`);
303
+ lines.push('');
304
+ lines.push('--- Leaks by Type ---');
305
+ const sortedTypes = Array.from(report.leaksByType.keys()).sort((a, b) => a - b);
306
+ for (const resourceType of sortedTypes) {
307
+ const leaks = report.leaksByType.get(resourceType) ?? [];
308
+ if (leaks.length === 0)
309
+ continue;
310
+ lines.push('');
311
+ lines.push(`${getResourceTypeName(resourceType)} (${leaks.length} leaks):`);
312
+ // Sort by age (oldest first)
313
+ const sorted = leaks.sort((a, b) => a.allocatedAt.getTime() - b.allocatedAt.getTime());
314
+ for (let i = 0; i < Math.min(10, sorted.length); i++) {
315
+ const leak = sorted[i];
316
+ const age = Date.now() - leak.allocatedAt.getTime();
317
+ let line = ` ${i + 1}. Handle ${leak.handle} - ${leak.sizeBytes} bytes, age ${age}ms`;
318
+ if (leak.tag) {
319
+ line += `, tag: ${leak.tag}`;
320
+ }
321
+ lines.push(line);
322
+ if (leak.stackTrace) {
323
+ const stackLines = leak.stackTrace.split('\n').slice(1, 6);
324
+ for (const stackLine of stackLines) {
325
+ lines.push(` ${stackLine.trim()}`);
326
+ }
327
+ }
328
+ }
329
+ if (sorted.length > 10) {
330
+ lines.push(` ... and ${sorted.length - 10} more`);
331
+ }
332
+ }
333
+ return lines.join('\n');
334
+ }
335
+ /** Get Node.js process memory usage */
336
+ export function getProcessMemory() {
337
+ const usage = process.memoryUsage();
338
+ return {
339
+ heapUsed: usage.heapUsed,
340
+ heapTotal: usage.heapTotal,
341
+ external: usage.external,
342
+ rss: usage.rss,
343
+ arrayBuffers: usage.arrayBuffers
344
+ };
345
+ }
346
+ /** Print Node.js process memory statistics */
347
+ export function printProcessMemory() {
348
+ const mem = getProcessMemory();
349
+ console.log('=== Node.js Process Memory ===');
350
+ console.log(`Heap Used: ${(mem.heapUsed / 1024 / 1024).toFixed(2)} MB`);
351
+ console.log(`Heap Total: ${(mem.heapTotal / 1024 / 1024).toFixed(2)} MB`);
352
+ console.log(`External: ${(mem.external / 1024 / 1024).toFixed(2)} MB`);
353
+ console.log(`RSS: ${(mem.rss / 1024 / 1024).toFixed(2)} MB`);
354
+ console.log(`ArrayBuffers: ${(mem.arrayBuffers / 1024 / 1024).toFixed(2)} MB`);
355
+ }
356
+ /** Force garbage collection if available (requires --expose-gc flag) */
357
+ export function forceGC() {
358
+ if (typeof global.gc === 'function') {
359
+ global.gc();
360
+ return true;
361
+ }
362
+ return false;
363
+ }
364
+ /** Take a heap snapshot if v8 is available */
365
+ export async function takeHeapSnapshot(filename) {
366
+ try {
367
+ const v8 = await import('node:v8');
368
+ const snapshotStream = v8.writeHeapSnapshot(filename);
369
+ if (snapshotStream) {
370
+ console.log(`Heap snapshot written to: ${snapshotStream}`);
371
+ return true;
372
+ }
373
+ return false;
374
+ }
375
+ catch {
376
+ console.warn('Heap snapshot not available (requires Node.js with v8 module)');
377
+ return false;
378
+ }
379
+ }
380
+ //# sourceMappingURL=profiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiler.js","sourceRoot":"","sources":["../src/profiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,mCAAmC;AACnC,MAAM,CAAN,IAAY,YAsBX;AAtBD,WAAY,YAAY;IACtB,qDAAW,CAAA;IACX,mDAAU,CAAA;IACV,mDAAU,CAAA;IACV,mDAAU,CAAA;IACV,uDAAY,CAAA;IACZ,+CAAQ,CAAA;IACR,+CAAQ,CAAA;IACR,iDAAS,CAAA;IACT,+CAAQ,CAAA;IACR,+CAAQ,CAAA;IACR,oDAAW,CAAA;IACX,8DAAgB,CAAA;IAChB,4DAAe,CAAA;IACf,0DAAc,CAAA;IACd,sDAAY,CAAA;IACZ,gDAAS,CAAA;IACT,4DAAe,CAAA;IACf,0DAAc,CAAA;IACd,oDAAW,CAAA;IACX,sDAAY,CAAA;IACZ,mDAAW,CAAA;AACb,CAAC,EAtBW,YAAY,KAAZ,YAAY,QAsBvB;AAED,MAAM,iBAAiB,GAAiC;IACtD,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,SAAS;IACjC,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,QAAQ;IAC/B,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,QAAQ;IAC/B,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,QAAQ;IAC/B,CAAC,YAAY,CAAC,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