OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdarg.h> | 5 #include <stdarg.h> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 1954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 PROFILE(isolate_, GetterCallbackEvent(name, getter_entry)); | 1965 PROFILE(isolate_, GetterCallbackEvent(name, getter_entry)); |
1966 } | 1966 } |
1967 Address setter_entry = v8::ToCData<Address>(ai->setter()); | 1967 Address setter_entry = v8::ToCData<Address>(ai->setter()); |
1968 if (setter_entry != 0) { | 1968 if (setter_entry != 0) { |
1969 PROFILE(isolate_, SetterCallbackEvent(name, setter_entry)); | 1969 PROFILE(isolate_, SetterCallbackEvent(name, setter_entry)); |
1970 } | 1970 } |
1971 } | 1971 } |
1972 } | 1972 } |
1973 | 1973 |
1974 | 1974 |
1975 static void AddIsolateIdIfNeeded(Isolate* isolate, StringStream* stream) { | 1975 static void AddIsolateIdIfNeeded(OStream& os, // NOLINT |
1976 if (FLAG_logfile_per_isolate) stream->Add("isolate-%p-", isolate); | 1976 Isolate* isolate) { |
| 1977 if (FLAG_logfile_per_isolate) os << "isolate-" << isolate << "-"; |
1977 } | 1978 } |
1978 | 1979 |
1979 | 1980 |
1980 static SmartArrayPointer<const char> PrepareLogFileName( | 1981 static void PrepareLogFileName(OStream& os, // NOLINT |
1981 Isolate* isolate, const char* file_name) { | 1982 Isolate* isolate, const char* file_name) { |
1982 HeapStringAllocator allocator; | 1983 AddIsolateIdIfNeeded(os, isolate); |
1983 StringStream stream(&allocator); | |
1984 AddIsolateIdIfNeeded(isolate, &stream); | |
1985 for (const char* p = file_name; *p; p++) { | 1984 for (const char* p = file_name; *p; p++) { |
1986 if (*p == '%') { | 1985 if (*p == '%') { |
1987 p++; | 1986 p++; |
1988 switch (*p) { | 1987 switch (*p) { |
1989 case '\0': | 1988 case '\0': |
1990 // If there's a % at the end of the string we back up | 1989 // If there's a % at the end of the string we back up |
1991 // one character so we can escape the loop properly. | 1990 // one character so we can escape the loop properly. |
1992 p--; | 1991 p--; |
1993 break; | 1992 break; |
1994 case 'p': | 1993 case 'p': |
1995 stream.Add("%d", base::OS::GetCurrentProcessId()); | 1994 os << base::OS::GetCurrentProcessId(); |
1996 break; | 1995 break; |
1997 case 't': { | 1996 case 't': |
1998 // %t expands to the current time in milliseconds. | 1997 // %t expands to the current time in milliseconds. |
1999 double time = base::OS::TimeCurrentMillis(); | 1998 os << static_cast<int64_t>(base::OS::TimeCurrentMillis()); |
2000 stream.Add("%.0f", FmtElm(time)); | |
2001 break; | 1999 break; |
2002 } | |
2003 case '%': | 2000 case '%': |
2004 // %% expands (contracts really) to %. | 2001 // %% expands (contracts really) to %. |
2005 stream.Put('%'); | 2002 os << '%'; |
2006 break; | 2003 break; |
2007 default: | 2004 default: |
2008 // All other %'s expand to themselves. | 2005 // All other %'s expand to themselves. |
2009 stream.Put('%'); | 2006 os << '%' << *p; |
2010 stream.Put(*p); | |
2011 break; | 2007 break; |
2012 } | 2008 } |
2013 } else { | 2009 } else { |
2014 stream.Put(*p); | 2010 os << *p; |
2015 } | 2011 } |
2016 } | 2012 } |
2017 return SmartArrayPointer<const char>(stream.ToCString()); | |
2018 } | 2013 } |
2019 | 2014 |
2020 | 2015 |
2021 bool Logger::SetUp(Isolate* isolate) { | 2016 bool Logger::SetUp(Isolate* isolate) { |
2022 // Tests and EnsureInitialize() can call this twice in a row. It's harmless. | 2017 // Tests and EnsureInitialize() can call this twice in a row. It's harmless. |
2023 if (is_initialized_) return true; | 2018 if (is_initialized_) return true; |
2024 is_initialized_ = true; | 2019 is_initialized_ = true; |
2025 | 2020 |
2026 // --ll-prof implies --log-code and --log-snapshot-positions. | 2021 // --ll-prof implies --log-code and --log-snapshot-positions. |
2027 if (FLAG_ll_prof) { | 2022 if (FLAG_ll_prof) { |
2028 FLAG_log_snapshot_positions = true; | 2023 FLAG_log_snapshot_positions = true; |
2029 } | 2024 } |
2030 | 2025 |
2031 SmartArrayPointer<const char> log_file_name = | 2026 OStringStream log_file_name; |
2032 PrepareLogFileName(isolate, FLAG_logfile); | 2027 PrepareLogFileName(log_file_name, isolate, FLAG_logfile); |
2033 log_->Initialize(log_file_name.get()); | 2028 log_->Initialize(log_file_name.c_str()); |
2034 | 2029 |
2035 | 2030 |
2036 if (FLAG_perf_basic_prof) { | 2031 if (FLAG_perf_basic_prof) { |
2037 perf_basic_logger_ = new PerfBasicLogger(); | 2032 perf_basic_logger_ = new PerfBasicLogger(); |
2038 addCodeEventListener(perf_basic_logger_); | 2033 addCodeEventListener(perf_basic_logger_); |
2039 } | 2034 } |
2040 | 2035 |
2041 if (FLAG_perf_jit_prof) { | 2036 if (FLAG_perf_jit_prof) { |
2042 perf_jit_logger_ = new PerfJitLogger(); | 2037 perf_jit_logger_ = new PerfJitLogger(); |
2043 addCodeEventListener(perf_jit_logger_); | 2038 addCodeEventListener(perf_jit_logger_); |
2044 } | 2039 } |
2045 | 2040 |
2046 if (FLAG_ll_prof) { | 2041 if (FLAG_ll_prof) { |
2047 ll_logger_ = new LowLevelLogger(log_file_name.get()); | 2042 ll_logger_ = new LowLevelLogger(log_file_name.c_str()); |
2048 addCodeEventListener(ll_logger_); | 2043 addCodeEventListener(ll_logger_); |
2049 } | 2044 } |
2050 | 2045 |
2051 ticker_ = new Ticker(isolate, kSamplingIntervalMs); | 2046 ticker_ = new Ticker(isolate, kSamplingIntervalMs); |
2052 | 2047 |
2053 if (Log::InitLogAtStart()) { | 2048 if (Log::InitLogAtStart()) { |
2054 is_logging_ = true; | 2049 is_logging_ = true; |
2055 } | 2050 } |
2056 | 2051 |
2057 if (FLAG_prof) { | 2052 if (FLAG_prof) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2126 if (jit_logger_) { | 2121 if (jit_logger_) { |
2127 removeCodeEventListener(jit_logger_); | 2122 removeCodeEventListener(jit_logger_); |
2128 delete jit_logger_; | 2123 delete jit_logger_; |
2129 jit_logger_ = NULL; | 2124 jit_logger_ = NULL; |
2130 } | 2125 } |
2131 | 2126 |
2132 return log_->Close(); | 2127 return log_->Close(); |
2133 } | 2128 } |
2134 | 2129 |
2135 } } // namespace v8::internal | 2130 } } // namespace v8::internal |
OLD | NEW |