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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 void ScriptProfiler::collectGarbage() | 99 void ScriptProfiler::collectGarbage() |
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) | |
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 | |
122 v8::HandleScope handleScope(isolate); | 108 v8::HandleScope handleScope(isolate); |
123 v8::Handle<v8::Value> value = node->GetHeapValue(); | 109 v8::Handle<v8::Value> value = profiler->FindObjectById(id); |
124 if (!value->IsObject()) | 110 if (value.IsEmpty() || !value->IsObject()) |
125 return ScriptObject(); | 111 return ScriptObject(); |
126 | 112 |
127 v8::Handle<v8::Object> object = value.As<v8::Object>(); | 113 v8::Handle<v8::Object> object = value.As<v8::Object>(); |
128 | 114 |
129 if (object->InternalFieldCount() >= v8DefaultWrapperInternalFieldCount) { | 115 if (object->InternalFieldCount() >= v8DefaultWrapperInternalFieldCount) { |
130 v8::Handle<v8::Value> wrapper = object->GetInternalField(v8DOMWrapperObj
ectIndex); | 116 v8::Handle<v8::Value> wrapper = object->GetInternalField(v8DOMWrapperObj
ectIndex); |
131 // Skip wrapper boilerplates which are like regular wrappers but don't h
ave | 117 // Skip wrapper boilerplates which are like regular wrappers but don't h
ave |
132 // native object. | 118 // native object. |
133 if (!wrapper.IsEmpty() && wrapper->IsUndefined()) | 119 if (!wrapper.IsEmpty() && wrapper->IsUndefined()) |
134 return ScriptObject(); | 120 return ScriptObject(); |
135 } | 121 } |
136 | 122 |
137 ScriptState* scriptState = ScriptState::forContext(object->CreationContext()
); | 123 ScriptState* scriptState = ScriptState::forContext(object->CreationContext()
); |
138 return ScriptObject(scriptState, object); | 124 return ScriptObject(scriptState, object); |
139 } | 125 } |
140 | 126 |
141 unsigned ScriptProfiler::getHeapObjectId(const ScriptValue& value) | 127 unsigned ScriptProfiler::getHeapObjectId(const ScriptValue& value) |
142 { | 128 { |
143 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 129 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
144 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); | 130 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); |
145 v8::SnapshotObjectId id = profiler->GetObjectId(value.v8Value()); | 131 v8::SnapshotObjectId id = profiler->GetObjectId(value.v8Value()); |
146 return id; | 132 return id; |
147 } | 133 } |
148 | 134 |
| 135 void ScriptProfiler::clearHeapObjectIds() |
| 136 { |
| 137 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 138 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); |
| 139 profiler->ClearObjectIds(); |
| 140 } |
| 141 |
149 namespace { | 142 namespace { |
150 | 143 |
151 class ActivityControlAdapter : public v8::ActivityControl { | 144 class ActivityControlAdapter : public v8::ActivityControl { |
152 public: | 145 public: |
153 ActivityControlAdapter(ScriptProfiler::HeapSnapshotProgress* progress) | 146 ActivityControlAdapter(ScriptProfiler::HeapSnapshotProgress* progress) |
154 : m_progress(progress), m_firstReport(true) { } | 147 : m_progress(progress), m_firstReport(true) { } |
155 ControlOption ReportProgressValue(int done, int total) | 148 ControlOption ReportProgressValue(int done, int total) |
156 { | 149 { |
157 ControlOption result = m_progress->isCanceled() ? kAbort : kContinue; | 150 ControlOption result = m_progress->isCanceled() ? kAbort : kContinue; |
158 if (m_firstReport) { | 151 if (m_firstReport) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 } | 305 } |
313 | 306 |
314 void ScriptProfiler::setIdle(bool isIdle) | 307 void ScriptProfiler::setIdle(bool isIdle) |
315 { | 308 { |
316 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 309 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
317 if (v8::CpuProfiler* profiler = isolate->GetCpuProfiler()) | 310 if (v8::CpuProfiler* profiler = isolate->GetCpuProfiler()) |
318 profiler->SetIdle(isIdle); | 311 profiler->SetIdle(isIdle); |
319 } | 312 } |
320 | 313 |
321 } // namespace WebCore | 314 } // namespace WebCore |
OLD | NEW |