blob: 747e5c7271335ac0cc9a94f2cef5ca4dc1a6450c [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
Steve Block791712a2010-08-27 10:21:07 +010038const char* StringsStorage::GetFunctionName(String* name) {
39 return GetFunctionName(GetName(name));
40}
41
42
43const char* StringsStorage::GetFunctionName(const char* name) {
44 return strlen(name) > 0 ? name : ProfileGenerator::kAnonymousFunctionName;
45}
46
47
Steve Block6ded16b2010-05-10 14:33:55 +010048CodeEntry::CodeEntry(Logger::LogEventsAndTags tag,
49 const char* name_prefix,
50 const char* name,
51 const char* resource_name,
Leon Clarkef7060e22010-06-03 12:02:55 +010052 int line_number,
53 int security_token_id)
Kristian Monsen0d5e1162010-09-30 15:31:59 +010054 : tag_(tag),
Steve Block6ded16b2010-05-10 14:33:55 +010055 name_prefix_(name_prefix),
56 name_(name),
57 resource_name_(resource_name),
Leon Clarkef7060e22010-06-03 12:02:55 +010058 line_number_(line_number),
Ben Murdoche0cee9b2011-05-25 10:26:03 +010059 shared_id_(0),
Leon Clarkef7060e22010-06-03 12:02:55 +010060 security_token_id_(security_token_id) {
Steve Block6ded16b2010-05-10 14:33:55 +010061}
62
63
64bool CodeEntry::is_js_function_tag(Logger::LogEventsAndTags tag) {
65 return tag == Logger::FUNCTION_TAG
66 || tag == Logger::LAZY_COMPILE_TAG
67 || tag == Logger::SCRIPT_TAG
68 || tag == Logger::NATIVE_FUNCTION_TAG
69 || tag == Logger::NATIVE_LAZY_COMPILE_TAG
70 || tag == Logger::NATIVE_SCRIPT_TAG;
71}
72
73
74ProfileNode::ProfileNode(ProfileTree* tree, CodeEntry* entry)
75 : tree_(tree),
76 entry_(entry),
77 total_ticks_(0),
78 self_ticks_(0),
79 children_(CodeEntriesMatch) {
80}
81
82
83void CodeMap::AddCode(Address addr, CodeEntry* entry, unsigned size) {
84 CodeTree::Locator locator;
85 tree_.Insert(addr, &locator);
86 locator.set_value(CodeEntryInfo(entry, size));
87}
88
89
90void CodeMap::MoveCode(Address from, Address to) {
91 tree_.Move(from, to);
92}
93
94void CodeMap::DeleteCode(Address addr) {
95 tree_.Remove(addr);
96}
97
98
Steve Block6ded16b2010-05-10 14:33:55 +010099CodeEntry* ProfileGenerator::EntryForVMState(StateTag tag) {
100 switch (tag) {
101 case GC:
102 return gc_entry_;
103 case JS:
104 case COMPILER:
105 // DOM events handlers are reported as OTHER / EXTERNAL entries.
106 // To avoid confusing people, let's put all these entries into
107 // one bucket.
108 case OTHER:
109 case EXTERNAL:
110 return program_entry_;
111 default: return NULL;
112 }
113}
114
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800115
Ben Murdochb0fe1622011-05-05 13:52:32 +0100116uint64_t HeapEntry::id() {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800117 union {
118 Id stored_id;
119 uint64_t returned_id;
120 } id_adaptor = {id_};
121 return id_adaptor.returned_id;
122}
123
Steve Block6ded16b2010-05-10 14:33:55 +0100124} } // namespace v8::internal
125
126#endif // ENABLE_LOGGING_AND_PROFILING
127
128#endif // V8_PROFILE_GENERATOR_INL_H_