Skip to content

Commit 4ef857e

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm] Add buffering of --trace_precompiler_to output in memory
Under certain circumstances we see that gen_snapshot spends significant portion of time in kernel. This happens with --trace_precompiler_to option specified on the command line. This change reduces number of I/O operations required to write --trace_precompiler_to output by adding a memory buffer for the whole output. TEST=pkg/vm_snapshot_analysis/test/precompiler_trace_test.dart Change-Id: I7c2b3fbf1f6b6bee950c2d23809e68e4698f84f4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175780 Commit-Queue: Alexander Markov <[email protected]> Reviewed-by: Vyacheslav Egorov <[email protected]>
1 parent 96552d2 commit 4ef857e

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

runtime/platform/text_buffer.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,18 @@ namespace dart {
1414
intptr_t BaseTextBuffer::Printf(const char* format, ...) {
1515
va_list args;
1616
va_start(args, format);
17+
intptr_t len = VPrintf(format, args);
18+
va_end(args);
19+
return len;
20+
}
21+
22+
intptr_t BaseTextBuffer::VPrintf(const char* format, va_list args) {
23+
va_list args1;
24+
va_copy(args1, args);
1725
intptr_t remaining = capacity_ - length_;
1826
ASSERT(remaining >= 0);
19-
intptr_t len = Utils::VSNPrint(buffer_ + length_, remaining, format, args);
20-
va_end(args);
27+
intptr_t len = Utils::VSNPrint(buffer_ + length_, remaining, format, args1);
28+
va_end(args1);
2129
if (len >= remaining) {
2230
if (!EnsureCapacity(len)) {
2331
length_ = capacity_ - 1;
@@ -27,7 +35,7 @@ intptr_t BaseTextBuffer::Printf(const char* format, ...) {
2735
remaining = capacity_ - length_;
2836
ASSERT(remaining > len);
2937
va_list args2;
30-
va_start(args2, format);
38+
va_copy(args2, args);
3139
intptr_t len2 =
3240
Utils::VSNPrint(buffer_ + length_, remaining, format, args2);
3341
va_end(args2);

runtime/platform/text_buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class BaseTextBuffer : public ValueObject {
2020
virtual ~BaseTextBuffer() {}
2121

2222
intptr_t Printf(const char* format, ...) PRINTF_ATTRIBUTE(2, 3);
23+
intptr_t VPrintf(const char* format, va_list args);
2324
void AddChar(char ch);
2425
void EscapeAndAddUTF16CodeUnit(uint16_t cu);
2526
void EscapeAndAddCodeUnit(uint32_t cu);

runtime/vm/compiler/aot/precompiler_tracer.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ PrecompilerTracer* PrecompilerTracer::StartTracingIfRequested(
3232
PrecompilerTracer::PrecompilerTracer(Precompiler* precompiler, void* stream)
3333
: zone_(Thread::Current()->zone()),
3434
precompiler_(precompiler),
35+
buffer_(1024),
3536
stream_(stream),
3637
strings_(HashTables::New<StringTable>(1024)),
3738
entities_(HashTables::New<EntityTable>(1024)),
@@ -46,6 +47,11 @@ void PrecompilerTracer::Finalize() {
4647
Write(",");
4748
WriteStringTable();
4849
Write("}\n");
50+
51+
const intptr_t output_length = buffer_.length();
52+
char* output = buffer_.Steal();
53+
Dart::file_write_callback()(output, output_length, stream_);
54+
free(output);
4955
Dart::file_close_callback()(stream_);
5056

5157
strings_.Release();

runtime/vm/compiler/aot/precompiler_tracer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ class PrecompilerTracer : public ZoneAllocated {
119119
void Write(const char* format, ...) PRINTF_ATTRIBUTE(2, 3) {
120120
va_list va;
121121
va_start(va, format);
122-
const char* line = OS::VSCreate(zone_, format, va);
123-
Dart::file_write_callback()(line, strlen(line), stream_);
122+
buffer_.VPrintf(format, va);
124123
va_end(va);
125124
}
126125

@@ -131,6 +130,7 @@ class PrecompilerTracer : public ZoneAllocated {
131130

132131
Zone* zone_;
133132
Precompiler* precompiler_;
133+
TextBuffer buffer_;
134134
void* stream_;
135135
StringTable strings_;
136136
EntityTable entities_;

0 commit comments

Comments
 (0)