@agoric/xsnap 0.14.3-dev-b047af2.0 → 0.14.3-dev-2a16ddd.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 (125) hide show
  1. package/package.json +8 -15
  2. package/src/build.js +4 -61
  3. package/moddable/modules/data/base64/base64.js +0 -28
  4. package/moddable/modules/data/base64/manifest.json +0 -11
  5. package/moddable/modules/data/base64/modBase64.c +0 -188
  6. package/moddable/modules/data/binaryMessage/BinaryMessage.js +0 -106
  7. package/moddable/modules/data/crc/crc.c +0 -205
  8. package/moddable/modules/data/crc/crc.js +0 -36
  9. package/moddable/modules/data/crc/manifest.json +0 -8
  10. package/moddable/modules/data/hex/hex.js +0 -28
  11. package/moddable/modules/data/hex/manifest.json +0 -11
  12. package/moddable/modules/data/hex/modHex.c +0 -139
  13. package/moddable/modules/data/logical/logical.js +0 -32
  14. package/moddable/modules/data/logical/modLogical.c +0 -98
  15. package/moddable/modules/data/qrcode/manifest.json +0 -9
  16. package/moddable/modules/data/qrcode/qrcode.c +0 -93
  17. package/moddable/modules/data/qrcode/qrcode.js +0 -23
  18. package/moddable/modules/data/qrcode/qrcodegen.c +0 -1025
  19. package/moddable/modules/data/qrcode/qrcodegen.h +0 -267
  20. package/moddable/modules/data/text/decoder/manifest.json +0 -8
  21. package/moddable/modules/data/text/decoder/textdecoder.c +0 -480
  22. package/moddable/modules/data/text/decoder/textdecoder.js +0 -27
  23. package/moddable/modules/data/text/encoder/manifest.json +0 -8
  24. package/moddable/modules/data/text/encoder/textencoder.c +0 -232
  25. package/moddable/modules/data/text/encoder/textencoder.js +0 -24
  26. package/moddable/modules/data/tinyint/tinyint.c +0 -150
  27. package/moddable/modules/data/tinyint/tinyint.js +0 -53
  28. package/moddable/modules/data/url/manifest.json +0 -17
  29. package/moddable/modules/data/url/url.c +0 -1959
  30. package/moddable/modules/data/url/url.js +0 -210
  31. package/moddable/modules/data/wavreader/manifest.json +0 -8
  32. package/moddable/modules/data/wavreader/wavreader.js +0 -128
  33. package/moddable/modules/data/zlib/deflate.c +0 -161
  34. package/moddable/modules/data/zlib/deflate.js +0 -63
  35. package/moddable/modules/data/zlib/inflate.c +0 -145
  36. package/moddable/modules/data/zlib/inflate.js +0 -66
  37. package/moddable/modules/data/zlib/manifest_deflate.json +0 -9
  38. package/moddable/modules/data/zlib/manifest_inflate.json +0 -9
  39. package/moddable/modules/data/zlib/miniz.c +0 -4924
  40. package/moddable/xs/includes/xs.d.ts +0 -73
  41. package/moddable/xs/includes/xs.h +0 -1533
  42. package/moddable/xs/includes/xsmc.h +0 -206
  43. package/moddable/xs/makefiles/lin/makefile +0 -33
  44. package/moddable/xs/makefiles/lin/xsc.mk +0 -118
  45. package/moddable/xs/makefiles/lin/xsid.mk +0 -90
  46. package/moddable/xs/makefiles/lin/xsl.mk +0 -168
  47. package/moddable/xs/makefiles/lin/xst.mk +0 -201
  48. package/moddable/xs/makefiles/mac/makefile +0 -33
  49. package/moddable/xs/makefiles/mac/xsc.mk +0 -130
  50. package/moddable/xs/makefiles/mac/xsid.mk +0 -102
  51. package/moddable/xs/makefiles/mac/xsl.mk +0 -177
  52. package/moddable/xs/makefiles/mac/xst.mk +0 -203
  53. package/moddable/xs/makefiles/mac/xst_no_asan.txt +0 -52
  54. package/moddable/xs/makefiles/win/build.bat +0 -26
  55. package/moddable/xs/makefiles/win/xsc.mak +0 -142
  56. package/moddable/xs/makefiles/win/xsid.mak +0 -113
  57. package/moddable/xs/makefiles/win/xsl.mak +0 -186
  58. package/moddable/xs/makefiles/win/xst.mak +0 -195
  59. package/moddable/xs/platforms/lin_xs.h +0 -99
  60. package/moddable/xs/platforms/mac_xs.h +0 -97
  61. package/moddable/xs/platforms/wasm_xs.h +0 -79
  62. package/moddable/xs/platforms/win_xs.h +0 -104
  63. package/moddable/xs/platforms/xsHost.h +0 -63
  64. package/moddable/xs/platforms/xsPlatform.h +0 -618
  65. package/moddable/xs/sources/xsAPI.c +0 -2555
  66. package/moddable/xs/sources/xsAll.c +0 -294
  67. package/moddable/xs/sources/xsAll.h +0 -2741
  68. package/moddable/xs/sources/xsArguments.c +0 -222
  69. package/moddable/xs/sources/xsArray.c +0 -2657
  70. package/moddable/xs/sources/xsAtomics.c +0 -844
  71. package/moddable/xs/sources/xsBigInt.c +0 -1859
  72. package/moddable/xs/sources/xsBoolean.c +0 -109
  73. package/moddable/xs/sources/xsCode.c +0 -4493
  74. package/moddable/xs/sources/xsCommon.c +0 -1710
  75. package/moddable/xs/sources/xsCommon.h +0 -1142
  76. package/moddable/xs/sources/xsDataView.c +0 -2890
  77. package/moddable/xs/sources/xsDate.c +0 -1541
  78. package/moddable/xs/sources/xsDebug.c +0 -2710
  79. package/moddable/xs/sources/xsDefaults.c +0 -134
  80. package/moddable/xs/sources/xsError.c +0 -353
  81. package/moddable/xs/sources/xsFunction.c +0 -776
  82. package/moddable/xs/sources/xsGenerator.c +0 -865
  83. package/moddable/xs/sources/xsGlobal.c +0 -839
  84. package/moddable/xs/sources/xsJSON.c +0 -1091
  85. package/moddable/xs/sources/xsLexical.c +0 -1969
  86. package/moddable/xs/sources/xsLockdown.c +0 -933
  87. package/moddable/xs/sources/xsMapSet.c +0 -1649
  88. package/moddable/xs/sources/xsMarshall.c +0 -1020
  89. package/moddable/xs/sources/xsMath.c +0 -624
  90. package/moddable/xs/sources/xsMemory.c +0 -1941
  91. package/moddable/xs/sources/xsModule.c +0 -3101
  92. package/moddable/xs/sources/xsNumber.c +0 -560
  93. package/moddable/xs/sources/xsObject.c +0 -1102
  94. package/moddable/xs/sources/xsPlatforms.c +0 -480
  95. package/moddable/xs/sources/xsProfile.c +0 -577
  96. package/moddable/xs/sources/xsPromise.c +0 -1199
  97. package/moddable/xs/sources/xsProperty.c +0 -636
  98. package/moddable/xs/sources/xsProxy.c +0 -1014
  99. package/moddable/xs/sources/xsRegExp.c +0 -1168
  100. package/moddable/xs/sources/xsRun.c +0 -4889
  101. package/moddable/xs/sources/xsScope.c +0 -1293
  102. package/moddable/xs/sources/xsScript.c +0 -288
  103. package/moddable/xs/sources/xsScript.h +0 -1186
  104. package/moddable/xs/sources/xsSnapshot.c +0 -2161
  105. package/moddable/xs/sources/xsSnapshot.h +0 -51
  106. package/moddable/xs/sources/xsSourceMap.c +0 -218
  107. package/moddable/xs/sources/xsString.c +0 -3332
  108. package/moddable/xs/sources/xsSymbol.c +0 -503
  109. package/moddable/xs/sources/xsSyntaxical.c +0 -4193
  110. package/moddable/xs/sources/xsTree.c +0 -1893
  111. package/moddable/xs/sources/xsType.c +0 -1488
  112. package/moddable/xs/sources/xsdtoa.c +0 -6672
  113. package/moddable/xs/sources/xsmc.c +0 -340
  114. package/moddable/xs/sources/xsre.c +0 -7578
  115. package/xsnap-native/xsnap/makefiles/lin/makefile +0 -10
  116. package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +0 -153
  117. package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +0 -144
  118. package/xsnap-native/xsnap/makefiles/mac/makefile +0 -10
  119. package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +0 -162
  120. package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +0 -153
  121. package/xsnap-native/xsnap/sources/xsnap-worker.c +0 -996
  122. package/xsnap-native/xsnap/sources/xsnap.c +0 -716
  123. package/xsnap-native/xsnap/sources/xsnap.h +0 -142
  124. package/xsnap-native/xsnap/sources/xsnapPlatform.c +0 -1496
  125. package/xsnap-native/xsnap/sources/xsnapPlatform.h +0 -105
