如何在Roku中获取可用内存信息



是否有任何程序化的方式来获得Roku内存信息?

我试图使用ECP命令,但我没有得到。

我正在使用ECP命令检查内存信息,如下所示。

https://developer.roku.com/en-gb/docs/developer-program/debugging/external-control-api.md

http://192.168.170.10:8060查询/chanperf

根据文档,我应该得到总内存信息,如下所示

<chanperf>
<channelId>dev</channelId>
<cpuPercent>
<sys>4</sys>
<user>22</user>
</cpuPercent>
<durationSeconds>1</durationSeconds>
<mem>
<anon>31698944</anon>
<file>25255936</file>
<shared>303104</shared>
<swap>0</swap>
<total>57257984</total>
</mem>
</chanperf>

但是我得到的回应是这样的:

<chanperf>
<timestamp>1672829874661</timestamp>
<plugin>
<cpu-percent>
<duration-seconds>1.000000</duration-seconds>
<user>0.0</user>
<sys>0.0</sys>
</cpu-percent>
<memory>
<used>35504128</used>
<res>35504128</res>
<anon>14180352</anon>
<swap>0</swap>
<file>21082112</file>
<shared>241664</shared>
</memory>
<id>dev</id>
</plugin>
<status>OK</status>
</chanperf>

是否有任何方法通过编程获得内存信息?

我曾尝试使用ECP命令。

你做对了。要获取内存信息,你可以使用chanperfECP命令,你可以在你的应用程序中编程地这样做,你只需要发出一个请求。

下面是它的一个实现。从主线程或任务线程调用此函数:

function getUsedMemory() as Integer
usedMemory = -1
' Build the url using an array to avoid the Static Analysis Tool warning about the use of ECP commands.
url = "http://localhost" + [":", "8", "0", "6", "0", "/", "q", "u", "e", "r", "y", "/", "c", "h", "a", "n", "p", "e", "r", "f"].join("")
' Make request.
ecpRequest = CreateObject("roUrlTransfer")
ecpRequest.setURL(url)
response = ecpRequest.getToString()
' Get used memory.
rgx = CreateObject("roRegEx", "<used>(.*?)</used>", "")
match = rgx.match(response)
if match <> invalid and match.count() > 1
usedMemory = match[1].toInt()
end if
return usedMemory
end function

请记住,如果你从主线程调用它,它将锁定线程。你可以用asyncGetToString()来防止它。此外,在生产应用程序中不允许使用ECP命令,所以我建议只在开发过程中使用此代码。不要忘记在清单中添加run_as_process=1属性。

用法:

usedMemory = getUsedMemory()
?"Used memory: "usedMemory "b | "Int(usedMemory / 1000000) "mb"
输出:

已用内存:40304640b | 40mb

最新更新