Populate data sizes in audio egress metrics
The stream and metadata sizes are summed across all HotwordAudioStreams in the HotwordDetectedResult. Also logged the same byte sizes. Bug: 261793715 Bug: 244599440 Test: `statsd_testdrive 578` with sample app. The sizes in the metrics are the same as the ones logged, and the values are in line with what the sample app is sending in the HotwordDetectedResult. Change-Id: I48279bba854e3e6badc530fa485bb46c2097ce44
This commit is contained in:
@@ -108,6 +108,7 @@ final class HotwordAudioStreamCopier {
|
|||||||
final int audioStreamCount = audioStreams.size();
|
final int audioStreamCount = audioStreams.size();
|
||||||
List<HotwordAudioStream> newAudioStreams = new ArrayList<>(audioStreams.size());
|
List<HotwordAudioStream> newAudioStreams = new ArrayList<>(audioStreams.size());
|
||||||
List<CopyTaskInfo> copyTaskInfos = new ArrayList<>(audioStreams.size());
|
List<CopyTaskInfo> copyTaskInfos = new ArrayList<>(audioStreams.size());
|
||||||
|
int totalMetadataBundleSizeBytes = 0;
|
||||||
for (HotwordAudioStream audioStream : audioStreams) {
|
for (HotwordAudioStream audioStream : audioStreams) {
|
||||||
ParcelFileDescriptor[] clientPipe = ParcelFileDescriptor.createReliablePipe();
|
ParcelFileDescriptor[] clientPipe = ParcelFileDescriptor.createReliablePipe();
|
||||||
ParcelFileDescriptor clientAudioSource = clientPipe[0];
|
ParcelFileDescriptor clientAudioSource = clientPipe[0];
|
||||||
@@ -119,6 +120,7 @@ final class HotwordAudioStreamCopier {
|
|||||||
|
|
||||||
int copyBufferLength = DEFAULT_COPY_BUFFER_LENGTH_BYTES;
|
int copyBufferLength = DEFAULT_COPY_BUFFER_LENGTH_BYTES;
|
||||||
PersistableBundle metadata = audioStream.getMetadata();
|
PersistableBundle metadata = audioStream.getMetadata();
|
||||||
|
totalMetadataBundleSizeBytes += HotwordDetectedResult.getParcelableSize(metadata);
|
||||||
if (metadata.containsKey(KEY_AUDIO_STREAM_COPY_BUFFER_LENGTH_BYTES)) {
|
if (metadata.containsKey(KEY_AUDIO_STREAM_COPY_BUFFER_LENGTH_BYTES)) {
|
||||||
copyBufferLength = metadata.getInt(KEY_AUDIO_STREAM_COPY_BUFFER_LENGTH_BYTES, -1);
|
copyBufferLength = metadata.getInt(KEY_AUDIO_STREAM_COPY_BUFFER_LENGTH_BYTES, -1);
|
||||||
if (copyBufferLength < 1 || copyBufferLength > MAX_COPY_BUFFER_LENGTH_BYTES) {
|
if (copyBufferLength < 1 || copyBufferLength > MAX_COPY_BUFFER_LENGTH_BYTES) {
|
||||||
@@ -142,7 +144,9 @@ final class HotwordAudioStreamCopier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String resultTaskId = TASK_ID_PREFIX + System.identityHashCode(result);
|
String resultTaskId = TASK_ID_PREFIX + System.identityHashCode(result);
|
||||||
mExecutorService.execute(new HotwordDetectedResultCopyTask(resultTaskId, copyTaskInfos));
|
mExecutorService.execute(
|
||||||
|
new HotwordDetectedResultCopyTask(resultTaskId, copyTaskInfos,
|
||||||
|
totalMetadataBundleSizeBytes));
|
||||||
|
|
||||||
return result.buildUpon().setAudioStreams(newAudioStreams).build();
|
return result.buildUpon().setAudioStreams(newAudioStreams).build();
|
||||||
}
|
}
|
||||||
@@ -162,11 +166,14 @@ final class HotwordAudioStreamCopier {
|
|||||||
private class HotwordDetectedResultCopyTask implements Runnable {
|
private class HotwordDetectedResultCopyTask implements Runnable {
|
||||||
private final String mResultTaskId;
|
private final String mResultTaskId;
|
||||||
private final List<CopyTaskInfo> mCopyTaskInfos;
|
private final List<CopyTaskInfo> mCopyTaskInfos;
|
||||||
|
private final int mTotalMetadataSizeBytes;
|
||||||
private final ExecutorService mExecutorService = Executors.newCachedThreadPool();
|
private final ExecutorService mExecutorService = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
HotwordDetectedResultCopyTask(String resultTaskId, List<CopyTaskInfo> copyTaskInfos) {
|
HotwordDetectedResultCopyTask(String resultTaskId, List<CopyTaskInfo> copyTaskInfos,
|
||||||
|
int totalMetadataSizeBytes) {
|
||||||
mResultTaskId = resultTaskId;
|
mResultTaskId = resultTaskId;
|
||||||
mCopyTaskInfos = copyTaskInfos;
|
mCopyTaskInfos = copyTaskInfos;
|
||||||
|
mTotalMetadataSizeBytes = totalMetadataSizeBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -188,20 +195,36 @@ final class HotwordAudioStreamCopier {
|
|||||||
try {
|
try {
|
||||||
HotwordMetricsLogger.writeAudioEgressEvent(mDetectorType,
|
HotwordMetricsLogger.writeAudioEgressEvent(mDetectorType,
|
||||||
HOTWORD_AUDIO_EGRESS_EVENT_REPORTED__EVENT__STARTED,
|
HOTWORD_AUDIO_EGRESS_EVENT_REPORTED__EVENT__STARTED,
|
||||||
mVoiceInteractorUid, /* streamSizeBytes= */ 0, /* bundleSizeBytes= */ 0,
|
mVoiceInteractorUid, /* streamSizeBytes= */ 0, mTotalMetadataSizeBytes,
|
||||||
size);
|
size);
|
||||||
// TODO(b/244599891): Set timeout, close after inactivity
|
// TODO(b/244599891): Set timeout, close after inactivity
|
||||||
mExecutorService.invokeAll(tasks);
|
mExecutorService.invokeAll(tasks);
|
||||||
|
|
||||||
|
int totalStreamSizeBytes = 0;
|
||||||
|
for (SingleAudioStreamCopyTask task : tasks) {
|
||||||
|
totalStreamSizeBytes += task.mTotalCopiedBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
Slog.i(TAG, mResultTaskId + ": Task was completed. Total bytes streamed: "
|
||||||
|
+ totalStreamSizeBytes + ", total metadata bundle size bytes: "
|
||||||
|
+ mTotalMetadataSizeBytes);
|
||||||
HotwordMetricsLogger.writeAudioEgressEvent(mDetectorType,
|
HotwordMetricsLogger.writeAudioEgressEvent(mDetectorType,
|
||||||
HOTWORD_AUDIO_EGRESS_EVENT_REPORTED__EVENT__ENDED,
|
HOTWORD_AUDIO_EGRESS_EVENT_REPORTED__EVENT__ENDED,
|
||||||
mVoiceInteractorUid, /* streamSizeBytes= */ 0, /* bundleSizeBytes= */ 0,
|
mVoiceInteractorUid, totalStreamSizeBytes, mTotalMetadataSizeBytes,
|
||||||
size);
|
size);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
int totalStreamSizeBytes = 0;
|
||||||
|
for (SingleAudioStreamCopyTask task : tasks) {
|
||||||
|
totalStreamSizeBytes += task.mTotalCopiedBytes;
|
||||||
|
}
|
||||||
|
|
||||||
HotwordMetricsLogger.writeAudioEgressEvent(mDetectorType,
|
HotwordMetricsLogger.writeAudioEgressEvent(mDetectorType,
|
||||||
HOTWORD_AUDIO_EGRESS_EVENT_REPORTED__EVENT__INTERRUPTED_EXCEPTION,
|
HOTWORD_AUDIO_EGRESS_EVENT_REPORTED__EVENT__INTERRUPTED_EXCEPTION,
|
||||||
mVoiceInteractorUid, /* streamSizeBytes= */ 0, /* bundleSizeBytes= */ 0,
|
mVoiceInteractorUid, totalStreamSizeBytes, mTotalMetadataSizeBytes,
|
||||||
size);
|
size);
|
||||||
Slog.e(TAG, mResultTaskId + ": Task was interrupted", e);
|
Slog.e(TAG, mResultTaskId + ": Task was interrupted. Total bytes streamed: "
|
||||||
|
+ totalStreamSizeBytes + ", total metadata bundle size bytes: "
|
||||||
|
+ mTotalMetadataSizeBytes);
|
||||||
bestEffortPropagateError(e.getMessage());
|
bestEffortPropagateError(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
mAppOpsManager.finishOp(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD,
|
mAppOpsManager.finishOp(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD,
|
||||||
@@ -246,6 +269,8 @@ final class HotwordAudioStreamCopier {
|
|||||||
private final int mDetectorType;
|
private final int mDetectorType;
|
||||||
private final int mUid;
|
private final int mUid;
|
||||||
|
|
||||||
|
private volatile int mTotalCopiedBytes = 0;
|
||||||
|
|
||||||
SingleAudioStreamCopyTask(String streamTaskId, ParcelFileDescriptor audioSource,
|
SingleAudioStreamCopyTask(String streamTaskId, ParcelFileDescriptor audioSource,
|
||||||
ParcelFileDescriptor audioSink, int copyBufferLength, int detectorType, int uid) {
|
ParcelFileDescriptor audioSink, int copyBufferLength, int detectorType, int uid) {
|
||||||
mStreamTaskId = streamTaskId;
|
mStreamTaskId = streamTaskId;
|
||||||
@@ -290,6 +315,7 @@ final class HotwordAudioStreamCopier {
|
|||||||
Arrays.copyOfRange(buffer, 0, 20)));
|
Arrays.copyOfRange(buffer, 0, 20)));
|
||||||
}
|
}
|
||||||
fos.write(buffer, 0, bytesRead);
|
fos.write(buffer, 0, bytesRead);
|
||||||
|
mTotalCopiedBytes += bytesRead;
|
||||||
}
|
}
|
||||||
// TODO(b/244599891): Close PFDs after inactivity
|
// TODO(b/244599891): Close PFDs after inactivity
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user