Add OS::GetCurrentProcessId and prepend output from trace-gc with the current pid

BUG=none
TEST=manual

Review URL: https://chromiumcodereview.appspot.com/9817002
Patch from Jochen Eisinger <jochen@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12032 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
mstarzinger@chromium.org 2012-07-10 12:52:36 +00:00
parent 5aacb93168
commit 97cbaec08a
11 changed files with 103 additions and 65 deletions

View File

@ -320,52 +320,52 @@ void Heap::ReportStatisticsBeforeGC() {
void Heap::PrintShortHeapStatistics() {
if (!FLAG_trace_gc_verbose) return;
PrintF("Memory allocator, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB\n",
isolate_->memory_allocator()->Size() / KB,
isolate_->memory_allocator()->Available() / KB);
PrintF("New space, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
new_space_.Size() / KB,
new_space_.Available() / KB,
new_space_.CommittedMemory() / KB);
PrintF("Old pointers, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
old_pointer_space_->SizeOfObjects() / KB,
old_pointer_space_->Available() / KB,
old_pointer_space_->CommittedMemory() / KB);
PrintF("Old data space, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
old_data_space_->SizeOfObjects() / KB,
old_data_space_->Available() / KB,
old_data_space_->CommittedMemory() / KB);
PrintF("Code space, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
code_space_->SizeOfObjects() / KB,
code_space_->Available() / KB,
code_space_->CommittedMemory() / KB);
PrintF("Map space, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
map_space_->SizeOfObjects() / KB,
map_space_->Available() / KB,
map_space_->CommittedMemory() / KB);
PrintF("Cell space, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
cell_space_->SizeOfObjects() / KB,
cell_space_->Available() / KB,
cell_space_->CommittedMemory() / KB);
PrintF("Large object space, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
lo_space_->SizeOfObjects() / KB,
lo_space_->Available() / KB,
lo_space_->CommittedMemory() / KB);
PrintPID("Memory allocator, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB\n",
isolate_->memory_allocator()->Size() / KB,
isolate_->memory_allocator()->Available() / KB);
PrintPID("New space, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
new_space_.Size() / KB,
new_space_.Available() / KB,
new_space_.CommittedMemory() / KB);
PrintPID("Old pointers, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
old_pointer_space_->SizeOfObjects() / KB,
old_pointer_space_->Available() / KB,
old_pointer_space_->CommittedMemory() / KB);
PrintPID("Old data space, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
old_data_space_->SizeOfObjects() / KB,
old_data_space_->Available() / KB,
old_data_space_->CommittedMemory() / KB);
PrintPID("Code space, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
code_space_->SizeOfObjects() / KB,
code_space_->Available() / KB,
code_space_->CommittedMemory() / KB);
PrintPID("Map space, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
map_space_->SizeOfObjects() / KB,
map_space_->Available() / KB,
map_space_->CommittedMemory() / KB);
PrintPID("Cell space, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
cell_space_->SizeOfObjects() / KB,
cell_space_->Available() / KB,
cell_space_->CommittedMemory() / KB);
PrintPID("Large object space, used: %6" V8_PTR_PREFIX "d KB"
", available: %6" V8_PTR_PREFIX "d KB"
", committed: %6" V8_PTR_PREFIX "d KB\n",
lo_space_->SizeOfObjects() / KB,
lo_space_->Available() / KB,
lo_space_->CommittedMemory() / KB);
}
@ -906,8 +906,8 @@ bool Heap::PerformGarbageCollection(GarbageCollector collector,
// have to limit maximal capacity of the young generation.
new_space_high_promotion_mode_active_ = true;
if (FLAG_trace_gc) {
PrintF("Limited new space size due to high promotion rate: %d MB\n",
new_space_.InitialCapacity() / MB);
PrintPID("Limited new space size due to high promotion rate: %d MB\n",
new_space_.InitialCapacity() / MB);
}
} else if (new_space_high_promotion_mode_active_ &&
IsStableOrDecreasingSurvivalTrend() &&
@ -917,8 +917,8 @@ bool Heap::PerformGarbageCollection(GarbageCollector collector,
// to grow again.
new_space_high_promotion_mode_active_ = false;
if (FLAG_trace_gc) {
PrintF("Unlimited new space size due to low promotion rate: %d MB\n",
new_space_.MaximumCapacity() / MB);
PrintPID("Unlimited new space size due to low promotion rate: %d MB\n",
new_space_.MaximumCapacity() / MB);
}
}
@ -5809,8 +5809,8 @@ bool Heap::ConfigureHeap(int max_semispace_size,
if (max_semispace_size < Page::kPageSize) {
max_semispace_size = Page::kPageSize;
if (FLAG_trace_gc) {
PrintF("Max semispace size cannot be less than %dkbytes\n",
Page::kPageSize >> 10);
PrintPID("Max semispace size cannot be less than %dkbytes\n",
Page::kPageSize >> 10);
}
}
max_semispace_size_ = max_semispace_size;
@ -5825,8 +5825,8 @@ bool Heap::ConfigureHeap(int max_semispace_size,
if (max_semispace_size_ > reserved_semispace_size_) {
max_semispace_size_ = reserved_semispace_size_;
if (FLAG_trace_gc) {
PrintF("Max semispace size cannot be more than %dkbytes\n",
reserved_semispace_size_ >> 10);
PrintPID("Max semispace size cannot be more than %dkbytes\n",
reserved_semispace_size_ >> 10);
}
}
} else {
@ -6920,7 +6920,7 @@ GCTracer::~GCTracer() {
}
}
PrintF("%8.0f ms: ", heap_->isolate()->time_millis_since_init());
PrintPID("%8.0f ms: ", heap_->isolate()->time_millis_since_init());
if (!FLAG_trace_gc_nvp) {
int external_time = static_cast<int>(scopes_[Scope::EXTERNAL]);

View File

@ -107,7 +107,7 @@ void IncrementalMarking::BlackToGreyAndUnshift(HeapObject* obj,
// trace it. In this case we switch to non-incremental marking in
// order to finish off this marking phase.
if (FLAG_trace_gc) {
PrintF("Hurrying incremental marking because of lack of progress\n");
PrintPID("Hurrying incremental marking because of lack of progress\n");
}
allocation_marking_factor_ = kMaxAllocationMarkingFactor;
}

View File

@ -892,8 +892,8 @@ void IncrementalMarking::Step(intptr_t allocated_bytes,
if ((steps_count_ % kAllocationMarkingFactorSpeedupInterval) == 0) {
if (FLAG_trace_gc) {
PrintF("Speed up marking after %d steps\n",
static_cast<int>(kAllocationMarkingFactorSpeedupInterval));
PrintPID("Speed up marking after %d steps\n",
static_cast<int>(kAllocationMarkingFactorSpeedupInterval));
}
speed_up = true;
}
@ -907,7 +907,7 @@ void IncrementalMarking::Step(intptr_t allocated_bytes,
if (space_left_is_very_small ||
only_1_nth_of_space_that_was_available_still_left) {
if (FLAG_trace_gc) PrintF("Speed up marking because of low space left\n");
if (FLAG_trace_gc) PrintPID("Speed up marking because of low space left\n");
speed_up = true;
}
@ -918,7 +918,7 @@ void IncrementalMarking::Step(intptr_t allocated_bytes,
if (size_of_old_space_multiplied_by_n_during_marking) {
speed_up = true;
if (FLAG_trace_gc) {
PrintF("Speed up marking because of heap size increase\n");
PrintPID("Speed up marking because of heap size increase\n");
}
}
@ -930,7 +930,7 @@ void IncrementalMarking::Step(intptr_t allocated_bytes,
// We try to scan at at least twice the speed that we are allocating.
if (promoted_during_marking > bytes_scanned_ / 2 + scavenge_slack + delay) {
if (FLAG_trace_gc) {
PrintF("Speed up marking because marker was not keeping up\n");
PrintPID("Speed up marking because marker was not keeping up\n");
}
speed_up = true;
}
@ -938,7 +938,7 @@ void IncrementalMarking::Step(intptr_t allocated_bytes,
if (speed_up) {
if (state_ != MARKING) {
if (FLAG_trace_gc) {
PrintF("Postponing speeding up marking until marking starts\n");
PrintPID("Postponing speeding up marking until marking starts\n");
}
} else {
allocation_marking_factor_ += kAllocationMarkingFactorSpeedup;
@ -946,7 +946,7 @@ void IncrementalMarking::Step(intptr_t allocated_bytes,
Min(kMaxAllocationMarkingFactor,
static_cast<intptr_t>(allocation_marking_factor_ * 1.3)));
if (FLAG_trace_gc) {
PrintF("Marking speed increased to %d\n", allocation_marking_factor_);
PrintPID("Marking speed increased to %d\n", allocation_marking_factor_);
}
}
}

View File

@ -215,8 +215,9 @@ class IncrementalMarking {
if (IsMarking()) {
if (allocation_marking_factor_ < kFastMarking) {
if (FLAG_trace_gc) {
PrintF("Increasing marking speed to %d due to high promotion rate\n",
static_cast<int>(kFastMarking));
PrintPID("Increasing marking speed to %d "
"due to high promotion rate\n",
static_cast<int>(kFastMarking));
}
allocation_marking_factor_ = kFastMarking;
}

View File

@ -153,6 +153,11 @@ double OS::nan_value() {
}
int OS::GetCurrentProcessId() {
return static_cast<int>(getpid());
}
// ----------------------------------------------------------------------------
// POSIX date/time support.
//

View File

@ -627,6 +627,11 @@ int OS::GetLastError() {
}
int OS::GetCurrentProcessId() {
return static_cast<int>(::GetCurrentProcessId());
}
// ----------------------------------------------------------------------------
// Win32 console output.
//

View File

@ -317,6 +317,8 @@ class OS {
static const int kMinComplexMemCopy = 256;
#endif // V8_TARGET_ARCH_IA32
static int GetCurrentProcessId();
private:
static const int msPerSecond = 1000;

View File

@ -53,6 +53,15 @@ void PrintF(FILE* out, const char* format, ...) {
}
void PrintPID(const char* format, ...) {
OS::Print("[%d] ", OS::GetCurrentProcessId());
va_list arguments;
va_start(arguments, format);
OS::VPrint(format, arguments);
va_end(arguments);
}
void Flush(FILE* out) {
fflush(out);
}

View File

@ -57,6 +57,9 @@ namespace internal {
void PRINTF_CHECKING PrintF(const char* format, ...);
void FPRINTF_CHECKING PrintF(FILE* out, const char* format, ...);
// Prepends the current process ID to the output.
void PRINTF_CHECKING PrintPID(const char* format, ...);
// Our version of fflush.
void Flush(FILE* out);

View File

@ -79,3 +79,9 @@ TEST(VirtualMemory) {
CHECK(vm->Uncommit(block_addr, block_size));
delete vm;
}
TEST(GetCurrentProcessId) {
OS::SetUp();
CHECK_EQ(static_cast<int>(getpid()), OS::GetCurrentProcessId());
}

View File

@ -25,3 +25,10 @@ TEST(VirtualMemory) {
CHECK(vm->Uncommit(block_addr, block_size));
delete vm;
}
TEST(GetCurrentProcessId) {
OS::SetUp();
CHECK_EQ(static_cast<int>(::GetCurrentProcessId()),
OS::GetCurrentProcessId());
}