简体   繁体   中英

How to get available memory info in Roku

Is there any programmatic way to get Roku memory info?

I was trying to use ECP command, but there I am not getting.

I am using ECP command to check memory info as below.

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

http://192.168.170.10:8060/query/chanperf

As per documentation i should get total memory info, as below.

<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>

But i am getting response like this:

<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>

Is there any way to get memory info through programtically?

I had tried to use ECP command.

You're on the right track. To get memory info you can use the chanperf ECP command, and you can do so programmatically from within your app, you just have to make a request.

Here's an implementation of it. Call this function from the main thread or a task thread:

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

Keep in mind that if you call it from the main thread it'll lock the thread. You can use asyncGetToString() instead to prevent that. Also, the use of ECP commands is not allowed on production apps so I'd recommend using this code during the development process only. And don't forget to add the run_as_process=1 attribute to your manifest.

Usage:

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

Output:

Used memory: 40304640b | 40mb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM