Pms API

To use Samsung Product API,

<script type="text/javascript" src="$WEBAPIS/webapis/webapis.js"></script>

Should be loaded in index.html

This module defines the Web App Memory APIs provided by the PMS stability-daemon.
These APIs allow web applications to query their real-time memory usage, memory limit,
and remaining memory budget, and to register a callback that fires when the memory
usage exceeds the allowed limit.

Since : 10.0

Product : TV, B2B

Privilege Level : Public

Privilege : http://tizen.org/privilege/system

Summary of Interfaces and Methods

Interface

Method

PmsManagerObject

PmsManager

DOMString getVersion();
long getWebAppMemoryUsage();
long getWebAppMemoryLimit();
void setMemoryUsageCallback(MemoryUsageCallback callback);
void unsetMemoryUsageCallback();

MemoryUsageCallback

void onmemoryexceeded(MemoryInfo memInfo);

1. Type Definitions

1.1 MemoryInfo

Contains memory information passed to the MemoryUsageCallback.

dictionary MemoryInfo {
  DOMString procName;
  long usedRss;
  long allowedRss;
};

The following values are supported

  • procName : Process name of webapp
  • usedRss : used memory by webapp
  • allowedRss : allowed memory for a webapp

2. Interfaces

2.1 PmsManagerObject

Defines a WebApi object instance of the Tizen Samsung Product API.
The webapis.pms object enables access to PMS Web App Memory API functionality.

[NoInterfaceObject] interface PmsManagerObject {
  readonly attribute PmsManager pms;
};
WebApi implements PmsManagerObject;

Since : 10.0

Attributes

  • readonly PmsManager pms
    PMS API namespace
    Since : 10.0

2.2 PmsManager

Provides methods for PMS Web App Memory functionalities.
These APIs query the stability-daemon's in-memory process monitoring data
for registered web applications.

[NoInterfaceObject] interface PmsManager {
  DOMString getVersion();
  long getWebAppMemoryUsage();
  long getWebAppMemoryLimit();
  void setMemoryUsageCallback(MemoryUsageCallback callback);
  void unsetMemoryUsageCallback();
};

Since : 10.0

Methods

getVersion

Retrieves the version of the PMS API.

DOMString getVersion();

Product : TV, B2B

Privilege Level : Public

Privilege : http://tizen.org/privilege/system

Return Value :

  • DOMString : Version string of the PMS API

Since : 10.0

Code Example :

try {
  var ver = webapis.pms.getVersion();
  console.log("PMS API version: " + ver);
} catch (e) {
  console.log(" Error: " + e.message);
}

getWebAppMemoryUsage

Retrieves the current total memory usage of the calling web application.
The total memory is computed as RSS + Swap + GEM + GPU, all in KB.

long getWebAppMemoryUsage();

Product : TV, B2B

Privilege Level : Public

Privilege : http://tizen.org/privilege/system

Return Value :

  • long : Memory usage in KB

Exceptions :

  • WebAPIException
    • with error type InvalidValuesError, if the process name does not exist.
    • with error type SecurityError, if the application does not have the privilege to call this method.

Code Example :

try {
  var usage = webapis.pms.getWebAppMemoryUsage();
  console.log(" memory usage = " + usage + " KB");
} catch (e) {
  console.log(" Error: " + e.message);
}

getWebAppMemoryLimit

Retrieves the memory limit of the calling web application.
The limit is the maximum allowed memory (allowedRss) for the web app, in KB.

long getWebAppMemoryLimit();

Product : TV, B2B

Privilege Level : Public

Privilege : http://tizen.org/privilege/system

Return Value :

  • long : Memory limit in KB

Exceptions :

  • WebAPIException
    • with error type InvalidValuesError, if the process name does not exist.
    • with error type SecurityError, if the application does not have the privilege to call this method.

Code Example :

try {
  var limit = webapis.pms.getWebAppMemoryLimit();
  console.log(" memory limit = " + limit + " KB");
} catch (e) {
  console.log(" Error: " + e.message);
}

setMemoryUsageCallback

Registers a callback that fires when the calling web app's memory
usage exceeds its allowedRss limit.

void setMemoryUsageCallback(MemoryUsageCallback callback);

Product : TV, B2B

Privilege Level : Public

Privilege : http://tizen.org/privilege/system

Parameters :

  • callback : - Function called when memory exceeds the allowed limit.
    Receives a MemoryInfo object with procName, usedRss,
    and allowedRss fields.

Exceptions :

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.
    • with error type InvalidStateError, if a callback is already registered.

Since : 10.0

Code Example :

try {
  webapis.pms.setMemoryUsageCallback(function(memInfo) {
    console.log("Memory exceeded: " + memInfo.usedRss + " KB (limit: " + memInfo.allowedRss + " KB)");
  });
} catch (e) {
  console.log(" Error: " + e.message);
}

unsetMemoryUsageCallback

Unregisters the memory usage callback previously set by
setMemoryUsageCallback.

void unsetMemoryUsageCallback();

Product : TV, B2B

Privilege Level : Public

Privilege : http://tizen.org/privilege/system

Exceptions :

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

Since : 10.0

Code Example :

try {
  webapis.pms.unsetMemoryUsageCallback();
} catch (e) {
  console.log(" Error: " + e.message);
}

2.3 MemoryUsageCallback

Callback interface for memory usage limit notifications.

[Callback, NoInterfaceObject] interface MemoryUsageCallback {
  void onmemoryexceeded(MemoryInfo memInfo);
};

Since : 10.0

Methods

onmemoryexceeded

Called when the web app's memory usage exceeds its
allowedRss limit.

void onmemoryexceeded(MemoryInfo memInfo);

Privilege Level : Public

Privilege : http://tizen.org/privilege/system

Parameters :

  • memInfo : - MemoryInfo object containing procName, usedRss,
    and allowedRss

Since : 10.0

3. Full WebIDL

module Pms {
  dictionary MemoryInfo {
    DOMString procName;
    long usedRss;
    long allowedRss;
  };

  [NoInterfaceObject] interface PmsManagerObject {
    readonly attribute PmsManager pms;
  };

  WebApi implements PmsManagerObject;

  [NoInterfaceObject] interface PmsManager {
    DOMString getVersion();
    long getWebAppMemoryUsage();
    long getWebAppMemoryLimit();
    void setMemoryUsageCallback(MemoryUsageCallback callback);
    void unsetMemoryUsageCallback();
  };

  [Callback, NoInterfaceObject] interface MemoryUsageCallback {
    void onmemoryexceeded(MemoryInfo memInfo);
  };

};