Question
I'm trying to retrieve the RAM usage for my currently running Tizen application. According to the documentation, it should be possible to get current RAM usage per running app.
I attempted to implement this in a basic analog clock application by modifying index.html and using the following code:
var myCurrentMemUsage = tizen.systeminfo.getCapability('http://tizen.org/runtime/memory.allocated.self');
However, this approach isn't working. I've tested on both Tizen 2016 and 2017 versions, and I receive the following console error:
NotSupportedError: Value for given key was not found undefined:
getCapability
Could you please help me understand why this isn't working and suggest alternative methods to retrieve memory usage?
Answer
Problem Understanding
The user is attempting to monitor their application's memory usage in real-time using the Tizen systeminfo API. The current approach using getCapability with the memory.allocated.self key is not working as expected, throwing a NotSupportedError.
Solution Methods
- Using systeminfo API (Recommended Approach)
The correct way to get memory information is through the
tizen.systeminfo.getPropertyValue()method instead ofgetCapability. Here's the proper implementation:
tizen.systeminfo.getPropertyValue(
"MEMORY",
function(memory) {
console.log("Total memory: " + memory.physical.total);
console.log("Available memory: " + memory.physical.available);
console.log("Used memory: " + (memory.physical.total - memory.physical.available));
},
function(error) {
console.log("Error getting memory info: " + error.message);
}
);
- Alternative Method for Application-Specific Memory Usage For application-specific memory usage, you can use the following approach:
tizen.application.getCurrentApplication().getMemoryUsage().then(
function(memoryUsage) {
console.log("Current app memory usage: " + memoryUsage);
},
function(error) {
console.log("Error getting app memory usage: " + error.message);
}
);
Additional Tips
- Make sure your application has the proper privileges in config.xml:
<tizen:privilege name="http://tizen.org/privilege/systemmonitor"/>
- The memory values returned are in kilobytes (KB)
- For more detailed memory profiling, consider using the Tizen Studio Profiler tool
- Remember that memory usage can fluctuate frequently, so consider implementing periodic checks rather than one-time measurements