| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 004b9ea commit f077afa
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -238,7 +238,8 @@ size_t BlobSerializer<Impl>::WriteVector(const std::vector<T>& data) { | |||
| 238 | 238 | if (is_debug) { | |
| 239 | 239 | std::string str = std::is_arithmetic_v<T> ? "" : ToStr(data); | |
| 240 | 240 | std::string name = GetName<T>(); | |
| 241 | - Debug("\nWriteVector<%s>() (%d-byte), count=%d: %s\n", | ||
| 241 | + Debug("\nAt 0x%x: WriteVector<%s>() (%d-byte), count=%d: %s\n", | ||
| 242 | + sink.size(), | ||
| 242 | 243 | name.c_str(), | |
| 243 | 244 | sizeof(T), | |
| 244 | 245 | data.size(), | |
@@ -270,7 +271,10 @@ size_t BlobSerializer<Impl>::WriteVector(const std::vector<T>& data) { | |||
| 270 | 271 | template <typename Impl> | |
| 271 | 272 | size_t BlobSerializer<Impl>::WriteStringView(std::string_view data, | |
| 272 | 273 | StringLogMode mode) { | |
| 273 | - Debug("WriteStringView(), length=%zu: %p\n", data.size(), data.data()); | ||
| 274 | + Debug("At 0x%x: WriteStringView(), length=%zu: %p\n", | ||
| 275 | + sink.size(), | ||
| 276 | + data.size(), | ||
| 277 | + data.data()); | ||
| 274 | 278 | size_t written_total = WriteArithmetic<size_t>(data.size()); | |
| 275 | 279 | ||
| 276 | 280 | size_t length = data.size(); | |
@@ -294,17 +298,27 @@ size_t BlobSerializer<Impl>::WriteString(const std::string& data) { | |||
| 294 | 298 | return WriteStringView(data, StringLogMode::kAddressAndContent); | |
| 295 | 299 | } | |
| 296 | 300 | ||
| 301 | + static size_t kPreviewCount = 16; | ||
| 302 | + | ||
| 297 | 303 | // Helper for writing an array of numeric types. | |
| 298 | 304 | template <typename Impl> | |
| 299 | 305 | template <typename T> | |
| 300 | 306 | size_t BlobSerializer<Impl>::WriteArithmetic(const T* data, size_t count) { | |
| 301 | 307 | static_assert(std::is_arithmetic_v<T>, "Arithmetic type"); | |
| 302 | 308 | DCHECK_GT(count, 0); // Should not write contents for vectors of size 0. | |
| 303 | 309 | if (is_debug) { | |
| 304 | - std::string str = | ||
| 305 | - "{ " + std::to_string(data[0]) + (count > 1 ? ", ... }" : " }"); | ||
| 310 | + size_t preview_count = count < kPreviewCount ? count : kPreviewCount; | ||
| 311 | + std::string str = "{ "; | ||
| 312 | + for (size_t i = 0; i < preview_count; ++i) { | ||
| 313 | + str += (std::to_string(data[i]) + ","); | ||
| 314 | + } | ||
| 315 | + if (count > preview_count) { | ||
| 316 | + str += "..."; | ||
| 317 | + } | ||
| 318 | + str += "}"; | ||
| 306 | 319 | std::string name = GetName<T>(); | |
| 307 | - Debug("Write<%s>() (%zu-byte), count=%zu: %s", | ||
| 320 | + Debug("At 0x%x: Write<%s>() (%zu-byte), count=%zu: %s", | ||
| 321 | + sink.size(), | ||
| 308 | 322 | name.c_str(), | |
| 309 | 323 | sizeof(T), | |
| 310 | 324 | count, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1337,18 +1337,24 @@ ExitCode GenerateAndWriteSnapshotData(const SnapshotData** snapshot_data_ptr, | |||
| 1337 | 1337 | return exit_code; | |
| 1338 | 1338 | } | |
| 1339 | 1339 | } else { | |
| 1340 | + std::optional<std::string> builder_script_content; | ||
| 1340 | 1341 | // Otherwise, load and run the specified builder script. | |
| 1341 | 1342 | std::unique_ptr<SnapshotData> generated_data = | |
| 1342 | 1343 | std::make_unique<SnapshotData>(); | |
| 1343 | - std::string builder_script_content; | ||
| 1344 | - int r = ReadFileSync(&builder_script_content, builder_script.c_str()); | ||
| 1345 | - if (r != 0) { | ||
| 1346 | - FPrintF(stderr, | ||
| 1347 | - "Cannot read builder script %s for building snapshot. %s: %s", | ||
| 1348 | - builder_script, | ||
| 1349 | - uv_err_name(r), | ||
| 1350 | - uv_strerror(r)); | ||
| 1351 | - return ExitCode::kGenericUserError; | ||
| 1344 | + if (builder_script != "node:generate_default_snapshot") { | ||
| 1345 | + builder_script_content = std::string(); | ||
| 1346 | + int r = ReadFileSync(&(builder_script_content.value()), | ||
| 1347 | + builder_script.c_str()); | ||
| 1348 | + if (r != 0) { | ||
| 1349 | + FPrintF(stderr, | ||
| 1350 | + "Cannot read builder script %s for building snapshot. %s: %s\n", | ||
| 1351 | + builder_script, | ||
| 1352 | + uv_err_name(r), | ||
| 1353 | + uv_strerror(r)); | ||
| 1354 | + return ExitCode::kGenericUserError; | ||
| 1355 | + } | ||
| 1356 | + } else { | ||
| 1357 | + snapshot_config.builder_script_path = std::nullopt; | ||
| 1352 | 1358 | } | |
| 1353 | 1359 | ||
| 1354 | 1360 | exit_code = node::SnapshotBuilder::Generate(generated_data.get(), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -599,16 +599,17 @@ std::vector<char> SnapshotData::ToBlob() const { | |||
| 599 | 599 | size_t written_total = 0; | |
| 600 | 600 | ||
| 601 | 601 | // Metadata | |
| 602 | - w.Debug("Write magic %" PRIx32 "\n", kMagic); | ||
| 602 | + w.Debug("0x%x: Write magic %" PRIx32 "\n", w.sink.size(), kMagic); | ||
| 603 | 603 | written_total += w.WriteArithmetic<uint32_t>(kMagic); | |
| 604 | - w.Debug("Write metadata\n"); | ||
| 604 | + w.Debug("0x%x: Write metadata\n", w.sink.size()); | ||
| 605 | 605 | written_total += w.Write<SnapshotMetadata>(metadata); | |
| 606 | - | ||
| 606 | + w.Debug("0x%x: Write snapshot blob\n", w.sink.size()); | ||
| 607 | 607 | written_total += w.Write<v8::StartupData>(v8_snapshot_blob_data); | |
| 608 | - w.Debug("Write isolate_data_indices\n"); | ||
| 608 | + w.Debug("0x%x: Write IsolateDataSerializeInfo\n", w.sink.size()); | ||
| 609 | 609 | written_total += w.Write<IsolateDataSerializeInfo>(isolate_data_info); | |
| 610 | + w.Debug("0x%x: Write EnvSerializeInfo\n", w.sink.size()); | ||
| 610 | 611 | written_total += w.Write<EnvSerializeInfo>(env_info); | |
| 611 | - w.Debug("Write code_cache\n"); | ||
| 612 | + w.Debug("0x%x: Write CodeCacheInfo\n", w.sink.size()); | ||
| 612 | 613 | written_total += w.WriteVector<builtins::CodeCacheInfo>(code_cache); | |
| 613 | 614 | w.Debug("SnapshotData::ToBlob() Wrote %d bytes\n", written_total); | |
| 614 | 615 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,70 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + const { spawnSyncAndAssert } = require('../common/child_process'); | ||
| 5 | + const tmpdir = require('../common/tmpdir'); | ||
| 6 | + const fs = require('fs'); | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + | ||
| 9 | + // When the test fails this helper can be modified to write outputs | ||
| 10 | + // differently and aid debugging. | ||
| 11 | + function log(line) { | ||
| 12 | + console.log(line); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + function generateSnapshot() { | ||
| 16 | + tmpdir.refresh(); | ||
| 17 | + | ||
| 18 | + spawnSyncAndAssert( | ||
| 19 | + process.execPath, | ||
| 20 | + [ | ||
| 21 | + '--random_seed=42', | ||
| 22 | + '--predictable', | ||
| 23 | + '--build-snapshot', | ||
| 24 | + 'node:generate_default_snapshot', | ||
| 25 | + ], | ||
| 26 | + { | ||
| 27 | + env: { ...process.env, NODE_DEBUG_NATIVE: 'SNAPSHOT_SERDES' }, | ||
| 28 | + cwd: tmpdir.path | ||
| 29 | + }, | ||
| 30 | + { | ||
| 31 | + stderr(output) { | ||
| 32 | + const lines = output.split('\n'); | ||
| 33 | + for (const line of lines) { | ||
| 34 | + if (line.startsWith('0x')) { | ||
| 35 | + log(line); | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + }, | ||
| 39 | + } | ||
| 40 | + ); | ||
| 41 | + const blobPath = tmpdir.resolve('snapshot.blob'); | ||
| 42 | + return fs.readFileSync(blobPath); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + const buf1 = generateSnapshot(); | ||
| 46 | + const buf2 = generateSnapshot(); | ||
| 47 | + | ||
| 48 | + const diff = []; | ||
| 49 | + let offset = 0; | ||
| 50 | + const step = 16; | ||
| 51 | + do { | ||
| 52 | + const length = Math.min(buf1.length - offset, step); | ||
| 53 | + const slice1 = buf1.slice(offset, offset + length).toString('hex'); | ||
| 54 | + const slice2 = buf2.slice(offset, offset + length).toString('hex'); | ||
| 55 | + if (slice1 !== slice2) { | ||
| 56 | + diff.push({ offset: '0x' + (offset).toString(16), slice1, slice2 }); | ||
| 57 | + } | ||
| 58 | + offset += length; | ||
| 59 | + } while (offset < buf1.length); | ||
| 60 | + | ||
| 61 | + assert.strictEqual(offset, buf1.length); | ||
| 62 | + if (offset < buf2.length) { | ||
| 63 | + const length = Math.min(buf2.length - offset, step); | ||
| 64 | + const slice2 = buf2.slice(offset, offset + length).toString('hex'); | ||
| 65 | + diff.push({ offset, slice1: '', slice2 }); | ||
| 66 | + offset += length; | ||
| 67 | + } while (offset < buf2.length); | ||
| 68 | + | ||
| 69 | + assert.deepStrictEqual(diff, []); | ||
| 70 | + assert.strictEqual(buf1.length, buf2.length); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments