Metrics for AudioRecord

Collect media metrics for audiorecord. Basic framework and initial set
of metrics.

Bug: 70569777
Test: recordings, observe stats
Change-Id: I66fce1eec46cc13a93b106c2be34d23c138920de
gugelfrei
Ray Essick 7 years ago
parent ed30470cf0
commit 734d186db7

@ -26,6 +26,8 @@
#include <utils/Log.h>
#include <private/media/AudioTrackShared.h>
#include <media/IAudioFlinger.h>
#include <media/MediaAnalyticsItem.h>
#include <media/TypeConverter.h>
#define WAIT_PERIOD_MS 10
@ -65,6 +67,34 @@ status_t AudioRecord::getMinFrameCount(
// ---------------------------------------------------------------------------
static std::string audioFormatTypeString(audio_format_t value) {
std::string formatType;
if (FormatConverter::toString(value, formatType)) {
return formatType;
}
char rawbuffer[16]; // room for "%d"
snprintf(rawbuffer, sizeof(rawbuffer), "%d", value);
return rawbuffer;
}
void AudioRecord::MediaMetrics::gather(const AudioRecord *record)
{
// key for media statistics is defined in the header
// attrs for media statistics
static constexpr char kAudioRecordChannelCount[] = "android.media.audiorecord.channels";
static constexpr char kAudioRecordFormat[] = "android.media.audiorecord.format";
static constexpr char kAudioRecordLatency[] = "android.media.audiorecord.latency";
static constexpr char kAudioRecordSampleRate[] = "android.media.audiorecord.samplerate";
// constructor guarantees mAnalyticsItem is valid
mAnalyticsItem->setInt32(kAudioRecordLatency, record->mLatency);
mAnalyticsItem->setInt32(kAudioRecordSampleRate, record->mSampleRate);
mAnalyticsItem->setInt32(kAudioRecordChannelCount, record->mChannelCount);
mAnalyticsItem->setCString(kAudioRecordFormat,
audioFormatTypeString(record->mFormat).c_str());
}
AudioRecord::AudioRecord(const String16 &opPackageName)
: mActive(false), mStatus(NO_INIT), mOpPackageName(opPackageName),
mSessionId(AUDIO_SESSION_ALLOCATE),
@ -105,6 +135,8 @@ AudioRecord::AudioRecord(
AudioRecord::~AudioRecord()
{
mMediaMetrics.gather(this);
if (mStatus == NO_ERROR) {
// Make sure that callback function exits in the case where
// it is looping on buffer empty condition in obtainBuffer().

@ -21,6 +21,7 @@
#include <cutils/sched_policy.h>
#include <media/AudioSystem.h>
#include <media/AudioTimestamp.h>
#include <media/MediaAnalyticsItem.h>
#include <media/Modulo.h>
#include <utils/RefBase.h>
#include <utils/threads.h>
@ -688,6 +689,24 @@ private:
// activity and connected devices
wp<AudioSystem::AudioDeviceCallback> mDeviceCallback;
private:
class MediaMetrics {
public:
MediaMetrics() : mAnalyticsItem(new MediaAnalyticsItem("audiorecord")) {
}
~MediaMetrics() {
// mAnalyticsItem alloc failure will be flagged in the constructor
// don't log empty records
if (mAnalyticsItem->count() > 0) {
mAnalyticsItem->setFinalized(true);
mAnalyticsItem->selfrecord();
}
}
void gather(const AudioRecord *record);
private:
std::unique_ptr<MediaAnalyticsItem> mAnalyticsItem;
};
MediaMetrics mMediaMetrics;
};
}; // namespace android

Loading…
Cancel
Save