@@ -1,577 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-2017 Moddable Tech, Inc.
3
- *
4
- * This file is part of the Moddable SDK Runtime.
5
- *
6
- * The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU Lesser General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * The Moddable SDK Runtime is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public License
17
- * along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- * This file incorporates work covered by the following copyright and
20
- * permission notice:
21
- *
22
- * Copyright (C) 2010-2016 Marvell International Ltd.
23
- * Copyright (C) 2002-2010 Kinoma, Inc.
24
- *
25
- * Licensed under the Apache License, Version 2.0 (the "License");
26
- * you may not use this file except in compliance with the License.
27
- * You may obtain a copy of the License at
28
- *
29
- * http://www.apache.org/licenses/LICENSE-2.0
30
- *
31
- * Unless required by applicable law or agreed to in writing, software
32
- * distributed under the License is distributed on an "AS IS" BASIS,
33
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34
- * See the License for the specific language governing permissions and
35
- * limitations under the License.
36
- */
37
-
38
-
39
- #define _GNU_SOURCE
40
- #include "xsAll.h"
41
- #if mxMacOSX || mxLinux
42
- #include <dlfcn.h>
43
- #endif
44
-
45
- #ifdef mxProfile
46
-
47
- typedef struct sxProfiler txProfiler;
48
- typedef struct sxProfilerRecord txProfilerRecord;
49
- typedef struct sxProfilerSample txProfilerSample;
50
-
51
- struct sxProfiler {
52
- txU8 when;
53
- txU8 former;
54
- txU8 start;
55
- txU8 stop;
56
- txU4 interval;
57
- txU4 recordCount;
58
- txProfilerRecord** records;
59
- txU8 sampleCount;
60
- txU8 sampleIndex;
61
- txProfilerSample* samples;
62
- txProfilerRecord* host;
63
- txProfilerRecord* gc;
64
- };
65
-
66
- struct sxProfilerRecord {
67
- txID recordID;
68
- txID constructorID;
69
- txID prototypeID;
70
- txID functionID;
71
- txCallback functionAddress;
72
- txID file;
73
- txInteger line;
74
- txInteger hitCount;
75
- txInteger calleeCount;
76
- txID* callees;
77
- txInteger flags;
78
- };
79
-
80
- struct sxProfilerSample {
81
- txID recordID;
82
- txU4 delta;
83
- };
84
-
85
- static txProfilerRecord* fxFrameToProfilerRecord(txMachine* the, txSlot* frame);
86
- static txU8 fxGetTicks();
87
- static void fxInsertProfilerCallee(txMachine* the, txProfilerRecord* record, txID recordID);
88
- static txU8 fxMicrosecondsToTicks(txU8 microseconds);
89
- static void fxPrintID(txMachine* the, FILE* file, txID id);
90
- static void fxPrintProfiler(txMachine* the, void* stream);
91
- static void fxPrintString(txMachine* the, FILE* file, txString theString);
92
- static void fxPushProfilerSample(txMachine* the, txID recordID, txU4 delta);
93
- static txProfilerRecord* fxNewProfilerRecord(txMachine* the, txID recordID);
94
- static txID fxRemoveProfilerCycle(txMachine* the, txProfiler* profiler, txID recordID);
95
- static txU8 fxTicksToMicroseconds(txU8 ticks);
96
-
97
- void fxCheckProfiler(txMachine* the, txSlot* frame)
98
- {
99
- txProfiler* profiler = the->profiler;
100
- if (!profiler)
101
- return;
102
- txU8 when = profiler->when;
103
- txU8 time = fxGetTicks();
104
- if (when < time) {
105
- txProfilerRecord* callee = C_NULL;
106
- txProfilerRecord* record = C_NULL;
107
- if (frame) {
108
- record = fxFrameToProfilerRecord(the, frame);
109
- frame = frame->next;
110
- }
111
- else {
112
- frame = the->frame;
113
- if (frame)
114
- record = profiler->gc;
115
- }
116
- if (record) {
117
- callee = record;
118
- while (frame) {
119
- txProfilerRecord* parent = fxFrameToProfilerRecord(the, frame);
120
- if (parent) {
121
- fxInsertProfilerCallee(the, parent, callee->recordID);
122
- callee = parent;
123
- }
124
- frame = frame->next;
125
- }
126
- }
127
- if (callee)
128
- fxInsertProfilerCallee(the, profiler->host, callee->recordID);
129
- else
130
- record = profiler->host;
131
- txU4 interval = profiler->interval;
132
- record->hitCount++;
133
- fxPushProfilerSample(the, record->recordID, (txU4)(time - profiler->former));
134
- profiler->former = time;
135
- profiler->when = time + interval - (time % interval);
136
- }
137
- }
138
-
139
- void fxCreateProfiler(txMachine* the)
140
- {
141
- txProfiler* profiler = the->profiler = c_malloc(sizeof(txProfiler));
142
- if (profiler == C_NULL)
143
- fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT);
144
- profiler->interval = (txU4)fxMicrosecondsToTicks(1250);
145
- profiler->former = fxGetTicks();
146
- profiler->when = profiler->former + profiler->interval;
147
- profiler->start = profiler->former;
148
-
149
- profiler->recordCount = 2;
150
- profiler->records = (txProfilerRecord**)c_calloc(sizeof(txProfilerRecord*), profiler->recordCount);
151
- if (profiler->records == C_NULL)
152
- fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT);
153
-
154
- profiler->sampleCount = 1024;
155
- profiler->sampleIndex = 0;
156
- profiler->samples = (txProfilerSample*)c_malloc((size_t)(profiler->sampleCount * sizeof(txProfilerSample)));
157
- if (profiler->samples == C_NULL)
158
- fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT);
159
- profiler->host = fxNewProfilerRecord(the, 0);
160
- profiler->gc = fxNewProfilerRecord(the, 1);
161
- }
162
-
163
- void fxDeleteProfiler(txMachine* the, void* stream)
164
- {
165
- txProfiler* profiler = the->profiler;
166
- profiler->stop = profiler->when;
167
- fxPrintProfiler(the, stream);
168
- c_free(profiler->samples);
169
- txU4 recordIndex = 0;
170
- while (recordIndex < profiler->recordCount) {
171
- txProfilerRecord* record = profiler->records[recordIndex];
172
- if (record) {
173
- if (record->callees)
174
- c_free(record->callees);
175
- c_free(record);
176
- }
177
- recordIndex++;
178
- }
179
- c_free(profiler->records);
180
- c_free(profiler);
181
- the->profiler = C_NULL;
182
- }
183
-
184
- txProfilerRecord* fxFrameToProfilerRecord(txMachine* the, txSlot* frame)
185
- {
186
- txProfiler* profiler = the->profiler;
187
- txSlot* function = frame + 3;
188
- if (function->kind == XS_REFERENCE_KIND) {
189
- function = function->value.reference;
190
- if (mxIsFunction(function)) {
191
- txSlot* code = mxFunctionInstanceCode(function);
192
- txSlot* home = mxFunctionInstanceHome(function);
193
- txID recordID = home->ID;
194
- txProfilerRecord* record = C_NULL;
195
- if (recordID < profiler->recordCount)
196
- record = profiler->records[recordID];
197
- if (record)
198
- return record;
199
- record = fxNewProfilerRecord(the, recordID);
200
- record->functionID = code->ID;
201
- home = home->value.home.object;
202
- if (home) {
203
- if (mxIsFunction(home)) {
204
- record->constructorID = mxFunctionInstanceCode(home)->ID;
205
- }
206
- else {
207
- txSlot* property = home->next;
208
- while (property && (property->flag & XS_INTERNAL_FLAG))
209
- property = property->next;
210
- while (property) {
211
- if (property->ID == mxID(_constructor))
212
- break;
213
- property = property->next;
214
- }
215
- if (property) {
216
- if (property->kind == XS_REFERENCE_KIND) {
217
- property = property->value.reference;
218
- if (mxIsFunction(property)) {
219
- record->constructorID = mxFunctionInstanceCode(property)->ID;
220
- record->prototypeID = mxID(_prototype);
221
- }
222
- }
223
- }
224
- else {
225
- property = home->next;
226
- while (property) {
227
- if (property->ID == mxID(_Symbol_toStringTag))
228
- break;
229
- property = property->next;
230
- }
231
- if (property) {
232
- if ((property->kind == XS_STRING_KIND) || (property->kind == XS_STRING_X_KIND)) {
233
- record->prototypeID = fxFindName(the, property->value.string);
234
- }
235
- }
236
- }
237
- }
238
- }
239
- if ((code->kind == XS_CODE_KIND) || (code->kind == XS_CODE_X_KIND)) {
240
- txByte* p = code->value.code.address + 2;
241
- if (*p == XS_CODE_FILE) {
242
- txID file;
243
- txS2 line;
244
- p++;
245
- mxDecodeID(p, file);
246
- p++;
247
- mxDecode2(p, line);
248
- record->file = file;
249
- record->line = line;
250
- }
251
- record->functionAddress = C_NULL;
252
- }
253
- else
254
- record->functionAddress = code->value.callback.address;
255
- return record;
256
- }
257
- }
258
- return C_NULL;
259
- }
260
-
261
- txU8 fxGetTicks()
262
- {
263
- #if mxMacOSX
264
- return clock_gettime_nsec_np(CLOCK_MONOTONIC);
265
- #elif mxWindows
266
- LARGE_INTEGER counter;
267
- QueryPerformanceCounter(&counter);
268
- return counter.QuadPart;
269
- #else
270
- c_timeval tv;
271
- c_gettimeofday(&tv, NULL);
272
- return (tv.tv_sec * 1000000ULL) + tv.tv_usec;
273
- #endif
274
- }
275
-
276
- void fxInsertProfilerCallee(txMachine* the, txProfilerRecord* record, txID recordID)
277
- {
278
- txInteger count = record->calleeCount;
279
- if (count == 0) {
280
- record->callees = c_malloc(sizeof(txID));
281
- if (record->callees == C_NULL)
282
- fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT);
283
- record->calleeCount = 1;
284
- record->callees[0] = recordID;
285
- return;
286
- }
287
- txInteger min = 0;
288
- txInteger max = count;
289
- txInteger mid;
290
- txID* callee = record->callees;
291
- while (min < max) {
292
- mid = (min + max) >> 1;
293
- callee = record->callees + mid;
294
- if (recordID < *callee)
295
- max = mid;
296
- else if (recordID > *callee)
297
- min = mid + 1;
298
- else
299
- return;
300
- }
301
- if (recordID > *callee)
302
- mid++;
303
- record->calleeCount++;
304
- record->callees = c_realloc(record->callees, record->calleeCount * sizeof(txID));
305
- if (record->callees == C_NULL)
306
- fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT);
307
- callee = record->callees + mid;
308
- if (mid < count)
309
- c_memmove(callee + 1, callee, (count - mid) * sizeof(txID));
310
- *callee = recordID;
311
- }
312
-
313
- txU8 fxMicrosecondsToTicks(txU8 microseconds)
314
- {
315
- #if mxMacOSX
316
- return microseconds * 1000;
317
- #elif mxWindows
318
- LARGE_INTEGER frequency;
319
- QueryPerformanceFrequency(&frequency);
320
- return (frequency.QuadPart * microseconds) / 1000000ULL;
321
- #else
322
- return microseconds;
323
- #endif
324
- }
325
-
326
- txProfilerRecord* fxNewProfilerRecord(txMachine* the, txID recordID)
327
- {
328
- txProfiler* profiler = the->profiler;
329
- txU4 recordCount = profiler->recordCount;
330
- txProfilerRecord* record;
331
- if (recordID >= recordCount) {
332
- recordCount = recordID + 1;
333
- profiler->records = (txProfilerRecord**)c_realloc(profiler->records, recordCount * sizeof(txProfilerRecord*));
334
- if (profiler->records == C_NULL)
335
- fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT);
336
- c_memset(profiler->records + profiler->recordCount, 0, (recordCount - profiler->recordCount) * sizeof(txProfilerRecord*));
337
- profiler->recordCount = recordCount;
338
- }
339
- record = c_malloc(sizeof(txProfilerRecord));
340
- if (record == C_NULL)
341
- fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT);
342
- record->recordID = recordID;
343
- record->hitCount = 0;
344
- record->constructorID = XS_NO_ID;
345
- record->prototypeID = XS_NO_ID;
346
- record->functionID = XS_NO_ID;
347
- record->file = XS_NO_ID;
348
- record->line = 0;
349
- record->calleeCount = 0;
350
- record->callees = C_NULL;
351
- record->flags = 0;
352
- profiler->records[recordID] = record;
353
- return record;
354
- }
355
-
356
- void fxPrintID(txMachine* the, FILE* file, txID id)
357
- {
358
- txSlot* key = fxGetKey(the, id);
359
- if (key) {
360
- if ((key->kind == XS_KEY_KIND) || (key->kind == XS_KEY_X_KIND)) {
361
- fxPrintString(the, file, key->value.key.string);
362
- return;
363
- }
364
- if ((key->kind == XS_STRING_KIND) || (key->kind == XS_STRING_X_KIND)) {
365
- fprintf(file, "[");
366
- fxPrintString(the, file, key->value.string);
367
- fprintf(file, "]");
368
- return;
369
- }
370
- }
371
- fprintf(file, "?");
372
- }
373
-
374
- void fxPrintProfiler(txMachine* the, void* stream)
375
- {
376
- // https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#type-Profile
377
- txProfiler* profiler = the->profiler;
378
- FILE* file = stream;
379
- char buffer[22];
380
- char name[36];
381
-
382
- fxRemoveProfilerCycle(the, profiler, 0);
383
-
384
- if (!file) {
385
- time_t timer;
386
- struct tm* tm_info;
387
- timer = time(NULL);
388
- tm_info = localtime(&timer);
389
- strftime(buffer, 22, "XS-%y-%m-%d-%H-%M-%S-", tm_info);
390
- snprintf(name, sizeof(name), "%s%03llu.cpuprofile", buffer, (profiler->stop / 1000) % 1000);
391
- file = fopen(name, "w");
392
- }
393
-
394
- fprintf(file, "{\"nodes\":[");
395
- txU4 recordIndex = 0;
396
- while (recordIndex < profiler->recordCount) {
397
- txProfilerRecord* record = profiler->records[recordIndex];
398
- if (record) {
399
- if (recordIndex > 0)
400
- fprintf(file, ",");
401
- fprintf(file, "{\"id\":%d,\"callFrame\":{\"functionName\":\"", record->recordID);
402
- if (recordIndex == 0)
403
- fprintf(file, "(host)");
404
- else if (recordIndex == 1)
405
- fprintf(file, "(gc)");
406
- else if (record->functionID != XS_NO_ID) {
407
- if (record->constructorID != XS_NO_ID) {
408
- fxPrintID(the, file, record->constructorID);
409
- fprintf(file, ".");
410
- }
411
- if (record->prototypeID != XS_NO_ID) {
412
- fxPrintID(the, file, record->prototypeID);
413
- fprintf(file, ".");
414
- }
415
- fxPrintID(the, file, record->functionID);
416
- }
417
- else if (record->functionAddress) {
418
- #if mxMacOSX || mxLinux
419
- Dl_info info;
420
- if (dladdr(record->functionAddress, &info) && info.dli_sname)
421
- fprintf(file, "@%s",info.dli_sname );
422
- else
423
- #endif
424
- fprintf(file, "@anonymous-%d", record->recordID);
425
- }
426
- else
427
- fprintf(file, "(anonymous-%d)", record->recordID);
428
-
429
- fprintf(file, "\",\"scriptId\":\"0\",\"url\":\"");
430
- if (record->file != XS_NO_ID)
431
- fxPrintID(the, file, record->file);
432
- fprintf(file, "\",\"lineNumber\":%d,\"columnNumber\":-1},\"hitCount\":%d,\"children\":[", record->line - 1, record->hitCount);
433
- txInteger calleeIndex = 0;
434
- txBoolean comma = 0;
435
- while (calleeIndex < record->calleeCount) {
436
- txID recordID = record->callees[calleeIndex];
437
- if (recordID != XS_NO_ID) {
438
- if (comma)
439
- fprintf(file, ",");
440
- fprintf(file, "%d", recordID);
441
- comma = 1;
442
- }
443
- calleeIndex++;
444
- }
445
- fprintf(file, "]}");
446
- }
447
- recordIndex++;
448
- }
449
- fprintf(file, "],\"startTime\":%llu,\"endTime\":%llu,\"samples\":[", fxTicksToMicroseconds(profiler->start), fxTicksToMicroseconds(profiler->when));
450
- {
451
- txU8 sampleIndex = 0;
452
- while (sampleIndex < profiler->sampleIndex) {
453
- txProfilerSample* sample = profiler->samples + sampleIndex;
454
- if (sampleIndex > 0)
455
- fprintf(file, ",");
456
- fprintf(file, "%d", sample->recordID);
457
- sampleIndex++;
458
- }
459
- }
460
- fprintf(file, "],\"timeDeltas\":[");
461
- {
462
- txU8 sampleIndex = 0;
463
- while (sampleIndex < profiler->sampleIndex) {
464
- txProfilerSample* sample = profiler->samples + sampleIndex;
465
- if (sampleIndex > 0)
466
- fprintf(file, ",");
467
- fprintf(file, "%llu", fxTicksToMicroseconds(sample->delta));
468
- sampleIndex++;
469
- }
470
- }
471
- fprintf(file, "]}");
472
- fclose(file);
473
- }
474
-
475
- void fxPrintString(txMachine* the, FILE* file, txString theString)
476
- {
477
- char buffer[16];
478
- for (;;) {
479
- txInteger character;
480
- char *p;
481
- theString = mxStringByteDecode(theString, &character);
482
- if (character == C_EOF)
483
- break;
484
- p = buffer;
485
- if ((character < 32) || ((0xD800 <= character) && (character <= 0xDFFF))) {
486
- *p++ = '\\';
487
- *p++ = 'u';
488
- p = fxStringifyUnicodeEscape(p, character, '\\');
489
- }
490
- else if (character == '"') {
491
- *p++ = '\\';
492
- *p++ = '"';
493
- }
494
- else if (character == '\\') {
495
- *p++ = '\\';
496
- *p++ = '\\';
497
- }
498
- else
499
- p = mxStringByteEncode(p, character);
500
- *p = 0;
501
- fprintf(file, "%s", buffer);
502
- }
503
- }
504
-
505
- void fxPushProfilerSample(txMachine* the, txID recordID, txU4 delta)
506
- {
507
- txProfiler* profiler = the->profiler;
508
- txU8 sampleCount = profiler->sampleCount;
509
- txU8 sampleIndex = profiler->sampleIndex;
510
- txProfilerSample* sample;
511
- if (sampleIndex == sampleCount) {
512
- sampleCount += 1024;
513
- profiler->samples = (txProfilerSample*)c_realloc(profiler->samples, (size_t)(sampleCount * sizeof(txProfilerSample)));
514
- if (profiler->samples == C_NULL)
515
- fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT);
516
- profiler->sampleCount = sampleCount;
517
- }
518
- sample = profiler->samples + sampleIndex;
519
- sample->recordID = recordID;
520
- sample->delta = delta;
521
- profiler->sampleIndex = sampleIndex + 1;
522
- }
523
-
524
- txID fxRemoveProfilerCycle(txMachine* the, txProfiler* profiler, txID recordID)
525
- {
526
- txProfilerRecord* record = profiler->records[recordID];
527
- if (record->flags & 1)
528
- return XS_NO_ID;
529
- if (record->flags & 2)
530
- return recordID;
531
- record->flags |= 3;
532
- txInteger calleeIndex = 0;
533
- while (calleeIndex < record->calleeCount) {
534
- txID calleeID = record->callees[calleeIndex];
535
- if (calleeID)
536
- record->callees[calleeIndex] = fxRemoveProfilerCycle(the, profiler, calleeID);
537
- calleeIndex++;
538
- }
539
- record->flags &= ~1;
540
- return recordID;
541
- }
542
-
543
- void fxResumeProfiler(txMachine* the)
544
- {
545
- txProfiler* profiler = the->profiler;
546
- if (!profiler)
547
- return;
548
- txU8 delta = fxGetTicks() - profiler->stop;
549
- profiler->when += delta;
550
- profiler->former += delta;
551
- profiler->start += delta;
552
- }
553
-
554
- void fxSuspendProfiler(txMachine* the)
555
- {
556
- txProfiler* profiler = the->profiler;
557
- if (!profiler)
558
- return;
559
- profiler->stop = fxGetTicks();
560
- }
561
-
562
- txU8 fxTicksToMicroseconds(txU8 ticks)
563
- {
564
- #if mxMacOSX
565
- return ticks / 1000;
566
- #elif mxWindows
567
- LARGE_INTEGER frequency;
568
- QueryPerformanceFrequency(&frequency);
569
- return (1000000ULL * ticks) / frequency.QuadPart;
570
- #else
571
- return ticks;
572
- #endif
573
- }
574
-
575
-
576
-
577
- #endif /* mxProfile */