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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.cpp

Issue 1978403004: Add UMA histograms for WebAudio (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address more review comments. Created 4 years, 6 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/webaudio/AudioContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 void AbstractAudioContext::throwExceptionForClosedState(ExceptionState& exceptio nState) 227 void AbstractAudioContext::throwExceptionForClosedState(ExceptionState& exceptio nState)
228 { 228 {
229 exceptionState.throwDOMException(InvalidStateError, "AudioContext has been c losed."); 229 exceptionState.throwDOMException(InvalidStateError, "AudioContext has been c losed.");
230 } 230 }
231 231
232 AudioBuffer* AbstractAudioContext::createBuffer(unsigned numberOfChannels, size_ t numberOfFrames, float sampleRate, ExceptionState& exceptionState) 232 AudioBuffer* AbstractAudioContext::createBuffer(unsigned numberOfChannels, size_ t numberOfFrames, float sampleRate, ExceptionState& exceptionState)
233 { 233 {
234 // It's ok to call createBuffer, even if the context is closed because the A udioBuffer doesn't 234 // It's ok to call createBuffer, even if the context is closed because the A udioBuffer doesn't
235 // really "belong" to any particular context. 235 // really "belong" to any particular context.
236 236
237 return AudioBuffer::create(numberOfChannels, numberOfFrames, sampleRate, exc eptionState); 237 AudioBuffer* buffer = AudioBuffer::create(numberOfChannels, numberOfFrames, sampleRate, exceptionState);
238
239 if (buffer) {
240 // Only record the data if the creation succeeded.
241 DEFINE_STATIC_LOCAL(SparseHistogram, audioBufferChannelsHistogram,
242 ("WebAudio.AudioBuffer.NumberOfChannels"));
243 DEFINE_STATIC_LOCAL(SparseHistogram, audioBufferLengthHistogram,
244 ("WebAudio.AudioBuffer.Length"));
245 DEFINE_STATIC_LOCAL(SparseHistogram, audioBufferSampleRateHistogram,
246 ("WebAudio.AudioBuffer.SampleRate"));
247
248 audioBufferChannelsHistogram.sample(numberOfChannels);
249
250 // To limit the size of the histogram, record 10*log10(numberOfFrames),
251 // clipping the value at 60 (buffer size of 1 million frames). This
252 // gives 60 entries in the histogram.
253 double histogramValue = 10*log10(numberOfFrames);
254 audioBufferLengthHistogram.sample(clampTo(static_cast<int>(0.5 + histogr amValue), 0, 60));
Mark P 2016/06/09 20:18:23 If you're doing a histogram with min and max and e
Raymond Toy 2016/06/09 22:34:28 Done.
255
256 // To limit the size of the histogram, record
257 // 40+10*log2(sampleRate/48000), clipping the value to lie between 0
258 // and 60. These limits correspond to a min rate of 3000 and a max of
259 // 192000. This gives 60 entries in the histogram.
260 histogramValue = 40 + 10*log2(sampleRate / 48000);
261 audioBufferSampleRateHistogram.sample(clampTo(static_cast<int>(0.5 + his togramValue), 0, 60));
262
263 // Compute the ratio of the buffer rate and the context rate so we know
264 // how often the buffer needs to be resampled to match the context. For
265 // the histogram, we multiply the ratio by 100 and round to the nearest
266 // integer. If the context is closed, don't record this because we
267 // don't have a sample rate for closed context.
268 if (!isContextClosed()) {
269 DEFINE_STATIC_LOCAL(SparseHistogram, audioBufferSampleRateRatioHisto gram,
270 ("WebAudio.AudioBuffer.SampleRateRatio"));
271 float ratio = sampleRate / this->sampleRate();
272 histogramValue = clampTo(40 + 10*log2(ratio), 0.0, 60.0);
273 audioBufferSampleRateRatioHistogram.sample(static_cast<int>(0.5 + hi stogramValue));
274 }
275 }
276
277 return buffer;
238 } 278 }
239 279
240 ScriptPromise AbstractAudioContext::decodeAudioData(ScriptState* scriptState, DO MArrayBuffer* audioData, AudioBufferCallback* successCallback, AudioBufferCallba ck* errorCallback, ExceptionState& exceptionState) 280 ScriptPromise AbstractAudioContext::decodeAudioData(ScriptState* scriptState, DO MArrayBuffer* audioData, AudioBufferCallback* successCallback, AudioBufferCallba ck* errorCallback, ExceptionState& exceptionState)
241 { 281 {
242 ASSERT(isMainThread()); 282 ASSERT(isMainThread());
243 ASSERT(audioData); 283 ASSERT(audioData);
244 284
245 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 285 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
246 ScriptPromise promise = resolver->promise(); 286 ScriptPromise promise = resolver->promise();
247 287
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 830
791 SecurityOrigin* AbstractAudioContext::getSecurityOrigin() const 831 SecurityOrigin* AbstractAudioContext::getSecurityOrigin() const
792 { 832 {
793 if (getExecutionContext()) 833 if (getExecutionContext())
794 return getExecutionContext()->getSecurityOrigin(); 834 return getExecutionContext()->getSecurityOrigin();
795 835
796 return nullptr; 836 return nullptr;
797 } 837 }
798 838
799 } // namespace blink 839 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/webaudio/AudioContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698