Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: content/browser/webrtc_log_manager.cc

Issue 14329020: Implementing uploading of a WebRTC diagnostic log. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed pre-submit warnings/errors (including adding bzip2 to content/browser DEPS). Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/webrtc_log_manager.h"
6
7 #if defined(USE_SYSTEM_LIBBZ2)
8 #include <bzlib.h>
9 #else
10 #include "third_party/bzip2/bzlib.h"
11 #endif
12
13 #include "base/shared_memory.h"
14 #include "content/common/partial_circular_buffer.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/content_browser_client.h"
17
18 namespace content {
19
20 namespace {
21 // TODO(grunell): Smaller size?
22 const uint32 kIntermediateCompressionBufferSize = 0.5 * 1024 * 1024; // 0.5 MB
23 //const uint32 kIntermediateCompressionBufferSize = 10 * 1024; // 10 KB
24 } // namespace
25
26 WebRtcLogManager::WebRtcLogManager() {
27 }
28
29 WebRtcLogManager::~WebRtcLogManager() {
30 }
31
32 WebRtcLogManager* WebRtcLogManager::GetInstance() {
33 return Singleton<WebRtcLogManager>::get();
34 }
35
36 void WebRtcLogManager::UploadLog(base::SharedMemory* shared_memory,
37 uint32 length,
38 base::PlatformFile file) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
40 DCHECK(shared_memory);
41 DCHECK(shared_memory->memory());
42
43 // We have taken ownership of |shared_memory|, make sure it's deleted when
44 // we're done.
45 scoped_ptr<base::SharedMemory> scoped_shared_memory(shared_memory);
46
47 ReadAndCompressLog(reinterpret_cast<uint8*>(scoped_shared_memory->memory()),
48 length, file);
49 DCHECK_EQ(0, base::SeekPlatformFile(file, base::PLATFORM_FILE_FROM_BEGIN, 0));
50
51 GetContentClient()->browser()->UploadWebRtcLog(file);
52 }
53
54 void WebRtcLogManager::ReadAndCompressLog(uint8* input,
Jói 2013/05/02 16:47:31 It almost seems strange that the content layer wou
Henrik Grunell 2013/05/03 07:59:36 I definitely like to have this in the embedder. Th
55 uint32 input_size,
56 base::PlatformFile output_file) {
57 const bool debug_print = false;
58
59 if (debug_print) LOG(ERROR) << "*** DUMPING LOG BUFFER BEGIN ***";
60
61 PartialCircularBuffer read_pcb(input, input_size);
62
63 // TODO(grunell): Maybe better to write directly to file with BZ2_bzWrite?
64 bz_stream stream = {0};
65 int result = BZ2_bzCompressInit(&stream, 6, 0, 0);
66 DCHECK(result == BZ_OK);
67
68 scoped_ptr<uint8[]> intermediate_buffer(
69 new uint8[kIntermediateCompressionBufferSize]);
70 scoped_ptr<uint8[]> compressed(
71 new uint8[kIntermediateCompressionBufferSize]);
72 memset(intermediate_buffer.get(), 0, kIntermediateCompressionBufferSize);
73 memset(compressed.get(), 0, kIntermediateCompressionBufferSize);
74 uint32 read = read_pcb.Read(intermediate_buffer.get(),
75 kIntermediateCompressionBufferSize);
76
77 if (debug_print) {
78 std::string tmp(
79 reinterpret_cast<char*>(&intermediate_buffer.get()[0]), read);
80 LOG(ERROR) << "Data (" << read << "):" << '\n' << tmp;
81 }
82
83 stream.next_in = reinterpret_cast<char*>(&intermediate_buffer.get()[0]);
84 stream.avail_in = read;
85 char* compressed_char_ptr = reinterpret_cast<char*>(&compressed.get()[0]);
86
87 // Keeps track of written output.
88 unsigned int last_total_out = stream.total_out_lo32;
89
90 while (read == kIntermediateCompressionBufferSize) {
91 stream.next_out = compressed_char_ptr;
92 stream.avail_out = kIntermediateCompressionBufferSize;
93 result = BZ2_bzCompress(&stream, BZ_RUN);
94 if (debug_print) {
95 LOG(ERROR) << "RESULT = " << result << ", read = " << read;
96 LOG(ERROR) << "avail_in = " << stream.avail_in
97 << ", total_in_lo32 = " << stream.total_in_lo32;
98 LOG(ERROR) << "avail_out = " << stream.avail_out
99 << ", total_out_lo32 = " << stream.total_out_lo32;
100 }
101 DCHECK(result == BZ_RUN_OK);
102 base::WritePlatformFileAtCurrentPos(output_file, compressed_char_ptr,
103 stream.total_out_lo32 - last_total_out);
104 last_total_out = stream.total_out_lo32;
105 read = read_pcb.Read(intermediate_buffer.get(),
106 kIntermediateCompressionBufferSize);
107 stream.next_in = reinterpret_cast<char*>(&intermediate_buffer.get()[0]);
108 stream.avail_in = read;
109
110 if (debug_print) {
111 std::string tmp(
112 reinterpret_cast<char*>(&intermediate_buffer.get()[0]), read);
113 LOG(ERROR) << "Data (" << read << "):" << '\n' << tmp;
114 }
115 }
116
117 do {
118 stream.next_out = compressed_char_ptr;
119 stream.avail_out = kIntermediateCompressionBufferSize;
120 result = BZ2_bzCompress(&stream, BZ_FINISH);
121 if (debug_print) {
122 LOG(ERROR) << "RESULT = " << result << ", read = " << read;
123 LOG(ERROR) << "avail_in = " << stream.avail_in
124 << ", total_in_lo32 = " << stream.total_in_lo32;
125 LOG(ERROR) << "avail_out = " << stream.avail_out
126 << ", total_out_lo32 = " << stream.total_out_lo32;
127 }
128 base::WritePlatformFileAtCurrentPos(output_file, compressed_char_ptr,
129 stream.total_out_lo32 - last_total_out);
130 last_total_out = stream.total_out_lo32;
131 } while (result == BZ_FINISH_OK);
132 DCHECK(result == BZ_STREAM_END);
133
134 result = BZ2_bzCompressEnd(&stream);
135 DCHECK(result == BZ_OK);
136
137 if (debug_print) LOG(ERROR) << "*** DUMPING LOG BUFFER END ***";
138 }
139
140 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698