OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 namespace v8 { | 33 namespace v8 { |
34 namespace internal { | 34 namespace internal { |
35 | 35 |
36 class Logger; | 36 class Logger; |
37 | 37 |
38 // Functions and data for performing output of log messages. | 38 // Functions and data for performing output of log messages. |
39 class Log { | 39 class Log { |
40 public: | 40 public: |
41 // Performs process-wide initialization. | 41 // Performs process-wide initialization. |
42 void Initialize(); | 42 void Initialize(const char* log_file_name); |
43 | 43 |
44 // Disables logging, but preserves acquired resources. | 44 // Disables logging, but preserves acquired resources. |
45 void stop() { is_stopped_ = true; } | 45 void stop() { is_stopped_ = true; } |
46 | 46 |
47 static bool InitLogAtStart() { | 47 static bool InitLogAtStart() { |
48 return FLAG_log || FLAG_log_runtime || FLAG_log_api | 48 return FLAG_log || FLAG_log_runtime || FLAG_log_api |
49 || FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect | 49 || FLAG_log_code || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect |
50 || FLAG_log_regexp || FLAG_ll_prof || FLAG_log_internal_timer_events; | 50 || FLAG_log_regexp || FLAG_ll_prof || FLAG_log_internal_timer_events; |
51 } | 51 } |
52 | 52 |
53 // Frees all resources acquired in Initialize and Open... functions. | 53 // Frees all resources acquired in Initialize and Open... functions. |
54 // When a temporary file is used for the log, returns its stream descriptor, | 54 // When a temporary file is used for the log, returns its stream descriptor, |
55 // leaving the file open. | 55 // leaving the file open. |
56 FILE* Close(); | 56 FILE* Close(); |
57 | 57 |
58 // Returns whether logging is enabled. | 58 // Returns whether logging is enabled. |
59 bool IsEnabled() { | 59 bool IsEnabled() { |
60 return !is_stopped_ && output_handle_ != NULL; | 60 return !is_stopped_ && output_handle_ != NULL; |
61 } | 61 } |
62 | 62 |
63 // Size of buffer used for formatting log messages. | 63 // Size of buffer used for formatting log messages. |
64 static const int kMessageBufferSize = 2048; | 64 static const int kMessageBufferSize = 2048; |
65 | 65 |
66 // This mode is only used in tests, as temporary files are automatically | 66 // This mode is only used in tests, as temporary files are automatically |
67 // deleted on close and thus can't be accessed afterwards. | 67 // deleted on close and thus can't be accessed afterwards. |
68 static const char* const kLogToTemporaryFile; | 68 static const char* const kLogToTemporaryFile; |
| 69 static const char* const kLogToConsole; |
69 | 70 |
70 private: | 71 private: |
71 explicit Log(Logger* logger); | 72 explicit Log(Logger* logger); |
72 | 73 |
73 // Opens stdout for logging. | 74 // Opens stdout for logging. |
74 void OpenStdout(); | 75 void OpenStdout(); |
75 | 76 |
76 // Opens file for logging. | 77 // Opens file for logging. |
77 void OpenFile(const char* name); | 78 void OpenFile(const char* name); |
78 | 79 |
(...skipping 10 matching lines...) Expand all Loading... |
89 return length; | 90 return length; |
90 } | 91 } |
91 | 92 |
92 // Whether logging is stopped (e.g. due to insufficient resources). | 93 // Whether logging is stopped (e.g. due to insufficient resources). |
93 bool is_stopped_; | 94 bool is_stopped_; |
94 | 95 |
95 // When logging is active output_handle_ is used to store a pointer to log | 96 // When logging is active output_handle_ is used to store a pointer to log |
96 // destination. mutex_ should be acquired before using output_handle_. | 97 // destination. mutex_ should be acquired before using output_handle_. |
97 FILE* output_handle_; | 98 FILE* output_handle_; |
98 | 99 |
99 // Used when low-level profiling is active. | |
100 FILE* ll_output_handle_; | |
101 | |
102 // mutex_ is a Mutex used for enforcing exclusive | 100 // mutex_ is a Mutex used for enforcing exclusive |
103 // access to the formatting buffer and the log file or log memory buffer. | 101 // access to the formatting buffer and the log file or log memory buffer. |
104 Mutex* mutex_; | 102 Mutex* mutex_; |
105 | 103 |
106 // Buffer used for formatting log messages. This is a singleton buffer and | 104 // Buffer used for formatting log messages. This is a singleton buffer and |
107 // mutex_ should be acquired before using it. | 105 // mutex_ should be acquired before using it. |
108 char* message_buffer_; | 106 char* message_buffer_; |
109 | 107 |
110 Logger* logger_; | 108 Logger* logger_; |
111 | 109 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 149 |
152 private: | 150 private: |
153 Log* log_; | 151 Log* log_; |
154 ScopedLock sl; | 152 ScopedLock sl; |
155 int pos_; | 153 int pos_; |
156 }; | 154 }; |
157 | 155 |
158 } } // namespace v8::internal | 156 } } // namespace v8::internal |
159 | 157 |
160 #endif // V8_LOG_UTILS_H_ | 158 #endif // V8_LOG_UTILS_H_ |
OLD | NEW |