Bug 932215 - Lazily allocate log buffers for webrtc (4MB saving). r=jib

This commit is contained in:
Randell Jesup 2013-10-30 12:13:07 -04:00
parent e2d895bec0
commit 93cf1e684e
4 changed files with 42 additions and 3 deletions

View File

@ -111,6 +111,8 @@
'include_tests%': 0,
'enable_tracing%': 0,
# lazily allocate the ~4MB of trace message buffers if set
'enable_lazy_trace_alloc%': 0,
'enable_android_opensl%': 0,
}, { # Settings for the standalone (not-in-Chromium) build.

View File

@ -132,6 +132,11 @@
'trace_win.h',
],
}],
['enable_lazy_trace_alloc==0', {
'defines': [
'WEBRTC_LAZY_TRACE_ALLOC',
],
}],
['OS=="android" or moz_widget_toolkit_gonk==1', {
'defines': [
'WEBRTC_THREAD_RR',

View File

@ -88,8 +88,12 @@ TraceImpl::TraceImpl()
for (int m = 0; m < WEBRTC_TRACE_NUM_ARRAY; ++m) {
for (int n = 0; n < WEBRTC_TRACE_MAX_QUEUE; ++n) {
#if defined(WEBRTC_LAZY_TRACE_ALLOC)
message_queue_[m][n] = new
char[WEBRTC_TRACE_MAX_MESSAGE_SIZE];
#else
message_queue_[m][n] = NULL;
#endif
}
}
}
@ -340,6 +344,21 @@ int32_t TraceImpl::AddModuleAndId(char* trace_message,
int32_t TraceImpl::SetTraceFileImpl(const char* file_name_utf8,
const bool add_file_counter) {
#if !defined(WEBRTC_LAZY_TRACE_ALLOC)
if (file_name_utf8) {
// Lazy-allocate trace buffers to save memory.
// Avoid locking issues by not holding both critsects at once.
// Do this before we can return true from .Open().
CriticalSectionScoped lock(critsect_array_);
for (int m = 0; m < WEBRTC_TRACE_NUM_ARRAY; ++m) {
for (int n = 0; n < WEBRTC_TRACE_MAX_QUEUE; ++n) {
message_queue_[m][n] = new char[WEBRTC_TRACE_MAX_MESSAGE_SIZE];
}
}
}
#endif
CriticalSectionScoped lock(critsect_interface_);
trace_file_.Flush();
@ -424,7 +443,19 @@ void TraceImpl::AddMessageToList(
CriticalSectionScoped lock(critsect_array_);
if (next_free_idx_[active_queue_] >= WEBRTC_TRACE_MAX_QUEUE) {
uint16_t idx = next_free_idx_[active_queue_];
#if !defined(WEBRTC_LAZY_TRACE_ALLOC)
// Avoid grabbing another lock just to check Open(); use
// the fact we've allocated buffers to decide whether to save
// the message in the buffer. Use the indexing as this minimizes
// cache misses/etc
if (!message_queue_[active_queue_][idx]) {
return;
}
#endif
if (idx >= WEBRTC_TRACE_MAX_QUEUE) {
if (!trace_file_.Open() && !callback_) {
// Keep at least the last 1/4 of old messages when not logging.
// TODO(hellner): isn't this redundant. The user will make it known
@ -436,7 +467,7 @@ void TraceImpl::AddMessageToList(
message_queue_[active_queue_][n + last_quarter_offset],
WEBRTC_TRACE_MAX_MESSAGE_SIZE);
}
next_free_idx_[active_queue_] = WEBRTC_TRACE_MAX_QUEUE / 4;
idx = next_free_idx_[active_queue_] = WEBRTC_TRACE_MAX_QUEUE / 4;
} else {
// More messages are being written than there is room for in the
// buffer. Drop any new messages.
@ -449,7 +480,6 @@ void TraceImpl::AddMessageToList(
}
}
uint16_t idx = next_free_idx_[active_queue_];
next_free_idx_[active_queue_]++;
level_[active_queue_][idx] = level;

View File

@ -21,6 +21,8 @@
'use_system_libvpx': 0,
'build_libjpeg': 0,
'build_libvpx': 0,
# saves 4MB when webrtc_trace is off
'enable_lazy_trace_alloc': 1,
# turn off mandatory use of NEON and instead use NEON detection
'arm_neon': 0,