Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011, Google Inc. All rights reserved. | 2 * Copyright (c) 2011, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 { | 100 { |
| 101 v8::V8::LowMemoryNotification(); | 101 v8::V8::LowMemoryNotification(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 ScriptObject ScriptProfiler::objectByHeapObjectId(unsigned id) | 104 ScriptObject ScriptProfiler::objectByHeapObjectId(unsigned id) |
| 105 { | 105 { |
| 106 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 106 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 107 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); | 107 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); |
| 108 if (!profiler) | 108 if (!profiler) |
| 109 return ScriptObject(); | 109 return ScriptObject(); |
| 110 // As ids are unique, it doesn't matter which HeapSnapshot owns HeapGraphNod e. | |
| 111 // We need to find first HeapSnapshot containing a node with the specified i d. | |
| 112 const v8::HeapGraphNode* node = 0; | |
| 113 for (int i = 0, l = profiler->GetSnapshotCount(); i < l; ++i) { | |
| 114 const v8::HeapSnapshot* snapshot = profiler->GetHeapSnapshot(i); | |
| 115 node = snapshot->GetNodeById(id); | |
| 116 if (node) | |
| 117 break; | |
| 118 } | |
| 119 if (!node) | |
| 120 return ScriptObject(); | |
| 121 | 110 |
| 122 v8::HandleScope handleScope(isolate); | 111 v8::HandleScope handleScope(isolate); |
| 123 v8::Handle<v8::Value> value = node->GetHeapValue(); | 112 v8::Handle<v8::Value> value = profiler->FindObjectById(id); |
| 124 if (!value->IsObject()) | 113 if (value.IsEmpty() || !value->IsObject()) |
| 125 return ScriptObject(); | 114 return ScriptObject(); |
| 126 | 115 |
| 127 v8::Handle<v8::Object> object = value.As<v8::Object>(); | 116 v8::Handle<v8::Object> object = value.As<v8::Object>(); |
| 128 | 117 |
| 129 if (object->InternalFieldCount() >= v8DefaultWrapperInternalFieldCount) { | 118 if (object->InternalFieldCount() >= v8DefaultWrapperInternalFieldCount) { |
| 130 v8::Handle<v8::Value> wrapper = object->GetInternalField(v8DOMWrapperObj ectIndex); | 119 v8::Handle<v8::Value> wrapper = object->GetInternalField(v8DOMWrapperObj ectIndex); |
| 131 // Skip wrapper boilerplates which are like regular wrappers but don't h ave | 120 // Skip wrapper boilerplates which are like regular wrappers but don't h ave |
| 132 // native object. | 121 // native object. |
| 133 if (!wrapper.IsEmpty() && wrapper->IsUndefined()) | 122 if (!wrapper.IsEmpty() && wrapper->IsUndefined()) |
| 134 return ScriptObject(); | 123 return ScriptObject(); |
| 135 } | 124 } |
| 136 | 125 |
| 137 ScriptState* scriptState = ScriptState::forContext(object->CreationContext() ); | 126 ScriptState* scriptState = ScriptState::forContext(object->CreationContext() ); |
| 138 return ScriptObject(scriptState, object); | 127 return ScriptObject(scriptState, object); |
| 139 } | 128 } |
| 140 | 129 |
| 141 unsigned ScriptProfiler::getHeapObjectId(const ScriptValue& value) | 130 unsigned ScriptProfiler::getHeapObjectId(const ScriptValue& value) |
| 142 { | 131 { |
| 143 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 132 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 144 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); | 133 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); |
| 145 v8::SnapshotObjectId id = profiler->GetObjectId(value.v8Value()); | 134 v8::SnapshotObjectId id = profiler->GetObjectId(value.v8Value()); |
| 146 return id; | 135 return id; |
| 147 } | 136 } |
| 148 | 137 |
| 138 void ScriptProfiler::clearHeapObjectIds() | |
| 139 { | |
| 140 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
| 141 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); | |
|
alph
2013/12/04 10:18:41
Just curious, why do you check for profiler not be
yurys
2013/12/04 11:33:27
The check is redundant, removed it from ScriptProf
| |
| 142 profiler->ClearObjectIds(); | |
| 143 } | |
| 144 | |
| 149 namespace { | 145 namespace { |
| 150 | 146 |
| 151 class ActivityControlAdapter : public v8::ActivityControl { | 147 class ActivityControlAdapter : public v8::ActivityControl { |
| 152 public: | 148 public: |
| 153 ActivityControlAdapter(ScriptProfiler::HeapSnapshotProgress* progress) | 149 ActivityControlAdapter(ScriptProfiler::HeapSnapshotProgress* progress) |
| 154 : m_progress(progress), m_firstReport(true) { } | 150 : m_progress(progress), m_firstReport(true) { } |
| 155 ControlOption ReportProgressValue(int done, int total) | 151 ControlOption ReportProgressValue(int done, int total) |
| 156 { | 152 { |
| 157 ControlOption result = m_progress->isCanceled() ? kAbort : kContinue; | 153 ControlOption result = m_progress->isCanceled() ? kAbort : kContinue; |
| 158 if (m_firstReport) { | 154 if (m_firstReport) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 } | 308 } |
| 313 | 309 |
| 314 void ScriptProfiler::setIdle(bool isIdle) | 310 void ScriptProfiler::setIdle(bool isIdle) |
| 315 { | 311 { |
| 316 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 312 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 317 if (v8::CpuProfiler* profiler = isolate->GetCpuProfiler()) | 313 if (v8::CpuProfiler* profiler = isolate->GetCpuProfiler()) |
| 318 profiler->SetIdle(isIdle); | 314 profiler->SetIdle(isIdle); |
| 319 } | 315 } |
| 320 | 316 |
| 321 } // namespace WebCore | 317 } // namespace WebCore |
| OLD | NEW |