简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长!
优质专栏:Audio工程师进阶系列【原创干货持续更新中……】🚀
人生格言: 人生从来没有捷径,只有行动才是治疗恐惧和懒惰的唯一良药.
1.前言
本篇目的:介绍一下一个媒体记录分析服务MediaMetricsService,它主要记录媒体服务相关的参数。
例如:audio、codec、extractor、audio.flinger、audio.thread线程等。
2.如何使用MediaMetricsService服务dump媒体信息
<1>.显示媒体信息top 100堆栈使用量排序
# dumpsys media.metrics --heap
Dump of the media.metrics process:
Metrics gathering: enabled
Since Boot: Submissions: 285 Accepted: 285
Records Discarded: 0 (by Count: 0 by Expiration: 0)
0: {audio.flinger, (06-03 19:31:28.234), (audioserver, 0, 1041), (event#=ctor)}
1: {audio.thread.13, (06-03 19:31:28.235), (audioserver, 1094, 1041), (event#=ctor, threadId=13, type=MIXER)}
2: {audio.thread.13, (06-03 19:31:28.235), (audioserver, 0, 1041), (channelCount=2, channelMask=3, encoding=AUDIO_FORMAT_PCM_16_BIT, event#=readParameters, flags=AUDIO_OUTPUT_FLAG_PRIMARY|AUDIO_OUTPUT_FLAG_FAST, frameCount=960, hal.encoding=AUDIO_FORMAT_PCM_16_BIT, hal.frameCount=240, hal.latencyMs=1.000000e+01, haptic.channelCount=0, haptic.channelMask=0, sampleRate=48000)}
3: {audio.flinger, (06-03 19:31:28.235), (audioserver, 0, 1041), (event#=setVoiceVolume, voiceVolume=-0.000000e+00)}
4: {audio.thread.13, (06-03 19:31:28.235), (audioserver, 0, 1041), (event#=createAudioPatch, inputDevices=, outputDevices=(AUDIO_DEVICE_OUT_SPEAKER, ))}
5: {audio.thread.13, (06-03 19:31:28.236), (audioserver, 0, 1041), (event#=beginAudioIntervalGroup, outputDevices=(AUDIO_DEVICE_OUT_SPEAKER, ))}
6: {audio.thread.21, (06-03 19:31:28.236), (audioserver, 1094, 1041), (event#=ctor, threadId=21, type=MIXER)}
7: {audio.thread.21, (06-03 19:31:28.236), (audioserver, 0, 1041), (channelCount=2, channelMask=3, encoding=AUDIO_FORMAT_PCM_16_BIT, event#=readParameters, flags=AUDIO_OUTPUT_FLAG_FAST|AUDIO_OUTPUT_FLAG_RAW, frameCount=960, hal.encoding=AUDIO_FORMAT_PCM_16_BIT, hal.frameCount=96, hal.latencyMs=5.000000e+00, haptic.channelCount=0, haptic.channelMask=0, sampleRate=48000)}
8: {audio.thread.21, (06-03 19:31:28.236), (audioserver, 0, 1041), (event#=createAudioPatch, inputDevices=, outputDevices=(AUDIO_DEVICE_OUT_SPEAKER, ))}
9: {audio.thread.21, (06-03 19:31:28.236), (audioserver, 0, 1041), (event#=beginAudioIntervalGroup, outputDevices=(AUDIO_DEVICE_OUT_SPEAKER, ))}
10: {audio.thread.29, (06-03 19:31:28.236), (audioserver, 1094, 1041), (event#=ctor, threadId=29, type=MIXER)}
11: {audio.thread.29, (06-03 19:31:28.236), (audioserver, 0, 1041), (channelCount=2, channelMask=3, encoding=AUDIO_FORMAT_PCM_24_BIT_PACKED, event#=readParameters, flags=AUDIO_OUTPUT_FLAG_DEEP_BUFFER, frameCount=1920, hal.encoding=AUDIO_FORMAT_PCM_24_BIT_PACKED, hal.frameCount=1920, hal.latencyMs=8.000000e+01, haptic.channelCount=0, haptic.channelMask=0, sampleRate=48000)}
12: {audio.thread.29, (06-03 19:31:28.236), (audioserver, 0, 1041), (event#=createAudioPatch, inputDevices=, outputDevices=(AUDIO_DEVICE_OUT_SPEAKER, ))}
13: {audio.thread.29, (06-03 19:31:28.236), (audioserver, 0, 1041), (event#=beginAudioIntervalGroup, outputDevices=(AUDIO_DEVICE_OUT_SPEAKER, ))}
14: {audio.thread.37, (06-03 19:31:28.236), (audioserver, 1094, 1041), (event#=ctor, threadId=37, type=OFFLOAD)}
15: {audio.thread.37, (06-03 19:31:28.236), (audioserver, 0, 1041), (channelCount=1, channelMask=1, encoding=AUDIO_FORMAT_MP3, event#=readParameters, flags=AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_NON_BLOCKING|AUDIO_OUTPUT_FLAG_GAPLESS_OFFLOAD, frameCount=262144, hal.encoding=AUDIO_FORMAT_MP3, hal.frameCount=262144, hal.latencyMs=9.600000e+01, haptic.channelCount=0, haptic.channelMask=0, sampleRate=8000)}
16: {audio.thread.37, (06-03 19:31:28.236), (audioserver, 0, 1041), (event#=dtor)}
17: {audio.thread.45, (06-03 19:31:28.236), (audioserver, 1094, 1041), (event#=ctor, threadId=45, type=MIXER)}
18: {audio.thread.45, (06-03 19:31:28.236), (audioserver, 0, 1041), (channelCount=2, channelMask=3, encoding=AUDIO_FORMAT_PCM_16_BIT, event#=readParameters, flags=AUDIO_OUTPUT_FLAG_NONE, frameCount=768, hal.encoding=AUDIO_FORMAT_PCM_16_BIT, hal.frameCount=256, hal.latencyMs=2.100000e+01, haptic.channelCount=0, haptic.channelMask=0, sampleRate=48000)}
19: {audio.thread.45, (06-03 19:31:28.236), (audioserver, 0, 1041), (event#=createAudioPatch, inputDevices=, outputDevices=(AUDIO_DEVICE_OUT_TELEPHONY_TX, ))}
20: {audio.thread.45, (06-03 19:31:28.236), (audioserver, 0, 1041), (event#=beginAudioIntervalGroup, outputDevices=(AUDIO_DEVICE_OUT_TELEPHONY_TX, ))}
21: {audio.thread.53, (06-03 19:31:28.236), (audioserver, 1094, 1041), (event#=ctor, threadId=53, type=MMAP_PLAYBACK)}
22: {audio.thread.53, (06-03 19:31:28.236), (audioserver, 0, 1041), (channelCount=0, channelMask=3, encoding=AUDIO_FORMAT_PCM_16_BIT, event#=readParameters, frameCount=48, hal.encoding=AUDIO_FORMAT_PCM_16_BIT, hal.frameCount=48, sampleRate=48000)}
23: {audio.thread.53, (06-03 19:31:28.236), (audioserver, 0, 1041), (event#=dtor)}
24: {audio.thread.61, (06-03 19:31:28.237), (audioserver, 1094, 1041), (event#=ctor, threadId=61, type=MIXER)}
25: {audio.thread.61, (06-03 19:31:28.237), (audioserver, 0, 1041), (channelCount=2, channelMask=3, encoding=AUDIO_FORMAT_PCM_16_BIT, event#=readParameters, flags=AUDIO_OUTPUT_FLAG_VOIP_RX, frameCount=960, hal.encoding=AUDIO_FORMAT_PCM_16_BIT, hal.frameCount=960, hal.latencyMs=4.000000e+01, haptic.channelCount=0, haptic.channelMask=0, sampleRate=48000)}
26: {audio.thread.61, (06-03 19:31:28.237), (audioserver, 0, 1041), (event#=createAudioPatch, inputDevices=, outputDevices=(AUDIO_DEVICE_OUT_SPEAKER, ))}
27: {audio.thread.61, (06-03 19:31:28.237), (audioserver, 0, 1041), (event#=beginAudioIntervalGroup, outputDevices=(AUDIO_DEVICE_OUT_SPEAKER, ))}
........
<2>.清除已保存的记录
# dumpsys media.metrics --clear
<3>.显示全部记录
# dumpsys media.metrics --all
<4>.media.metrics帮助
# dumpsys media.metrics --help
Recognized parameters:
--all show all records
--clear clear out saved records
--heap show heap usage (top 100)
--help display help
--prefix X process records for component X
--since X X < 0: records from -X seconds in the past
X = 0: ignore
X > 0: records from X seconds since Unix epoch
--unreachable show unreachable memory (leaks)