2011-09-19 18:36:47 +00:00
|
|
|
// Copyright 2011 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.
|
|
|
|
|
|
|
|
#ifndef V8_PROFILE_GENERATOR_H_
|
|
|
|
#define V8_PROFILE_GENERATOR_H_
|
|
|
|
|
2011-05-06 06:50:20 +00:00
|
|
|
#include "allocation.h"
|
2010-03-15 14:11:19 +00:00
|
|
|
#include "hashmap.h"
|
2010-06-11 16:34:59 +00:00
|
|
|
#include "../include/v8-profiler.h"
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2013-05-14 22:51:33 +00:00
|
|
|
struct OffsetRange;
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
class TokenEnumerator {
|
|
|
|
public:
|
|
|
|
TokenEnumerator();
|
|
|
|
~TokenEnumerator();
|
|
|
|
int GetTokenId(Object* token);
|
|
|
|
|
2010-06-08 11:27:00 +00:00
|
|
|
static const int kNoSecurityToken = -1;
|
|
|
|
static const int kInheritsSecurityToken = -2;
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
private:
|
2013-01-25 08:31:46 +00:00
|
|
|
static void 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);
|
|
|
|
void TokenRemoved(Object** token_location);
|
|
|
|
|
|
|
|
List<Object**> token_locations_;
|
|
|
|
List<bool> token_removed_;
|
|
|
|
|
|
|
|
friend class TokenEnumeratorTester;
|
2010-06-11 16:34:59 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TokenEnumerator);
|
2010-05-18 14:19:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-06-09 07:00:33 +00:00
|
|
|
// Provides a storage of strings allocated in C++ heap, to hold them
|
|
|
|
// forever, even if they disappear from JS heap or external storage.
|
|
|
|
class StringsStorage {
|
|
|
|
public:
|
|
|
|
StringsStorage();
|
|
|
|
~StringsStorage();
|
|
|
|
|
2011-03-10 12:05:31 +00:00
|
|
|
const char* GetCopy(const char* src);
|
|
|
|
const char* GetFormatted(const char* format, ...);
|
|
|
|
const char* GetVFormatted(const char* format, va_list args);
|
2013-03-04 15:00:57 +00:00
|
|
|
const char* GetName(Name* name);
|
2010-10-18 09:15:38 +00:00
|
|
|
const char* GetName(int index);
|
2013-03-04 15:00:57 +00:00
|
|
|
inline const char* GetFunctionName(Name* name);
|
2010-08-18 08:19:29 +00:00
|
|
|
inline const char* GetFunctionName(const char* name);
|
2012-06-13 11:02:24 +00:00
|
|
|
size_t GetUsedMemorySize() const;
|
2010-06-09 07:00:33 +00:00
|
|
|
|
|
|
|
private:
|
2011-11-09 12:15:35 +00:00
|
|
|
static const int kMaxNameSize = 1024;
|
|
|
|
|
2010-06-09 07:00:33 +00:00
|
|
|
INLINE(static bool StringsMatch(void* key1, void* key2)) {
|
|
|
|
return strcmp(reinterpret_cast<char*>(key1),
|
|
|
|
reinterpret_cast<char*>(key2)) == 0;
|
|
|
|
}
|
2011-03-10 12:05:31 +00:00
|
|
|
const char* AddOrDisposeString(char* str, uint32_t hash);
|
2010-06-09 07:00:33 +00:00
|
|
|
|
2010-07-15 13:21:50 +00:00
|
|
|
// Mapping of strings by String::Hash to const char* strings.
|
2010-06-09 07:00:33 +00:00
|
|
|
HashMap names_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(StringsStorage);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
class CodeEntry {
|
|
|
|
public:
|
2010-03-19 09:46:53 +00:00
|
|
|
// CodeEntry doesn't own name strings, just references them.
|
2010-04-06 10:36:38 +00:00
|
|
|
INLINE(CodeEntry(Logger::LogEventsAndTags tag,
|
|
|
|
const char* name_prefix,
|
|
|
|
const char* name,
|
|
|
|
const char* resource_name,
|
2010-05-18 14:19:33 +00:00
|
|
|
int line_number,
|
|
|
|
int security_token_id));
|
2013-05-14 22:51:33 +00:00
|
|
|
~CodeEntry();
|
2010-04-06 10:36:38 +00:00
|
|
|
|
2010-04-07 14:18:26 +00:00
|
|
|
INLINE(bool is_js_function() const) { return is_js_function_tag(tag_); }
|
2010-04-06 10:36:38 +00:00
|
|
|
INLINE(const char* name_prefix() const) { return name_prefix_; }
|
|
|
|
INLINE(bool has_name_prefix() const) { return name_prefix_[0] != '\0'; }
|
|
|
|
INLINE(const char* name() const) { return name_; }
|
|
|
|
INLINE(const char* resource_name() const) { return resource_name_; }
|
|
|
|
INLINE(int line_number() const) { return line_number_; }
|
2011-02-22 16:31:24 +00:00
|
|
|
INLINE(void set_shared_id(int shared_id)) { shared_id_ = shared_id; }
|
2010-05-18 14:19:33 +00:00
|
|
|
INLINE(int security_token_id() const) { return security_token_id_; }
|
2010-04-06 10:36:38 +00:00
|
|
|
|
2010-04-07 14:18:26 +00:00
|
|
|
INLINE(static bool is_js_function_tag(Logger::LogEventsAndTags tag));
|
|
|
|
|
2013-05-14 22:51:33 +00:00
|
|
|
List<OffsetRange>* no_frame_ranges() const { return no_frame_ranges_; }
|
|
|
|
void set_no_frame_ranges(List<OffsetRange>* ranges) {
|
|
|
|
no_frame_ranges_ = ranges;
|
|
|
|
}
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
void CopyData(const CodeEntry& source);
|
2010-09-20 09:29:12 +00:00
|
|
|
uint32_t GetCallUid() const;
|
|
|
|
bool IsSameAs(CodeEntry* entry) const;
|
2010-05-18 14:19:33 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
static const char* const kEmptyNamePrefix;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Logger::LogEventsAndTags tag_;
|
2010-04-06 10:36:38 +00:00
|
|
|
const char* name_prefix_;
|
2010-03-15 14:11:19 +00:00
|
|
|
const char* name_;
|
|
|
|
const char* resource_name_;
|
|
|
|
int line_number_;
|
2011-02-22 16:31:24 +00:00
|
|
|
int shared_id_;
|
2010-05-18 14:19:33 +00:00
|
|
|
int security_token_id_;
|
2013-05-14 22:51:33 +00:00
|
|
|
List<OffsetRange>* no_frame_ranges_;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CodeEntry);
|
2010-03-15 14:11:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
class ProfileTree;
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
class ProfileNode {
|
|
|
|
public:
|
2010-04-15 11:37:29 +00:00
|
|
|
INLINE(ProfileNode(ProfileTree* tree, CodeEntry* entry));
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
ProfileNode* FindChild(CodeEntry* entry);
|
|
|
|
ProfileNode* FindOrAddChild(CodeEntry* entry);
|
|
|
|
INLINE(void IncrementSelfTicks()) { ++self_ticks_; }
|
2010-05-18 14:19:33 +00:00
|
|
|
INLINE(void IncreaseSelfTicks(unsigned amount)) { self_ticks_ += amount; }
|
2010-03-15 14:11:19 +00:00
|
|
|
INLINE(void IncreaseTotalTicks(unsigned amount)) { total_ticks_ += amount; }
|
|
|
|
|
2010-03-19 13:51:01 +00:00
|
|
|
INLINE(CodeEntry* entry() const) { return entry_; }
|
|
|
|
INLINE(unsigned self_ticks() const) { return self_ticks_; }
|
2010-04-15 11:37:29 +00:00
|
|
|
INLINE(unsigned total_ticks() const) { return total_ticks_; }
|
2010-03-30 11:38:39 +00:00
|
|
|
INLINE(const List<ProfileNode*>* children() const) { return &children_list_; }
|
2010-04-15 11:37:29 +00:00
|
|
|
double GetSelfMillis() const;
|
|
|
|
double GetTotalMillis() const;
|
2013-04-02 07:48:25 +00:00
|
|
|
unsigned id() const { return id_; }
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
void Print(int indent);
|
|
|
|
|
|
|
|
private:
|
2010-03-19 09:46:53 +00:00
|
|
|
INLINE(static bool CodeEntriesMatch(void* entry1, void* entry2)) {
|
2010-09-20 09:29:12 +00:00
|
|
|
return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs(
|
|
|
|
reinterpret_cast<CodeEntry*>(entry2));
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
INLINE(static uint32_t CodeEntryHash(CodeEntry* entry)) {
|
2010-09-20 09:29:12 +00:00
|
|
|
return entry->GetCallUid();
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
ProfileTree* tree_;
|
2010-03-15 14:11:19 +00:00
|
|
|
CodeEntry* entry_;
|
|
|
|
unsigned total_ticks_;
|
|
|
|
unsigned self_ticks_;
|
2010-07-15 13:21:50 +00:00
|
|
|
// Mapping from CodeEntry* to ProfileNode*
|
2010-03-15 14:11:19 +00:00
|
|
|
HashMap children_;
|
2010-03-30 11:38:39 +00:00
|
|
|
List<ProfileNode*> children_list_;
|
2013-04-02 07:48:25 +00:00
|
|
|
unsigned id_;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ProfileNode);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-03-30 11:38:39 +00:00
|
|
|
class ProfileTree {
|
2010-03-15 14:11:19 +00:00
|
|
|
public:
|
2010-04-06 14:54:20 +00:00
|
|
|
ProfileTree();
|
2010-03-15 14:11:19 +00:00
|
|
|
~ProfileTree();
|
|
|
|
|
2013-04-02 07:48:25 +00:00
|
|
|
ProfileNode* AddPathFromEnd(const Vector<CodeEntry*>& path);
|
2010-03-15 14:11:19 +00:00
|
|
|
void AddPathFromStart(const Vector<CodeEntry*>& path);
|
|
|
|
void CalculateTotalTicks();
|
2010-05-18 14:19:33 +00:00
|
|
|
void FilteredClone(ProfileTree* src, int security_token_id);
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
double TicksToMillis(unsigned ticks) const {
|
|
|
|
return ticks * ms_to_ticks_scale_;
|
|
|
|
}
|
2010-03-30 11:38:39 +00:00
|
|
|
ProfileNode* root() const { return root_; }
|
2010-04-15 11:37:29 +00:00
|
|
|
void SetTickRatePerMs(double ticks_per_ms);
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2013-04-02 07:48:25 +00:00
|
|
|
unsigned next_node_id() { return next_node_id_++; }
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
void ShortPrint();
|
|
|
|
void Print() {
|
|
|
|
root_->Print(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
template <typename Callback>
|
2010-05-18 14:19:33 +00:00
|
|
|
void TraverseDepthFirst(Callback* callback);
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2010-04-06 14:54:20 +00:00
|
|
|
CodeEntry root_entry_;
|
2013-04-02 07:48:25 +00:00
|
|
|
unsigned next_node_id_;
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileNode* root_;
|
2010-04-15 11:37:29 +00:00
|
|
|
double ms_to_ticks_scale_;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ProfileTree);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
class CpuProfile {
|
2010-03-15 14:11:19 +00:00
|
|
|
public:
|
2013-04-02 07:48:25 +00:00
|
|
|
CpuProfile(const char* title, unsigned uid, bool record_samples)
|
|
|
|
: title_(title), uid_(uid), record_samples_(record_samples) { }
|
2010-03-30 11:38:39 +00:00
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
// Add pc -> ... -> main() call path to the profile.
|
|
|
|
void AddPath(const Vector<CodeEntry*>& path);
|
|
|
|
void CalculateTotalTicks();
|
2010-04-15 11:37:29 +00:00
|
|
|
void SetActualSamplingRate(double actual_sampling_rate);
|
2010-05-18 14:19:33 +00:00
|
|
|
CpuProfile* FilteredClone(int security_token_id);
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2010-03-30 11:38:39 +00:00
|
|
|
INLINE(const char* title() const) { return title_; }
|
|
|
|
INLINE(unsigned uid() const) { return uid_; }
|
|
|
|
INLINE(const ProfileTree* top_down() const) { return &top_down_; }
|
2010-03-19 09:46:53 +00:00
|
|
|
|
2013-04-02 07:48:25 +00:00
|
|
|
INLINE(int samples_count() const) { return samples_.length(); }
|
|
|
|
INLINE(ProfileNode* sample(int index) const) { return samples_.at(index); }
|
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
void UpdateTicksScale();
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
void ShortPrint();
|
|
|
|
void Print();
|
|
|
|
|
|
|
|
private:
|
2010-03-30 11:38:39 +00:00
|
|
|
const char* title_;
|
|
|
|
unsigned uid_;
|
2013-04-02 07:48:25 +00:00
|
|
|
bool record_samples_;
|
|
|
|
List<ProfileNode*> samples_;
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileTree top_down_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CpuProfile);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-03-30 11:38:39 +00:00
|
|
|
class CodeMap {
|
2010-03-15 14:11:19 +00:00
|
|
|
public:
|
2011-03-10 12:00:27 +00:00
|
|
|
CodeMap() : next_shared_id_(1) { }
|
2011-09-14 11:47:03 +00:00
|
|
|
void AddCode(Address addr, CodeEntry* entry, unsigned size);
|
|
|
|
void MoveCode(Address from, Address to);
|
2013-05-14 22:51:33 +00:00
|
|
|
CodeEntry* FindEntry(Address addr, Address* start = NULL);
|
2011-03-10 12:00:27 +00:00
|
|
|
int GetSharedId(Address addr);
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2010-03-30 11:38:39 +00:00
|
|
|
void Print();
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
private:
|
|
|
|
struct CodeEntryInfo {
|
|
|
|
CodeEntryInfo(CodeEntry* an_entry, unsigned a_size)
|
|
|
|
: entry(an_entry), size(a_size) { }
|
|
|
|
CodeEntry* entry;
|
|
|
|
unsigned size;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CodeTreeConfig {
|
|
|
|
typedef Address Key;
|
|
|
|
typedef CodeEntryInfo Value;
|
|
|
|
static const Key kNoKey;
|
2011-10-07 14:41:08 +00:00
|
|
|
static const Value NoValue() { return CodeEntryInfo(NULL, 0); }
|
2010-03-15 14:11:19 +00:00
|
|
|
static int Compare(const Key& a, const Key& b) {
|
|
|
|
return a < b ? -1 : (a > b ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
typedef SplayTree<CodeTreeConfig> CodeTree;
|
|
|
|
|
2010-03-30 11:38:39 +00:00
|
|
|
class CodeTreePrinter {
|
|
|
|
public:
|
|
|
|
void Call(const Address& key, const CodeEntryInfo& value);
|
|
|
|
};
|
|
|
|
|
2011-09-14 11:47:03 +00:00
|
|
|
void DeleteAllCoveredCode(Address start, Address end);
|
|
|
|
|
2011-03-10 12:00:27 +00:00
|
|
|
// Fake CodeEntry pointer to distinguish shared function entries.
|
|
|
|
static CodeEntry* const kSharedFunctionCodeEntry;
|
2011-02-22 16:31:24 +00:00
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
CodeTree tree_;
|
2011-03-10 12:00:27 +00:00
|
|
|
int next_shared_id_;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CodeMap);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
class CpuProfilesCollection {
|
2010-03-15 14:11:19 +00:00
|
|
|
public:
|
2010-03-19 09:46:53 +00:00
|
|
|
CpuProfilesCollection();
|
|
|
|
~CpuProfilesCollection();
|
|
|
|
|
2013-04-02 07:48:25 +00:00
|
|
|
bool StartProfiling(const char* title, unsigned uid, bool record_samples);
|
2010-05-18 14:19:33 +00:00
|
|
|
CpuProfile* StopProfiling(int security_token_id,
|
|
|
|
const char* title,
|
|
|
|
double actual_sampling_rate);
|
|
|
|
List<CpuProfile*>* Profiles(int security_token_id);
|
2013-03-04 15:00:57 +00:00
|
|
|
const char* GetName(Name* name) {
|
2010-06-09 07:00:33 +00:00
|
|
|
return function_and_resource_names_.GetName(name);
|
|
|
|
}
|
2010-10-18 09:15:38 +00:00
|
|
|
const char* GetName(int args_count) {
|
|
|
|
return function_and_resource_names_.GetName(args_count);
|
|
|
|
}
|
2010-05-18 14:19:33 +00:00
|
|
|
CpuProfile* GetProfile(int security_token_id, unsigned uid);
|
2010-08-10 12:06:42 +00:00
|
|
|
bool IsLastProfile(const char* title);
|
2011-03-22 16:10:01 +00:00
|
|
|
void RemoveProfile(CpuProfile* profile);
|
|
|
|
bool HasDetachedProfiles() { return detached_profiles_.length() > 0; }
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag,
|
2013-03-04 15:00:57 +00:00
|
|
|
Name* name, String* resource_name, int line_number);
|
2010-03-15 14:11:19 +00:00
|
|
|
CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag, const char* name);
|
2010-04-06 10:36:38 +00:00
|
|
|
CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag,
|
2013-03-04 15:00:57 +00:00
|
|
|
const char* name_prefix, Name* name);
|
2010-03-19 09:46:53 +00:00
|
|
|
CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag, int args_count);
|
2010-05-18 14:19:33 +00:00
|
|
|
CodeEntry* NewCodeEntry(int security_token_id);
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2010-03-30 11:38:39 +00:00
|
|
|
// Called from profile generator thread.
|
|
|
|
void AddPathToCurrentProfiles(const Vector<CodeEntry*>& path);
|
|
|
|
|
2010-08-31 14:16:01 +00:00
|
|
|
// Limits the number of profiles that can be simultaneously collected.
|
|
|
|
static const int kMaxSimultaneousProfiles = 100;
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
private:
|
2013-03-04 15:00:57 +00:00
|
|
|
const char* GetFunctionName(Name* name) {
|
2010-08-18 08:19:29 +00:00
|
|
|
return function_and_resource_names_.GetFunctionName(name);
|
|
|
|
}
|
|
|
|
const char* GetFunctionName(const char* name) {
|
|
|
|
return function_and_resource_names_.GetFunctionName(name);
|
|
|
|
}
|
2011-03-22 16:10:01 +00:00
|
|
|
int GetProfileIndex(unsigned uid);
|
2010-05-18 14:19:33 +00:00
|
|
|
List<CpuProfile*>* GetProfilesList(int security_token_id);
|
|
|
|
int TokenToIndex(int security_token_id);
|
2010-03-19 09:46:53 +00:00
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
INLINE(static bool UidsMatch(void* key1, void* key2)) {
|
2010-03-30 11:38:39 +00:00
|
|
|
return key1 == key2;
|
|
|
|
}
|
|
|
|
|
2010-06-09 07:00:33 +00:00
|
|
|
StringsStorage function_and_resource_names_;
|
2010-03-19 09:46:53 +00:00
|
|
|
List<CodeEntry*> code_entries_;
|
2010-05-18 14:19:33 +00:00
|
|
|
List<List<CpuProfile*>* > profiles_by_token_;
|
2010-07-15 13:21:50 +00:00
|
|
|
// Mapping from profiles' uids to indexes in the second nested list
|
|
|
|
// of profiles_by_token_.
|
2010-03-30 11:38:39 +00:00
|
|
|
HashMap profiles_uids_;
|
2011-03-22 16:10:01 +00:00
|
|
|
List<CpuProfile*> detached_profiles_;
|
2010-03-30 11:38:39 +00:00
|
|
|
|
|
|
|
// Accessed by VM thread and profile generator thread.
|
|
|
|
List<CpuProfile*> current_profiles_;
|
|
|
|
Semaphore* current_profiles_semaphore_;
|
2010-03-19 09:46:53 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CpuProfilesCollection);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
class SampleRateCalculator {
|
|
|
|
public:
|
|
|
|
SampleRateCalculator()
|
|
|
|
: result_(Logger::kSamplingIntervalMs * kResultScale),
|
|
|
|
ticks_per_ms_(Logger::kSamplingIntervalMs),
|
|
|
|
measurements_count_(0),
|
|
|
|
wall_time_query_countdown_(1) {
|
|
|
|
}
|
|
|
|
|
|
|
|
double ticks_per_ms() {
|
|
|
|
return result_ / static_cast<double>(kResultScale);
|
|
|
|
}
|
|
|
|
void Tick();
|
|
|
|
void UpdateMeasurements(double current_time);
|
|
|
|
|
|
|
|
// Instead of querying current wall time each tick,
|
|
|
|
// we use this constant to control query intervals.
|
|
|
|
static const unsigned kWallTimeQueryIntervalMs = 100;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// As the result needs to be accessed from a different thread, we
|
|
|
|
// use type that guarantees atomic writes to memory. There should
|
|
|
|
// be <= 1000 ticks per second, thus storing a value of a 10 ** 5
|
|
|
|
// order should provide enough precision while keeping away from a
|
|
|
|
// potential overflow.
|
|
|
|
static const int kResultScale = 100000;
|
|
|
|
|
|
|
|
AtomicWord result_;
|
|
|
|
// All other fields are accessed only from the sampler thread.
|
|
|
|
double ticks_per_ms_;
|
|
|
|
unsigned measurements_count_;
|
|
|
|
unsigned wall_time_query_countdown_;
|
|
|
|
double last_wall_time_;
|
2010-06-11 16:34:59 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(SampleRateCalculator);
|
2010-04-15 11:37:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
class ProfileGenerator {
|
|
|
|
public:
|
|
|
|
explicit ProfileGenerator(CpuProfilesCollection* profiles);
|
|
|
|
|
|
|
|
void RecordTickSample(const TickSample& sample);
|
|
|
|
|
|
|
|
INLINE(CodeMap* code_map()) { return &code_map_; }
|
|
|
|
|
2010-04-15 11:37:29 +00:00
|
|
|
INLINE(void Tick()) { sample_rate_calc_.Tick(); }
|
|
|
|
INLINE(double actual_sampling_rate()) {
|
|
|
|
return sample_rate_calc_.ticks_per_ms();
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
static const char* const kAnonymousFunctionName;
|
|
|
|
static const char* const kProgramEntryName;
|
|
|
|
static const char* const kGarbageCollectorEntryName;
|
2010-04-07 14:18:26 +00:00
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
private:
|
2010-04-07 14:18:26 +00:00
|
|
|
INLINE(CodeEntry* EntryForVMState(StateTag tag));
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
CpuProfilesCollection* profiles_;
|
2010-03-15 14:11:19 +00:00
|
|
|
CodeMap code_map_;
|
2010-04-06 14:54:20 +00:00
|
|
|
CodeEntry* program_entry_;
|
2010-04-07 14:18:26 +00:00
|
|
|
CodeEntry* gc_entry_;
|
2010-04-15 11:37:29 +00:00
|
|
|
SampleRateCalculator sample_rate_calc_;
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ProfileGenerator);
|
|
|
|
};
|
|
|
|
|
2010-06-11 16:34:59 +00:00
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_PROFILE_GENERATOR_H_
|