android - 如何从 ADB shell 强制/触发 xamarin mono 到 GC?
问题描述
尝试使用此命令adb shell debug.mono.profile获取堆射击。
那么使用 adb shell 触发 GC 的命令是什么?
解决方案
添加到调用覆盖的BroadcastReceiver
应用程序。GC.Collect
OnReceive
这是我使用的一个:
#if DEBUG
[BroadcastReceiver(Name = ReceiverName, Enabled = true, Exported = true)]
[IntentFilter(new string[] { IntentFilterName })]
public class MonoGCBroadcastReceiver : BroadcastReceiver
{
const string ReceiverName = "com.sushihangover.someapp.garbagecollect";
const string IntentFilterName = "perform.mono.gc";
readonly string TAG = Application.Context.PackageName;
public override void OnReceive(Context context, Intent intent)
{
if (intent.Action == IntentFilterName)
{
var generation = intent.GetIntExtra("generation", 9999);
if (!Enum.TryParse(intent.GetStringExtra("mode"), true, out GCCollectionMode mode))
{
mode = GCCollectionMode.Forced;
}
var force = intent.GetBooleanExtra("forced", true);
var compacting = intent.GetBooleanExtra("compacting", true);
Log.Debug(TAG, $"GC: G:{generation} : M:{mode} : F:{force} C:{compacting}");
GC.Collect(generation, mode, force, compacting);
}
}
}
#endif
现在,您可以使用adb
调用该接收器并为垃圾收集器传递可选参数。
例子:
export packageName="com.sushihangover.someapp"
adb shell setprop debug.mono.profile log:heapshot
# Start you app
adb shell am broadcast \
-n $packageName/.garbagecollect \
-a perform.mono.gc \
--es mode "force" \
--ei generation 1 \
--ez forced true
// Clear debug.mono.profile when all done collecting your mlpd
adb shell setprop debug.mono.profile '""'
推荐阅读
- javascript - google.language API 不再可用
- java - 取消 GWT 重复定时器
- javascript - 如何在所有具有相同 id 的 td 上输出值?
- javascript - 使用 javascript [500 (Internal Server Error)] 从 php 数据在谷歌地图上设置标记
- robotframework - 如何将一长串论点分解成几条短线?
- python - 选择列不为空且等于(字符串)值的行
- c# - 在电子邮件中添加多行集合文本
- c# - 通知 Windows 10 开始菜单更改
- sonata-admin - Symfony 3.4 - SonataUser - Twig - 空白页
- javascript - Google App Script emailing entire workbook as opposed to a single sheet