2012-02-10 12:36:05 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2010-03-15 14:11:19 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
2011-05-03 08:23:58 +00:00
|
|
|
|
|
|
|
#include "profile-generator-inl.h"
|
|
|
|
|
2013-05-14 22:51:33 +00:00
|
|
|
#include "compiler.h"
|
2010-05-18 14:19:33 +00:00
|
|
|
#include "global-handles.h"
|
2010-06-11 16:34:59 +00:00
|
|
|
#include "scopeinfo.h"
|
2010-09-14 11:49:06 +00:00
|
|
|
#include "unicode.h"
|
2010-06-11 16:34:59 +00:00
|
|
|
#include "zone-inl.h"
|
2012-04-17 15:57:35 +00:00
|
|
|
#include "debug.h"
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2010-04-06 10:36:38 +00:00
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
TokenEnumerator::TokenEnumerator()
|
|
|
|
: token_locations_(4),
|
|
|
|
token_removed_(4) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TokenEnumerator::~TokenEnumerator() {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
2010-05-18 14:19:33 +00:00
|
|
|
for (int i = 0; i < token_locations_.length(); ++i) {
|
|
|
|
if (!token_removed_[i]) {
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->global_handles()->ClearWeakness(token_locations_[i]);
|
|
|
|
isolate->global_handles()->Destroy(token_locations_[i]);
|
2010-05-18 14:19:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TokenEnumerator::GetTokenId(Object* token) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
2010-06-08 11:27:00 +00:00
|
|
|
if (token == NULL) return TokenEnumerator::kNoSecurityToken;
|
2010-05-18 14:19:33 +00:00
|
|
|
for (int i = 0; i < token_locations_.length(); ++i) {
|
|
|
|
if (*token_locations_[i] == token && !token_removed_[i]) return i;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Object> handle = isolate->global_handles()->Create(token);
|
2010-05-18 14:19:33 +00:00
|
|
|
// handle.location() points to a memory cell holding a pointer
|
|
|
|
// to a token object in the V8's heap.
|
2013-01-25 08:31:46 +00:00
|
|
|
isolate->global_handles()->MakeWeak(handle.location(),
|
|
|
|
this,
|
2011-03-18 20:35:07 +00:00
|
|
|
TokenRemovedCallback);
|
2010-05-18 14:19:33 +00:00
|
|
|
token_locations_.Add(handle.location());
|
|
|
|
token_removed_.Add(false);
|
|
|
|
return token_locations_.length() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-25 08:31:46 +00:00
|
|
|
void TokenEnumerator::TokenRemovedCallback(v8::Isolate* isolate,
|
2013-06-03 08:17:04 +00:00
|
|
|
v8::Persistent<v8::Value>* handle,
|
2010-05-18 14:19:33 +00:00
|
|
|
void* parameter) {
|
|
|
|
reinterpret_cast<TokenEnumerator*>(parameter)->TokenRemoved(
|
2013-06-13 09:27:09 +00:00
|
|
|
Utils::OpenPersistent(handle).location());
|
2013-06-03 08:17:04 +00:00
|
|
|
handle->Dispose(isolate);
|
2010-05-18 14:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TokenEnumerator::TokenRemoved(Object** token_location) {
|
|
|
|
for (int i = 0; i < token_locations_.length(); ++i) {
|
|
|
|
if (token_locations_[i] == token_location && !token_removed_[i]) {
|
|
|
|
token_removed_[i] = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-09 07:00:33 +00:00
|
|
|
StringsStorage::StringsStorage()
|
|
|
|
: names_(StringsMatch) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StringsStorage::~StringsStorage() {
|
|
|
|
for (HashMap::Entry* p = names_.Start();
|
|
|
|
p != NULL;
|
|
|
|
p = names_.Next(p)) {
|
|
|
|
DeleteArray(reinterpret_cast<const char*>(p->value));
|
|
|
|
}
|
2011-03-10 12:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* StringsStorage::GetCopy(const char* src) {
|
2011-03-10 12:58:57 +00:00
|
|
|
int len = static_cast<int>(strlen(src));
|
2011-03-10 12:05:31 +00:00
|
|
|
Vector<char> dst = Vector<char>::New(len + 1);
|
|
|
|
OS::StrNCpy(dst, src, len);
|
|
|
|
dst[len] = '\0';
|
2012-01-04 15:12:15 +00:00
|
|
|
uint32_t hash =
|
2012-12-19 13:27:20 +00:00
|
|
|
StringHasher::HashSequentialString(dst.start(), len, HEAP->HashSeed());
|
2011-03-10 12:05:31 +00:00
|
|
|
return AddOrDisposeString(dst.start(), hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* StringsStorage::GetFormatted(const char* format, ...) {
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
const char* result = GetVFormatted(format, args);
|
|
|
|
va_end(args);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* StringsStorage::AddOrDisposeString(char* str, uint32_t hash) {
|
|
|
|
HashMap::Entry* cache_entry = names_.Lookup(str, hash, true);
|
|
|
|
if (cache_entry->value == NULL) {
|
|
|
|
// New entry added.
|
|
|
|
cache_entry->value = str;
|
|
|
|
} else {
|
|
|
|
DeleteArray(str);
|
|
|
|
}
|
|
|
|
return reinterpret_cast<const char*>(cache_entry->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* StringsStorage::GetVFormatted(const char* format, va_list args) {
|
|
|
|
Vector<char> str = Vector<char>::New(1024);
|
|
|
|
int len = OS::VSNPrintF(str, format, args);
|
|
|
|
if (len == -1) {
|
|
|
|
DeleteArray(str.start());
|
|
|
|
return format;
|
|
|
|
}
|
2012-12-19 13:27:20 +00:00
|
|
|
uint32_t hash = StringHasher::HashSequentialString(
|
2012-01-10 13:24:18 +00:00
|
|
|
str.start(), len, HEAP->HashSeed());
|
2011-03-10 12:05:31 +00:00
|
|
|
return AddOrDisposeString(str.start(), hash);
|
2010-06-09 07:00:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
const char* StringsStorage::GetName(Name* name) {
|
2010-06-09 07:00:33 +00:00
|
|
|
if (name->IsString()) {
|
2013-03-04 15:00:57 +00:00
|
|
|
String* str = String::cast(name);
|
|
|
|
int length = Min(kMaxNameSize, str->length());
|
2011-11-09 12:15:35 +00:00
|
|
|
SmartArrayPointer<char> data =
|
2013-03-04 15:00:57 +00:00
|
|
|
str->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL, 0, length);
|
2012-12-19 13:27:20 +00:00
|
|
|
uint32_t hash = StringHasher::HashSequentialString(
|
|
|
|
*data, length, name->GetHeap()->HashSeed());
|
2011-11-09 12:15:35 +00:00
|
|
|
return AddOrDisposeString(data.Detach(), hash);
|
2013-03-04 15:00:57 +00:00
|
|
|
} else if (name->IsSymbol()) {
|
|
|
|
return "<symbol>";
|
2010-06-09 07:00:33 +00:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-18 09:15:38 +00:00
|
|
|
const char* StringsStorage::GetName(int index) {
|
2011-03-10 12:05:31 +00:00
|
|
|
return GetFormatted("%d", index);
|
2010-10-18 09:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-13 11:02:24 +00:00
|
|
|
size_t StringsStorage::GetUsedMemorySize() const {
|
|
|
|
size_t size = sizeof(*this);
|
|
|
|
size += sizeof(HashMap::Entry) * names_.capacity();
|
|
|
|
for (HashMap::Entry* p = names_.Start(); p != NULL; p = names_.Next(p)) {
|
|
|
|
size += strlen(reinterpret_cast<const char*>(p->value)) + 1;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2013-06-26 16:04:25 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
const char* const CodeEntry::kEmptyNamePrefix = "";
|
2013-06-26 16:04:25 +00:00
|
|
|
const char* const CodeEntry::kEmptyResourceName = "";
|
2010-04-06 10:36:38 +00:00
|
|
|
|
|
|
|
|
2013-05-14 22:51:33 +00:00
|
|
|
CodeEntry::~CodeEntry() {
|
|
|
|
delete no_frame_ranges_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
void CodeEntry::CopyData(const CodeEntry& source) {
|
|
|
|
tag_ = source.tag_;
|
|
|
|
name_prefix_ = source.name_prefix_;
|
|
|
|
name_ = source.name_;
|
|
|
|
resource_name_ = source.resource_name_;
|
|
|
|
line_number_ = source.line_number_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-20 09:29:12 +00:00
|
|
|
uint32_t CodeEntry::GetCallUid() const {
|
2012-01-10 12:58:41 +00:00
|
|
|
uint32_t hash = ComputeIntegerHash(tag_, v8::internal::kZeroHashSeed);
|
2011-02-22 16:31:24 +00:00
|
|
|
if (shared_id_ != 0) {
|
2012-01-10 12:58:41 +00:00
|
|
|
hash ^= ComputeIntegerHash(static_cast<uint32_t>(shared_id_),
|
|
|
|
v8::internal::kZeroHashSeed);
|
2011-02-22 16:31:24 +00:00
|
|
|
} else {
|
|
|
|
hash ^= ComputeIntegerHash(
|
2012-01-10 12:58:41 +00:00
|
|
|
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name_prefix_)),
|
|
|
|
v8::internal::kZeroHashSeed);
|
2011-02-22 16:31:24 +00:00
|
|
|
hash ^= ComputeIntegerHash(
|
2012-01-10 12:58:41 +00:00
|
|
|
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name_)),
|
|
|
|
v8::internal::kZeroHashSeed);
|
2011-02-22 16:31:24 +00:00
|
|
|
hash ^= ComputeIntegerHash(
|
2012-01-10 12:58:41 +00:00
|
|
|
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(resource_name_)),
|
|
|
|
v8::internal::kZeroHashSeed);
|
|
|
|
hash ^= ComputeIntegerHash(line_number_, v8::internal::kZeroHashSeed);
|
2011-02-22 16:31:24 +00:00
|
|
|
}
|
2010-09-20 09:29:12 +00:00
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CodeEntry::IsSameAs(CodeEntry* entry) const {
|
|
|
|
return this == entry
|
|
|
|
|| (tag_ == entry->tag_
|
2011-02-22 16:31:24 +00:00
|
|
|
&& shared_id_ == entry->shared_id_
|
|
|
|
&& (shared_id_ != 0
|
|
|
|
|| (name_prefix_ == entry->name_prefix_
|
|
|
|
&& name_ == entry->name_
|
|
|
|
&& resource_name_ == entry->resource_name_
|
|
|
|
&& line_number_ == entry->line_number_)));
|
2010-09-20 09:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileNode* ProfileNode::FindChild(CodeEntry* entry) {
|
|
|
|
HashMap::Entry* map_entry =
|
|
|
|
children_.Lookup(entry, CodeEntryHash(entry), false);
|
|
|
|
return map_entry != NULL ?
|
|
|
|
reinterpret_cast<ProfileNode*>(map_entry->value) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ProfileNode* ProfileNode::FindOrAddChild(CodeEntry* entry) {
|
|
|
|
HashMap::Entry* map_entry =
|
|
|
|
children_.Lookup(entry, CodeEntryHash(entry), true);
|
|
|
|
if (map_entry->value == NULL) {
|
|
|
|
// New node added.
|
2010-04-15 11:37:29 +00:00
|
|
|
ProfileNode* new_node = new ProfileNode(tree_, entry);
|
2010-03-30 11:38:39 +00:00
|
|
|
map_entry->value = new_node;
|
|
|
|
children_list_.Add(new_node);
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
return reinterpret_cast<ProfileNode*>(map_entry->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
double ProfileNode::GetSelfMillis() const {
|
|
|
|
return tree_->TicksToMillis(self_ticks_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double ProfileNode::GetTotalMillis() const {
|
|
|
|
return tree_->TicksToMillis(total_ticks_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
void ProfileNode::Print(int indent) {
|
2013-04-23 07:26:30 +00:00
|
|
|
OS::Print("%5u %5u %*c %s%s [%d] #%d",
|
2010-03-15 14:11:19 +00:00
|
|
|
total_ticks_, self_ticks_,
|
|
|
|
indent, ' ',
|
2010-04-06 14:54:20 +00:00
|
|
|
entry_->name_prefix(),
|
2010-05-18 14:19:33 +00:00
|
|
|
entry_->name(),
|
2013-04-23 07:26:30 +00:00
|
|
|
entry_->security_token_id(),
|
|
|
|
id());
|
2010-04-06 14:54:20 +00:00
|
|
|
if (entry_->resource_name()[0] != '\0')
|
|
|
|
OS::Print(" %s:%d", entry_->resource_name(), entry_->line_number());
|
|
|
|
OS::Print("\n");
|
2010-03-15 14:11:19 +00:00
|
|
|
for (HashMap::Entry* p = children_.Start();
|
|
|
|
p != NULL;
|
|
|
|
p = children_.Next(p)) {
|
|
|
|
reinterpret_cast<ProfileNode*>(p->value)->Print(indent + 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class DeleteNodesCallback {
|
|
|
|
public:
|
2010-05-18 14:19:33 +00:00
|
|
|
void BeforeTraversingChild(ProfileNode*, ProfileNode*) { }
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
void AfterAllChildrenTraversed(ProfileNode* node) {
|
|
|
|
delete node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AfterChildTraversed(ProfileNode*, ProfileNode*) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-04-06 14:54:20 +00:00
|
|
|
ProfileTree::ProfileTree()
|
2013-07-01 09:51:44 +00:00
|
|
|
: root_entry_(Logger::FUNCTION_TAG, "", "(root)"),
|
2013-04-02 07:48:25 +00:00
|
|
|
next_node_id_(1),
|
2010-04-15 11:37:29 +00:00
|
|
|
root_(new ProfileNode(this, &root_entry_)) {
|
2010-04-06 14:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileTree::~ProfileTree() {
|
|
|
|
DeleteNodesCallback cb;
|
2010-05-18 14:19:33 +00:00
|
|
|
TraverseDepthFirst(&cb);
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 07:48:25 +00:00
|
|
|
ProfileNode* ProfileTree::AddPathFromEnd(const Vector<CodeEntry*>& path) {
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileNode* node = root_;
|
|
|
|
for (CodeEntry** entry = path.start() + path.length() - 1;
|
|
|
|
entry != path.start() - 1;
|
|
|
|
--entry) {
|
|
|
|
if (*entry != NULL) {
|
|
|
|
node = node->FindOrAddChild(*entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node->IncrementSelfTicks();
|
2013-04-02 07:48:25 +00:00
|
|
|
return node;
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProfileTree::AddPathFromStart(const Vector<CodeEntry*>& path) {
|
|
|
|
ProfileNode* node = root_;
|
|
|
|
for (CodeEntry** entry = path.start();
|
|
|
|
entry != path.start() + path.length();
|
|
|
|
++entry) {
|
|
|
|
if (*entry != NULL) {
|
|
|
|
node = node->FindOrAddChild(*entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node->IncrementSelfTicks();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
struct NodesPair {
|
|
|
|
NodesPair(ProfileNode* src, ProfileNode* dst)
|
|
|
|
: src(src), dst(dst) { }
|
|
|
|
ProfileNode* src;
|
|
|
|
ProfileNode* dst;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FilteredCloneCallback {
|
|
|
|
public:
|
2011-03-22 16:10:01 +00:00
|
|
|
FilteredCloneCallback(ProfileNode* dst_root, int security_token_id)
|
2010-05-18 14:19:33 +00:00
|
|
|
: stack_(10),
|
|
|
|
security_token_id_(security_token_id) {
|
|
|
|
stack_.Add(NodesPair(NULL, dst_root));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BeforeTraversingChild(ProfileNode* parent, ProfileNode* child) {
|
|
|
|
if (IsTokenAcceptable(child->entry()->security_token_id(),
|
|
|
|
parent->entry()->security_token_id())) {
|
|
|
|
ProfileNode* clone = stack_.last().dst->FindOrAddChild(child->entry());
|
|
|
|
clone->IncreaseSelfTicks(child->self_ticks());
|
|
|
|
stack_.Add(NodesPair(child, clone));
|
|
|
|
} else {
|
|
|
|
// Attribute ticks to parent node.
|
|
|
|
stack_.last().dst->IncreaseSelfTicks(child->self_ticks());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AfterAllChildrenTraversed(ProfileNode* parent) { }
|
|
|
|
|
|
|
|
void AfterChildTraversed(ProfileNode*, ProfileNode* child) {
|
|
|
|
if (stack_.last().src == child) {
|
|
|
|
stack_.RemoveLast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool IsTokenAcceptable(int token, int parent_token) {
|
2010-06-08 11:27:00 +00:00
|
|
|
if (token == TokenEnumerator::kNoSecurityToken
|
2010-05-18 14:19:33 +00:00
|
|
|
|| token == security_token_id_) return true;
|
2010-06-08 11:27:00 +00:00
|
|
|
if (token == TokenEnumerator::kInheritsSecurityToken) {
|
|
|
|
ASSERT(parent_token != TokenEnumerator::kInheritsSecurityToken);
|
|
|
|
return parent_token == TokenEnumerator::kNoSecurityToken
|
2010-05-18 14:19:33 +00:00
|
|
|
|| parent_token == security_token_id_;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<NodesPair> stack_;
|
|
|
|
int security_token_id_;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ProfileTree::FilteredClone(ProfileTree* src, int security_token_id) {
|
|
|
|
ms_to_ticks_scale_ = src->ms_to_ticks_scale_;
|
|
|
|
FilteredCloneCallback cb(root_, security_token_id);
|
|
|
|
src->TraverseDepthFirst(&cb);
|
|
|
|
CalculateTotalTicks();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
void ProfileTree::SetTickRatePerMs(double ticks_per_ms) {
|
|
|
|
ms_to_ticks_scale_ = ticks_per_ms > 0 ? 1.0 / ticks_per_ms : 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-30 11:38:39 +00:00
|
|
|
class Position {
|
|
|
|
public:
|
|
|
|
explicit Position(ProfileNode* node)
|
|
|
|
: node(node), child_idx_(0) { }
|
2010-03-15 14:11:19 +00:00
|
|
|
INLINE(ProfileNode* current_child()) {
|
2010-03-30 11:38:39 +00:00
|
|
|
return node->children()->at(child_idx_);
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
2010-03-30 11:38:39 +00:00
|
|
|
INLINE(bool has_current_child()) {
|
|
|
|
return child_idx_ < node->children()->length();
|
|
|
|
}
|
|
|
|
INLINE(void next_child()) { ++child_idx_; }
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileNode* node;
|
2010-03-30 11:38:39 +00:00
|
|
|
private:
|
|
|
|
int child_idx_;
|
2010-03-15 14:11:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
// Non-recursive implementation of a depth-first post-order tree traversal.
|
2010-03-15 14:11:19 +00:00
|
|
|
template <typename Callback>
|
2010-05-18 14:19:33 +00:00
|
|
|
void ProfileTree::TraverseDepthFirst(Callback* callback) {
|
2010-03-15 14:11:19 +00:00
|
|
|
List<Position> stack(10);
|
2010-03-30 11:38:39 +00:00
|
|
|
stack.Add(Position(root_));
|
2010-05-18 14:19:33 +00:00
|
|
|
while (stack.length() > 0) {
|
2010-03-15 14:11:19 +00:00
|
|
|
Position& current = stack.last();
|
2010-03-30 11:38:39 +00:00
|
|
|
if (current.has_current_child()) {
|
2010-05-18 14:19:33 +00:00
|
|
|
callback->BeforeTraversingChild(current.node, current.current_child());
|
2010-03-30 11:38:39 +00:00
|
|
|
stack.Add(Position(current.current_child()));
|
2010-03-15 14:11:19 +00:00
|
|
|
} else {
|
|
|
|
callback->AfterAllChildrenTraversed(current.node);
|
|
|
|
if (stack.length() > 1) {
|
|
|
|
Position& parent = stack[stack.length() - 2];
|
|
|
|
callback->AfterChildTraversed(parent.node, current.node);
|
2010-03-30 11:38:39 +00:00
|
|
|
parent.next_child();
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
2010-05-18 14:19:33 +00:00
|
|
|
// Remove child from the stack.
|
|
|
|
stack.RemoveLast();
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
2010-05-18 14:19:33 +00:00
|
|
|
}
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class CalculateTotalTicksCallback {
|
|
|
|
public:
|
2010-05-18 14:19:33 +00:00
|
|
|
void BeforeTraversingChild(ProfileNode*, ProfileNode*) { }
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
void AfterAllChildrenTraversed(ProfileNode* node) {
|
|
|
|
node->IncreaseTotalTicks(node->self_ticks());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AfterChildTraversed(ProfileNode* parent, ProfileNode* child) {
|
|
|
|
parent->IncreaseTotalTicks(child->total_ticks());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void ProfileTree::CalculateTotalTicks() {
|
|
|
|
CalculateTotalTicksCallback cb;
|
2010-05-18 14:19:33 +00:00
|
|
|
TraverseDepthFirst(&cb);
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProfileTree::ShortPrint() {
|
2010-04-15 11:37:29 +00:00
|
|
|
OS::Print("root: %u %u %.2fms %.2fms\n",
|
|
|
|
root_->total_ticks(), root_->self_ticks(),
|
|
|
|
root_->GetTotalMillis(), root_->GetSelfMillis());
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfile::AddPath(const Vector<CodeEntry*>& path) {
|
2013-04-02 07:48:25 +00:00
|
|
|
ProfileNode* top_frame_node = top_down_.AddPathFromEnd(path);
|
|
|
|
if (record_samples_) samples_.Add(top_frame_node);
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfile::CalculateTotalTicks() {
|
|
|
|
top_down_.CalculateTotalTicks();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
void CpuProfile::SetActualSamplingRate(double actual_sampling_rate) {
|
|
|
|
top_down_.SetTickRatePerMs(actual_sampling_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
CpuProfile* CpuProfile::FilteredClone(int security_token_id) {
|
2010-06-08 11:27:00 +00:00
|
|
|
ASSERT(security_token_id != TokenEnumerator::kNoSecurityToken);
|
2013-04-02 07:48:25 +00:00
|
|
|
CpuProfile* clone = new CpuProfile(title_, uid_, false);
|
2010-05-18 14:19:33 +00:00
|
|
|
clone->top_down_.FilteredClone(&top_down_, security_token_id);
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
void CpuProfile::ShortPrint() {
|
|
|
|
OS::Print("top down ");
|
|
|
|
top_down_.ShortPrint();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfile::Print() {
|
|
|
|
OS::Print("[Top down]:\n");
|
|
|
|
top_down_.Print();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-10 12:00:27 +00:00
|
|
|
CodeEntry* const CodeMap::kSharedFunctionCodeEntry = NULL;
|
2010-03-15 14:11:19 +00:00
|
|
|
const CodeMap::CodeTreeConfig::Key CodeMap::CodeTreeConfig::kNoKey = NULL;
|
|
|
|
|
|
|
|
|
2011-09-14 11:47:03 +00:00
|
|
|
void CodeMap::AddCode(Address addr, CodeEntry* entry, unsigned size) {
|
|
|
|
DeleteAllCoveredCode(addr, addr + size);
|
|
|
|
CodeTree::Locator locator;
|
|
|
|
tree_.Insert(addr, &locator);
|
|
|
|
locator.set_value(CodeEntryInfo(entry, size));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeMap::DeleteAllCoveredCode(Address start, Address end) {
|
|
|
|
List<Address> to_delete;
|
|
|
|
Address addr = end - 1;
|
|
|
|
while (addr >= start) {
|
|
|
|
CodeTree::Locator locator;
|
|
|
|
if (!tree_.FindGreatestLessThan(addr, &locator)) break;
|
|
|
|
Address start2 = locator.key(), end2 = start2 + locator.value().size;
|
|
|
|
if (start2 < end && start < end2) to_delete.Add(start2);
|
|
|
|
addr = start2 - 1;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < to_delete.length(); ++i) tree_.Remove(to_delete[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-14 22:51:33 +00:00
|
|
|
CodeEntry* CodeMap::FindEntry(Address addr, Address* start) {
|
2010-03-15 14:11:19 +00:00
|
|
|
CodeTree::Locator locator;
|
|
|
|
if (tree_.FindGreatestLessThan(addr, &locator)) {
|
|
|
|
// locator.key() <= addr. Need to check that addr is within entry.
|
|
|
|
const CodeEntryInfo& entry = locator.value();
|
2013-05-14 22:51:33 +00:00
|
|
|
if (addr < (locator.key() + entry.size)) {
|
|
|
|
if (start) {
|
|
|
|
*start = locator.key();
|
|
|
|
}
|
2010-03-15 14:11:19 +00:00
|
|
|
return entry.entry;
|
2013-05-14 22:51:33 +00:00
|
|
|
}
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-10 12:00:27 +00:00
|
|
|
int CodeMap::GetSharedId(Address addr) {
|
2011-02-22 16:31:24 +00:00
|
|
|
CodeTree::Locator locator;
|
2011-03-10 12:00:27 +00:00
|
|
|
// For shared function entries, 'size' field is used to store their IDs.
|
2011-02-22 16:31:24 +00:00
|
|
|
if (tree_.Find(addr, &locator)) {
|
|
|
|
const CodeEntryInfo& entry = locator.value();
|
2011-03-10 12:00:27 +00:00
|
|
|
ASSERT(entry.entry == kSharedFunctionCodeEntry);
|
2011-02-22 16:31:24 +00:00
|
|
|
return entry.size;
|
|
|
|
} else {
|
|
|
|
tree_.Insert(addr, &locator);
|
2011-03-10 12:00:27 +00:00
|
|
|
int id = next_shared_id_++;
|
|
|
|
locator.set_value(CodeEntryInfo(kSharedFunctionCodeEntry, id));
|
|
|
|
return id;
|
2011-02-22 16:31:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-14 11:47:03 +00:00
|
|
|
void CodeMap::MoveCode(Address from, Address to) {
|
|
|
|
if (from == to) return;
|
|
|
|
CodeTree::Locator locator;
|
|
|
|
if (!tree_.Find(from, &locator)) return;
|
|
|
|
CodeEntryInfo entry = locator.value();
|
|
|
|
tree_.Remove(from);
|
|
|
|
AddCode(to, entry.entry, entry.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-30 11:38:39 +00:00
|
|
|
void CodeMap::CodeTreePrinter::Call(
|
|
|
|
const Address& key, const CodeMap::CodeEntryInfo& value) {
|
2013-04-24 12:09:04 +00:00
|
|
|
// For shared function entries, 'size' field is used to store their IDs.
|
|
|
|
if (value.entry == kSharedFunctionCodeEntry) {
|
|
|
|
OS::Print("%p SharedFunctionInfo %d\n", key, value.size);
|
|
|
|
} else {
|
|
|
|
OS::Print("%p %5d %s\n", key, value.size, value.entry->name());
|
|
|
|
}
|
2010-03-30 11:38:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeMap::Print() {
|
|
|
|
CodeTreePrinter printer;
|
|
|
|
tree_.ForEach(&printer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
CpuProfilesCollection::CpuProfilesCollection()
|
2010-06-09 07:00:33 +00:00
|
|
|
: profiles_uids_(UidsMatch),
|
2010-03-30 11:38:39 +00:00
|
|
|
current_profiles_semaphore_(OS::CreateSemaphore(1)) {
|
2010-05-18 14:19:33 +00:00
|
|
|
// Create list of unabridged profiles.
|
|
|
|
profiles_by_token_.Add(new List<CpuProfile*>());
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
static void DeleteCodeEntry(CodeEntry** entry_ptr) {
|
2010-03-15 14:11:19 +00:00
|
|
|
delete *entry_ptr;
|
|
|
|
}
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
static void DeleteCpuProfile(CpuProfile** profile_ptr) {
|
|
|
|
delete *profile_ptr;
|
|
|
|
}
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
static void DeleteProfilesList(List<CpuProfile*>** list_ptr) {
|
2011-03-22 16:10:01 +00:00
|
|
|
if (*list_ptr != NULL) {
|
|
|
|
(*list_ptr)->Iterate(DeleteCpuProfile);
|
|
|
|
delete *list_ptr;
|
|
|
|
}
|
2010-05-18 14:19:33 +00:00
|
|
|
}
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
CpuProfilesCollection::~CpuProfilesCollection() {
|
2010-03-30 11:38:39 +00:00
|
|
|
delete current_profiles_semaphore_;
|
|
|
|
current_profiles_.Iterate(DeleteCpuProfile);
|
2011-03-22 16:10:01 +00:00
|
|
|
detached_profiles_.Iterate(DeleteCpuProfile);
|
2010-05-18 14:19:33 +00:00
|
|
|
profiles_by_token_.Iterate(DeleteProfilesList);
|
2010-03-19 09:46:53 +00:00
|
|
|
code_entries_.Iterate(DeleteCodeEntry);
|
|
|
|
}
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
|
2013-04-02 07:48:25 +00:00
|
|
|
bool CpuProfilesCollection::StartProfiling(const char* title, unsigned uid,
|
|
|
|
bool record_samples) {
|
2010-03-30 11:38:39 +00:00
|
|
|
ASSERT(uid > 0);
|
|
|
|
current_profiles_semaphore_->Wait();
|
2010-08-31 14:16:01 +00:00
|
|
|
if (current_profiles_.length() >= kMaxSimultaneousProfiles) {
|
|
|
|
current_profiles_semaphore_->Signal();
|
|
|
|
return false;
|
|
|
|
}
|
2010-03-30 11:38:39 +00:00
|
|
|
for (int i = 0; i < current_profiles_.length(); ++i) {
|
|
|
|
if (strcmp(current_profiles_[i]->title(), title) == 0) {
|
|
|
|
// Ignore attempts to start profile with the same title.
|
|
|
|
current_profiles_semaphore_->Signal();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-04-02 07:48:25 +00:00
|
|
|
current_profiles_.Add(new CpuProfile(title, uid, record_samples));
|
2010-03-30 11:38:39 +00:00
|
|
|
current_profiles_semaphore_->Signal();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
CpuProfile* CpuProfilesCollection::StopProfiling(int security_token_id,
|
|
|
|
const char* title,
|
2010-04-15 11:37:29 +00:00
|
|
|
double actual_sampling_rate) {
|
2010-04-13 11:59:37 +00:00
|
|
|
const int title_len = StrLength(title);
|
2010-03-30 11:38:39 +00:00
|
|
|
CpuProfile* profile = NULL;
|
|
|
|
current_profiles_semaphore_->Wait();
|
|
|
|
for (int i = current_profiles_.length() - 1; i >= 0; --i) {
|
|
|
|
if (title_len == 0 || strcmp(current_profiles_[i]->title(), title) == 0) {
|
|
|
|
profile = current_profiles_.Remove(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
current_profiles_semaphore_->Signal();
|
|
|
|
|
|
|
|
if (profile != NULL) {
|
|
|
|
profile->CalculateTotalTicks();
|
2010-04-15 11:37:29 +00:00
|
|
|
profile->SetActualSamplingRate(actual_sampling_rate);
|
2010-05-18 14:19:33 +00:00
|
|
|
List<CpuProfile*>* unabridged_list =
|
2010-06-08 11:27:00 +00:00
|
|
|
profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)];
|
2010-05-18 14:19:33 +00:00
|
|
|
unabridged_list->Add(profile);
|
2010-03-30 11:38:39 +00:00
|
|
|
HashMap::Entry* entry =
|
|
|
|
profiles_uids_.Lookup(reinterpret_cast<void*>(profile->uid()),
|
|
|
|
static_cast<uint32_t>(profile->uid()),
|
|
|
|
true);
|
|
|
|
ASSERT(entry->value == NULL);
|
2010-05-18 14:19:33 +00:00
|
|
|
entry->value = reinterpret_cast<void*>(unabridged_list->length() - 1);
|
|
|
|
return GetProfile(security_token_id, profile->uid());
|
2010-03-30 11:38:39 +00:00
|
|
|
}
|
2010-05-18 14:19:33 +00:00
|
|
|
return NULL;
|
2010-03-30 11:38:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
CpuProfile* CpuProfilesCollection::GetProfile(int security_token_id,
|
|
|
|
unsigned uid) {
|
2011-03-22 16:10:01 +00:00
|
|
|
int index = GetProfileIndex(uid);
|
|
|
|
if (index < 0) return NULL;
|
2010-05-18 14:19:33 +00:00
|
|
|
List<CpuProfile*>* unabridged_list =
|
2010-06-08 11:27:00 +00:00
|
|
|
profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)];
|
|
|
|
if (security_token_id == TokenEnumerator::kNoSecurityToken) {
|
2010-05-18 14:19:33 +00:00
|
|
|
return unabridged_list->at(index);
|
|
|
|
}
|
|
|
|
List<CpuProfile*>* list = GetProfilesList(security_token_id);
|
|
|
|
if (list->at(index) == NULL) {
|
2010-12-07 11:31:57 +00:00
|
|
|
(*list)[index] =
|
|
|
|
unabridged_list->at(index)->FilteredClone(security_token_id);
|
2010-05-18 14:19:33 +00:00
|
|
|
}
|
|
|
|
return list->at(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-22 16:10:01 +00:00
|
|
|
int CpuProfilesCollection::GetProfileIndex(unsigned uid) {
|
|
|
|
HashMap::Entry* entry = profiles_uids_.Lookup(reinterpret_cast<void*>(uid),
|
|
|
|
static_cast<uint32_t>(uid),
|
|
|
|
false);
|
|
|
|
return entry != NULL ?
|
|
|
|
static_cast<int>(reinterpret_cast<intptr_t>(entry->value)) : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-10 12:06:42 +00:00
|
|
|
bool CpuProfilesCollection::IsLastProfile(const char* title) {
|
|
|
|
// Called from VM thread, and only it can mutate the list,
|
|
|
|
// so no locking is needed here.
|
|
|
|
if (current_profiles_.length() != 1) return false;
|
|
|
|
return StrLength(title) == 0
|
|
|
|
|| strcmp(current_profiles_[0]->title(), title) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-22 16:10:01 +00:00
|
|
|
void CpuProfilesCollection::RemoveProfile(CpuProfile* profile) {
|
|
|
|
// Called from VM thread for a completed profile.
|
|
|
|
unsigned uid = profile->uid();
|
|
|
|
int index = GetProfileIndex(uid);
|
|
|
|
if (index < 0) {
|
|
|
|
detached_profiles_.RemoveElement(profile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
profiles_uids_.Remove(reinterpret_cast<void*>(uid),
|
|
|
|
static_cast<uint32_t>(uid));
|
|
|
|
// Decrement all indexes above the deleted one.
|
|
|
|
for (HashMap::Entry* p = profiles_uids_.Start();
|
|
|
|
p != NULL;
|
|
|
|
p = profiles_uids_.Next(p)) {
|
|
|
|
intptr_t p_index = reinterpret_cast<intptr_t>(p->value);
|
|
|
|
if (p_index > index) {
|
|
|
|
p->value = reinterpret_cast<void*>(p_index - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < profiles_by_token_.length(); ++i) {
|
|
|
|
List<CpuProfile*>* list = profiles_by_token_[i];
|
|
|
|
if (list != NULL && index < list->length()) {
|
|
|
|
// Move all filtered clones into detached_profiles_,
|
|
|
|
// so we can know that they are still in use.
|
|
|
|
CpuProfile* cloned_profile = list->Remove(index);
|
|
|
|
if (cloned_profile != NULL && cloned_profile != profile) {
|
|
|
|
detached_profiles_.Add(cloned_profile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
int CpuProfilesCollection::TokenToIndex(int security_token_id) {
|
2010-06-08 11:27:00 +00:00
|
|
|
ASSERT(TokenEnumerator::kNoSecurityToken == -1);
|
2010-05-18 14:19:33 +00:00
|
|
|
return security_token_id + 1; // kNoSecurityToken -> 0, 0 -> 1, ...
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<CpuProfile*>* CpuProfilesCollection::GetProfilesList(
|
|
|
|
int security_token_id) {
|
|
|
|
const int index = TokenToIndex(security_token_id);
|
2010-05-31 10:09:07 +00:00
|
|
|
const int lists_to_add = index - profiles_by_token_.length() + 1;
|
|
|
|
if (lists_to_add > 0) profiles_by_token_.AddBlock(NULL, lists_to_add);
|
2010-05-18 14:19:33 +00:00
|
|
|
List<CpuProfile*>* unabridged_list =
|
2010-06-08 11:27:00 +00:00
|
|
|
profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)];
|
2010-05-18 14:19:33 +00:00
|
|
|
const int current_count = unabridged_list->length();
|
|
|
|
if (profiles_by_token_[index] == NULL) {
|
|
|
|
profiles_by_token_[index] = new List<CpuProfile*>(current_count);
|
|
|
|
}
|
|
|
|
List<CpuProfile*>* list = profiles_by_token_[index];
|
2010-05-31 10:09:07 +00:00
|
|
|
const int profiles_to_add = current_count - list->length();
|
|
|
|
if (profiles_to_add > 0) list->AddBlock(NULL, profiles_to_add);
|
2010-05-18 14:19:33 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<CpuProfile*>* CpuProfilesCollection::Profiles(int security_token_id) {
|
|
|
|
List<CpuProfile*>* unabridged_list =
|
2010-06-08 11:27:00 +00:00
|
|
|
profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)];
|
|
|
|
if (security_token_id == TokenEnumerator::kNoSecurityToken) {
|
2010-05-18 14:19:33 +00:00
|
|
|
return unabridged_list;
|
|
|
|
}
|
|
|
|
List<CpuProfile*>* list = GetProfilesList(security_token_id);
|
|
|
|
const int current_count = unabridged_list->length();
|
|
|
|
for (int i = 0; i < current_count; ++i) {
|
|
|
|
if (list->at(i) == NULL) {
|
2010-12-07 11:31:57 +00:00
|
|
|
(*list)[i] = unabridged_list->at(i)->FilteredClone(security_token_id);
|
2010-05-18 14:19:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
2010-03-19 09:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-01 09:51:44 +00:00
|
|
|
CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag,
|
|
|
|
Name* name,
|
|
|
|
String* resource_name,
|
|
|
|
int line_number) {
|
|
|
|
CodeEntry* entry = new CodeEntry(tag,
|
|
|
|
CodeEntry::kEmptyNamePrefix,
|
|
|
|
GetFunctionName(name),
|
|
|
|
TokenEnumerator::kNoSecurityToken,
|
|
|
|
GetName(resource_name),
|
|
|
|
line_number);
|
|
|
|
code_entries_.Add(entry);
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag,
|
|
|
|
const char* name) {
|
|
|
|
CodeEntry* entry = new CodeEntry(tag,
|
|
|
|
CodeEntry::kEmptyNamePrefix,
|
|
|
|
GetFunctionName(name));
|
|
|
|
code_entries_.Add(entry);
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag,
|
|
|
|
const char* name_prefix,
|
|
|
|
Name* name) {
|
|
|
|
CodeEntry* entry = new CodeEntry(tag,
|
|
|
|
name_prefix,
|
|
|
|
GetName(name),
|
|
|
|
TokenEnumerator::kInheritsSecurityToken);
|
|
|
|
code_entries_.Add(entry);
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag,
|
|
|
|
int args_count) {
|
|
|
|
CodeEntry* entry = new CodeEntry(tag,
|
|
|
|
"args_count: ",
|
|
|
|
GetName(args_count),
|
|
|
|
TokenEnumerator::kInheritsSecurityToken);
|
|
|
|
code_entries_.Add(entry);
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-30 11:38:39 +00:00
|
|
|
void CpuProfilesCollection::AddPathToCurrentProfiles(
|
|
|
|
const Vector<CodeEntry*>& path) {
|
|
|
|
// As starting / stopping profiles is rare relatively to this
|
|
|
|
// method, we don't bother minimizing the duration of lock holding,
|
|
|
|
// e.g. copying contents of the list to a local vector.
|
|
|
|
current_profiles_semaphore_->Wait();
|
|
|
|
for (int i = 0; i < current_profiles_.length(); ++i) {
|
|
|
|
current_profiles_[i]->AddPath(path);
|
|
|
|
}
|
|
|
|
current_profiles_semaphore_->Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
void SampleRateCalculator::Tick() {
|
|
|
|
if (--wall_time_query_countdown_ == 0)
|
|
|
|
UpdateMeasurements(OS::TimeCurrentMillis());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SampleRateCalculator::UpdateMeasurements(double current_time) {
|
|
|
|
if (measurements_count_++ != 0) {
|
|
|
|
const double measured_ticks_per_ms =
|
|
|
|
(kWallTimeQueryIntervalMs * ticks_per_ms_) /
|
|
|
|
(current_time - last_wall_time_);
|
|
|
|
// Update the average value.
|
|
|
|
ticks_per_ms_ +=
|
|
|
|
(measured_ticks_per_ms - ticks_per_ms_) / measurements_count_;
|
|
|
|
// Update the externally accessible result.
|
|
|
|
result_ = static_cast<AtomicWord>(ticks_per_ms_ * kResultScale);
|
|
|
|
}
|
|
|
|
last_wall_time_ = current_time;
|
|
|
|
wall_time_query_countdown_ =
|
|
|
|
static_cast<unsigned>(kWallTimeQueryIntervalMs * ticks_per_ms_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
const char* const ProfileGenerator::kAnonymousFunctionName =
|
|
|
|
"(anonymous function)";
|
|
|
|
const char* const ProfileGenerator::kProgramEntryName =
|
|
|
|
"(program)";
|
|
|
|
const char* const ProfileGenerator::kGarbageCollectorEntryName =
|
|
|
|
"(garbage collector)";
|
2010-04-07 14:18:26 +00:00
|
|
|
|
2010-04-06 14:54:20 +00:00
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
ProfileGenerator::ProfileGenerator(CpuProfilesCollection* profiles)
|
2010-04-06 14:54:20 +00:00
|
|
|
: profiles_(profiles),
|
|
|
|
program_entry_(
|
2010-04-07 14:18:26 +00:00
|
|
|
profiles->NewCodeEntry(Logger::FUNCTION_TAG, kProgramEntryName)),
|
|
|
|
gc_entry_(
|
|
|
|
profiles->NewCodeEntry(Logger::BUILTIN_TAG,
|
|
|
|
kGarbageCollectorEntryName)) {
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
|
|
|
|
void ProfileGenerator::RecordTickSample(const TickSample& sample) {
|
2010-04-07 14:18:26 +00:00
|
|
|
// Allocate space for stack frames + pc + function + vm-state.
|
2010-04-06 14:54:20 +00:00
|
|
|
ScopedVector<CodeEntry*> entries(sample.frames_count + 3);
|
2010-04-07 14:18:26 +00:00
|
|
|
// As actual number of decoded code entries may vary, initialize
|
|
|
|
// entries vector with NULL values.
|
2010-03-19 09:46:53 +00:00
|
|
|
CodeEntry** entry = entries.start();
|
2010-04-07 14:18:26 +00:00
|
|
|
memset(entry, 0, entries.length() * sizeof(*entry));
|
|
|
|
if (sample.pc != NULL) {
|
2013-05-14 22:51:33 +00:00
|
|
|
Address start;
|
|
|
|
CodeEntry* pc_entry = code_map_.FindEntry(sample.pc, &start);
|
|
|
|
// If pc is in the function code before it set up stack frame or after the
|
2013-06-25 07:14:06 +00:00
|
|
|
// frame was destroyed SafeStackFrameIterator incorrectly thinks that
|
2013-05-14 22:51:33 +00:00
|
|
|
// ebp contains return address of the current function and skips caller's
|
|
|
|
// frame. Check for this case and just skip such samples.
|
|
|
|
if (pc_entry) {
|
|
|
|
List<OffsetRange>* ranges = pc_entry->no_frame_ranges();
|
|
|
|
if (ranges) {
|
|
|
|
Code* code = Code::cast(HeapObject::FromAddress(start));
|
2013-05-14 23:54:39 +00:00
|
|
|
int pc_offset = static_cast<int>(sample.pc - code->instruction_start());
|
2013-05-14 22:51:33 +00:00
|
|
|
for (int i = 0; i < ranges->length(); i++) {
|
|
|
|
OffsetRange& range = ranges->at(i);
|
|
|
|
if (range.from <= pc_offset && pc_offset < range.to) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*entry++ = pc_entry;
|
2010-03-19 09:46:53 +00:00
|
|
|
|
2013-04-19 11:55:01 +00:00
|
|
|
if (sample.has_external_callback) {
|
2011-03-21 18:13:27 +00:00
|
|
|
// Don't use PC when in external callback code, as it can point
|
|
|
|
// inside callback's code, and we will erroneously report
|
|
|
|
// that a callback calls itself.
|
|
|
|
*(entries.start()) = NULL;
|
|
|
|
*entry++ = code_map_.FindEntry(sample.external_callback);
|
2010-03-19 09:46:53 +00:00
|
|
|
}
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
for (const Address* stack_pos = sample.stack,
|
2010-04-07 14:18:26 +00:00
|
|
|
*stack_end = stack_pos + sample.frames_count;
|
|
|
|
stack_pos != stack_end;
|
|
|
|
++stack_pos) {
|
|
|
|
*entry++ = code_map_.FindEntry(*stack_pos);
|
|
|
|
}
|
2010-03-19 09:46:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-07 14:18:26 +00:00
|
|
|
if (FLAG_prof_browser_mode) {
|
2010-04-15 14:12:17 +00:00
|
|
|
bool no_symbolized_entries = true;
|
|
|
|
for (CodeEntry** e = entries.start(); e != entry; ++e) {
|
|
|
|
if (*e != NULL) {
|
|
|
|
no_symbolized_entries = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If no frames were symbolized, put the VM state entry in.
|
|
|
|
if (no_symbolized_entries) {
|
|
|
|
*entry++ = EntryForVMState(sample.state);
|
|
|
|
}
|
2010-04-07 14:18:26 +00:00
|
|
|
}
|
2010-04-06 14:54:20 +00:00
|
|
|
|
2010-03-30 11:38:39 +00:00
|
|
|
profiles_->AddPathToCurrentProfiles(entries);
|
2010-03-19 09:46:53 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 16:34:59 +00:00
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
} } // namespace v8::internal
|