ayiyoyoyo.api.runtime Since 26.11.11.1
运行时信息与控制。
提供当前应用运行时的控制、动态资源信息和系统查询。
exit(retcode) Since 26.11.11.1
退出当前小应用。
| 参数 | 类型 | 说明 |
|---|---|---|
| retcode | number | (可选) 进程退出码,默认为 0。 |
javascript
await __A.runtime.exit();javascript
await __A.runtime.exit(10);getBootTime() Since 26.12.12.1
获取系统启动时间戳(Unix 时间)。
| 返回值 | 说明 |
|---|---|
| number | null | 系统启动时间戳(Unix 时间);失败时为 null。 |
javascript
const ts = await __A.runtime.getBootTime();getCpuCount(logical) Since 26.12.12.1
获取 CPU 核心数。
| 参数 | 类型 | 说明 |
|---|---|---|
| logical | boolean | (可选) true 返回逻辑核心数,false 返回物理核心数。默认 true。 |
| 返回值 | 说明 |
|---|---|
| number | null | 核心数;拿不到时为 null。 |
javascript
const n = await __A.runtime.getCpuCount();
const physical = await __A.runtime.getCpuCount(false);getCpuFreq(percpu) Since 26.12.12.1
获取 CPU 频率。
| 参数 | 类型 | 说明 |
|---|---|---|
| percpu | boolean | (可选) true 返回每个核心,false 返回总计。默认 false。 |
| 返回值 | 说明 |
|---|---|
| object | null | CPU 频率;失败时为 null。 |
javascript
const f = await __A.runtime.getCpuFreq();getCpuPercent(percpu) Since 26.12.12.1
获取 CPU 使用率百分比(瞬时,非阻塞)。
| 参数 | 类型 | 说明 |
|---|---|---|
| percpu | boolean | (可选) true 返回每个核心的列表,false 返回总使用率。默认 false。 |
| 返回值 | 说明 |
|---|---|
| number | object | 使用率百分比。 |
javascript
const p = await __A.runtime.getCpuPercent();
const per = await __A.runtime.getCpuPercent(true);getCpuStats() Since 26.12.12.1
获取 CPU 统计信息(上下文切换、中断等)。
| 返回值 | 说明 |
|---|---|
| object | null | CPU 统计信息(上下文切换、中断等);失败时为 null。 |
javascript
const s = await __A.runtime.getCpuStats();getCpuTimes(percpu) Since 26.12.12.1
获取 CPU 时间统计。
| 参数 | 类型 | 说明 |
|---|---|---|
| percpu | boolean | (可选) true 返回每个核心,false 返回总计。默认 false。 |
| 返回值 | 说明 |
|---|---|
| object | null | CPU 时间统计;失败时为 null。 |
javascript
const t = await __A.runtime.getCpuTimes();getCpuTimesPercent(percpu) Since 26.12.12.1
获取 CPU 时间占比统计(瞬时)。
| 参数 | 类型 | 说明 |
|---|---|---|
| percpu | boolean | (可选) true 返回每个核心,false 返回总计。默认 false。 |
| 返回值 | 说明 |
|---|---|
| object | null | CPU 时间占比统计(瞬时);失败时为 null。 |
javascript
const t = await __A.runtime.getCpuTimesPercent();getDiskIoCounters(per_disk, nowrap) Since 26.12.12.1
获取磁盘 IO 统计。
| 参数 | 类型 | 说明 |
|---|---|---|
| per_disk | boolean | (可选) true 返回每个磁盘,false 返回总计。默认 false。 |
| nowrap | boolean | (可选) 是否把计数器字段包装成 namedtuple。默认 true。 |
| 返回值 | 说明 |
|---|---|
| object | null | 磁盘 IO 统计;失败时为 null。 |
javascript
const io = await __A.runtime.getDiskIoCounters();getDiskPartitions(all_disk) Since 26.12.12.1
获取磁盘分区列表。
| 参数 | 类型 | 说明 |
|---|---|---|
| all_disk | boolean | (可选) true 包含伪文件系统(tmpfs 等),false 只含物理磁盘。默认 false。 |
| 返回值 | 说明 |
|---|---|
| object | null | 磁盘分区列表;失败时为 null。 |
javascript
const parts = await __A.runtime.getDiskPartitions();getDiskUsage(path) Since 26.12.12.1
获取指定路径所在磁盘的使用情况。
| 参数 | 类型 | 说明 |
|---|---|---|
| path | string | (可选) 路径。为 null 时用基座数据目录。 |
| 返回值 | 说明 |
|---|---|
| object | null | 指定路径所在磁盘的使用情况;失败时为 null。 |
javascript
const u = await __A.runtime.getDiskUsage();
const u2 = await __A.runtime.getDiskUsage('/home');getLoadAvg() Since 26.12.12.1
获取系统平均负载(1/5/15 分钟)。
| 返回值 | 说明 |
|---|---|
| object | null | (1min, 5min, 15min);部分平台不支持时返回 null。 |
javascript
const [a, b, c] = await __A.runtime.getLoadAvg();getNetConnections(kind) Since 26.12.12.1
获取当前网络连接。
| 参数 | 类型 | 说明 |
|---|---|---|
| kind | string | (可选) 'inet' / 'inet4' / 'inet6' / 'tcp' / 'udp' / 'all' 等。默认 'inet'。 |
| 返回值 | 说明 |
|---|---|
| object | null | 当前网络连接;失败时为 null。 |
javascript
const conns = await __A.runtime.getNetConnections();getNetIfAddrs() Since 26.12.12.1
获取网卡地址列表。
| 返回值 | 说明 |
|---|---|
| object | null | 网卡地址列表;失败时为 null。 |
javascript
const addrs = await __A.runtime.getNetIfAddrs();getNetIfStats() Since 26.12.12.1
获取网卡状态(是否 up、速率等)。
| 返回值 | 说明 |
|---|---|
| object | null | 网卡状态(是否 up、速率等);失败时为 null。 |
javascript
const stats = await __A.runtime.getNetIfStats();getNetIoCounters(per_nic, nowrap) Since 26.12.12.1
获取网络 IO 统计。
| 参数 | 类型 | 说明 |
|---|---|---|
| per_nic | boolean | (可选) true 返回每个网卡,false 返回总计。默认 false。 |
| nowrap | boolean | (可选) 是否把计数器字段包装成 namedtuple。默认 true。 |
| 返回值 | 说明 |
|---|---|
| object | null | 网络 IO 统计;失败时为 null。 |
javascript
const io = await __A.runtime.getNetIoCounters();getSensorsBattery() Since 26.12.12.1
获取电池信息。无电池或平台不支持时返回空 dict。
| 返回值 | 说明 |
|---|---|
| object | null | 电池信息。无电池或平台不支持时返回空 dict;失败时为 null。 |
javascript
const b = await __A.runtime.getSensorsBattery();
if (b.percent !== undefined) console.log(b.percent);getSensorsFans() Since 26.12.12.1
获取风扇转速。平台/硬件不支持时返回空 dict。
| 返回值 | 说明 |
|---|---|
| object | null | 风扇转速。平台/硬件不支持时返回空 dict;失败时为 null。 |
javascript
const fans = await __A.runtime.getSensorsFans();getSensorsTemperatures(fahrenheit) Since 26.12.12.1
获取温度传感器数据。平台/硬件不支持时返回空 dict。
| 参数 | 类型 | 说明 |
|---|---|---|
| fahrenheit | boolean | (可选) true 返回华氏度。默认 false。 |
| 返回值 | 说明 |
|---|---|
| object | null | 温度传感器数据。平台/硬件不支持时返回空 dict;失败时为 null。 |
javascript
const temps = await __A.runtime.getSensorsTemperatures();getSwapMemory() Since 26.12.12.1
获取交换分区信息。
| 返回值 | 说明 |
|---|---|
| object | null | 交换分区信息;失败时为 null。 |
javascript
const s = await __A.runtime.getSwapMemory();getUsers() Since 26.12.12.1
获取当前登录用户列表。
| 返回值 | 说明 |
|---|---|
| object | null | 当前登录用户列表;失败时为 null。 |
javascript
const users = await __A.runtime.getUsers();getVirtualMemory() Since 26.12.12.1
获取虚拟内存信息。
| 返回值 | 说明 |
|---|---|
| object | null | 虚拟内存信息;失败时为 null。 |
javascript
const m = await __A.runtime.getVirtualMemory();
console.log(m.percent);noop() Since 26.11.11.1
空操作。
无任何逻辑,直接返回。可以用于:
- 验证 jsapi 是否正确注册、bridge 是否连通。
- 作为最小调用的,测量一次 bridge 往返的耗时。
运行 100 次,获取平均耗费时间:
javascript
const times = 100;
const start = performance.now();
for (let i = 0; i < times; i++) {
await __A.runtime.noop();
}
const avgMs = (performance.now() - start) / times;
console.log(`AVG time: ${avgMs.toFixed(4)} ms`);