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

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: Use CustomCountHistogram 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
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
244 // Arbitrarly limit the maximum length to 1 million frames (about 20 sec
245 // at 48kHz). The number of buckets is fairly arbitrary.
246 DEFINE_STATIC_LOCAL(CustomCountHistogram, audioBufferLengthHistogram,
247 ("WebAudio.AudioBuffer.Length", 1, 1000000, 50));
248 // The limits are the min and max AudioBuffer sample rates currently
249 // supported. We use explicit values here instead of
250 // AudioUtilities::minAudioBufferSampleRate() and
251 // AudioUtilities::maxAudioBufferSampleRate(). The number of buckets is
252 // fairly arbitrary.
253 DEFINE_STATIC_LOCAL(CustomCountHistogram, audioBufferSampleRateHistogram ,
254 ("WebAudio.AudioBuffer.SampleRate", 3000, 192000, 60));
255
256 audioBufferChannelsHistogram.sample(numberOfChannels);
257 audioBufferLengthHistogram.count(numberOfFrames);
258 audioBufferSampleRateHistogram.count(sampleRate);
259
260 // Compute the ratio of the buffer rate and the context rate so we know
261 // how often the buffer needs to be resampled to match the context. For
262 // the histogram, we multiply the ratio by 100 and round to the nearest
263 // integer. If the context is closed, don't record this because we
264 // don't have a sample rate for closed context.
265 if (!isContextClosed()) {
266 // The limits are choosen from 100*(3000/192000) = 1.5625 and
267 // 100*(192000/3000) = 6400, where 3000 and 192000 are the current
268 // min and max sample rates possible for an AudioBuffer. The number
269 // of buckets is fairly arbitrary.
270 DEFINE_STATIC_LOCAL(CustomCountHistogram, audioBufferSampleRateRatio Histogram,
271 ("WebAudio.AudioBuffer.SampleRateRatio", 1, 6400, 50));
272 float ratio = 100 * sampleRate / this->sampleRate();
273 audioBufferSampleRateRatioHistogram.count(static_cast<int>(0.5 + rat io));
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

Powered by Google App Engine
This is Rietveld 408576698