blob: 0c50581ab795ef2c3793a98f9c3b2c3324461a09 [file] [log] [blame]
Steve Block6ded16b2010-05-10 14:33:55 +01001// Copyright 2010 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_PROFILE_GENERATOR_INL_H_
29#define V8_PROFILE_GENERATOR_INL_H_
30
31#ifdef ENABLE_LOGGING_AND_PROFILING
32
33#include "profile-generator.h"
34
35namespace v8 {
36namespace internal {
37
Leon Clarkef7060e22010-06-03 12:02:55 +010038CodeEntry::CodeEntry(int security_token_id)
39 : call_uid_(0),
40 tag_(Logger::FUNCTION_TAG),
41 name_prefix_(kEmptyNamePrefix),
42 name_(""),
43 resource_name_(""),
44 line_number_(0),
45 security_token_id_(security_token_id) {
46}
47
48
Steve Block6ded16b2010-05-10 14:33:55 +010049CodeEntry::CodeEntry(Logger::LogEventsAndTags tag,
50 const char* name_prefix,
51 const char* name,
52 const char* resource_name,
Leon Clarkef7060e22010-06-03 12:02:55 +010053 int line_number,
54 int security_token_id)
Steve Block6ded16b2010-05-10 14:33:55 +010055 : call_uid_(next_call_uid_++),
56 tag_(tag),
57 name_prefix_(name_prefix),
58 name_(name),
59 resource_name_(resource_name),
Leon Clarkef7060e22010-06-03 12:02:55 +010060 line_number_(line_number),
61 security_token_id_(security_token_id) {
Steve Block6ded16b2010-05-10 14:33:55 +010062}
63
64
65bool CodeEntry::is_js_function_tag(Logger::LogEventsAndTags tag) {
66 return tag == Logger::FUNCTION_TAG
67 || tag == Logger::LAZY_COMPILE_TAG
68 || tag == Logger::SCRIPT_TAG
69 || tag == Logger::NATIVE_FUNCTION_TAG
70 || tag == Logger::NATIVE_LAZY_COMPILE_TAG
71 || tag == Logger::NATIVE_SCRIPT_TAG;
72}
73
74
75ProfileNode::ProfileNode(ProfileTree* tree, CodeEntry* entry)
76 : tree_(tree),
77 entry_(entry),
78 total_ticks_(0),
79 self_ticks_(0),
80 children_(CodeEntriesMatch) {
81}
82
83
84void CodeMap::AddCode(Address addr, CodeEntry* entry, unsigned size) {
85 CodeTree::Locator locator;
86 tree_.Insert(addr, &locator);
87 locator.set_value(CodeEntryInfo(entry, size));
88}
89
90
91void CodeMap::MoveCode(Address from, Address to) {
92 tree_.Move(from, to);
93}
94
95void CodeMap::DeleteCode(Address addr) {
96 tree_.Remove(addr);
97}
98
99
Steve Block6ded16b2010-05-10 14:33:55 +0100100const char* CpuProfilesCollection::GetFunctionName(String* name) {
101 return GetFunctionName(GetName(name));
102}
103
104
105const char* CpuProfilesCollection::GetFunctionName(const char* name) {
106 return strlen(name) > 0 ? name : ProfileGenerator::kAnonymousFunctionName;
107}
108
109
110CodeEntry* ProfileGenerator::EntryForVMState(StateTag tag) {
111 switch (tag) {
112 case GC:
113 return gc_entry_;
114 case JS:
115 case COMPILER:
116 // DOM events handlers are reported as OTHER / EXTERNAL entries.
117 // To avoid confusing people, let's put all these entries into
118 // one bucket.
119 case OTHER:
120 case EXTERNAL:
121 return program_entry_;
122 default: return NULL;
123 }
124}
125
Steve Block6ded16b2010-05-10 14:33:55 +0100126} } // namespace v8::internal
127
128#endif // ENABLE_LOGGING_AND_PROFILING
129
130#endif // V8_PROFILE_GENERATOR_INL_H_