火基地性能监测插件
非官方电容插件 基地性能监测[^1]
使用大小写
Firebase性能监控插件通常用于了解您应用的性能特征,例如:
- 自定义代码跟踪: 测量应用程序中的具体任务需要多长时间, 如加载数据或处理图像.
- 自定义衡量标准:在微量内计数与性能相关的事件,如缓存点击或重试.
- 业绩分割: 添加自定义属性到您的痕迹中, 如用户 ID, 以分割您的性能数据 .
- 遵守隐私:在运行时间启用或禁用性能监测,例如基于用户的同意.
兼容性
| 插件版本 | 电容版本 | 状态 |
|---|---|---|
| 8.x.x (英语) | >=8.x.x | 积极支持 |
| 7.x.x (中文(简体) ) | 7.x.x (中文(简体) ) | 折旧 |
| 6.x.x (中文(简体) ) | 6.x.x (中文(简体) ) | 折旧 |
| 5.x.x (中文(简体) ) | 5.x.x (中文(简体) ) | 折旧 |
| 1.x.x (中文(简体) ) | 4.x.x (中文(简体) ) | 折旧 |
指南
- 带有火基地的电容控制器中的 App 性能监视器: 自动和自定义跟踪, 用于应用程序的启动、 渲染和网络调用 .
- 如何在电容App中使用火把: 整个插件家族在一个向导中,性能监测是应用健康的一半.
安装
你可以用我们的 AI 辅助设置 以安装插件. 添加数据 超级技能 至您的 AI 工具,使用以下命令:
npx skills add capawesome-team/skills --skill capacitor-plugins
然后使用下列提示:
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capacitor-firebase/performance` plugin in my project.
如果你喜欢 手动设置,通过运行以下命令来安装插件,并遵循下面的平台特定指令:
npm install @capacitor-firebase/performance firebase
npx cap sync
如果您还没有将 Firebase 添加到您的项目中(机器人 编号 : iOS系统 编号 : 网页) (中文(简体) ).
机器人
见 将性能监控插件添加到您的应用程序中 并遵守指示 正确设置您的应用程序.
变量
如果需要, 您可以在您的应用程序中定义以下工程变量 variables.gradle 要更改依赖的默认版本的文件 :
$firebasePerfVersion版本com.google.firebase:firebase-perf(默认 :22.0.4(中文(简体) )
如果您在工程中遇到其它插件的依赖性冲突, 这会有所帮助 .
iOS系统
Swift 软件包管理器
在您的 capacitor.config.json (或 capacitor.config.ts) 避免 SwiftPM 软件包识别相撞数字 :
{
"experimental": {
"ios": {
"spm": {
"packageOptions": {
"@capacitor-firebase/performance": {
"symlink": true
}
}
}
}
}
}
请注意目标 packageOptions 支持需要控制器 CLI 8.4.0+ (中文(简体) )。 。 。 .
配置
此插件不需要配置 .
演示
这里有一个实例: robingenz/电容器-火力基地-插座-demo
使用量
以下例子显示如何开始并停止追踪,记录自定义度量衡,添加自定义属性,切换性能监测,并手动记录一个追踪.
开始和停止追踪
启动自定义代码跟踪, 以测量您应用程序中的特定任务需要多长时间, 并在任务完成后立即停止 :
import { FirebasePerformance } from '@capacitor-firebase/performance';
const startTrace = async () => {
await FirebasePerformance.startTrace({ traceName: 'test_trace' });
};
const stopTrace = async () => {
await FirebasePerformance.stopTrace({ traceName: 'test_trace' });
};
记录自定义衡量标准
设定一个微量的自定义度量的值, 从原子上递增, 或者读取其当前值 。 注意, 测量值下至最接近的整数 :
import { FirebasePerformance } from '@capacitor-firebase/performance';
const putMetric = async () => {
await FirebasePerformance.putMetric({
traceName: 'test_trace',
metricName: 'item_cache_hit',
num: 1,
});
};
const incrementMetric = async () => {
await FirebasePerformance.incrementMetric({
traceName: 'test_trace',
metricName: 'item_cache_hit',
incrementBy: 1,
});
};
const getMetric = async () => {
const result = await FirebasePerformance.getMetric({
traceName: 'test_trace',
metricName: 'item_cache_hit',
});
return result.value;
};
添加自定义属性到跟踪
将自定义属性设定在一个跟踪上,例如用户ID,以分割您的性能数据。 您也可以再次读取或删除:
import { FirebasePerformance } from '@capacitor-firebase/performance';
const putAttribute = async () => {
await FirebasePerformance.putAttribute({
traceName: 'test_trace',
attribute: 'user_id',
value: '123',
});
};
const getAttribute = async () => {
const result = await FirebasePerformance.getAttribute({
traceName: 'test_trace',
attribute: 'user_id',
});
return result.attributes;
};
const getAttributes = async () => {
const result = await FirebasePerformance.getAttributes({ traceName: 'test_trace' });
return result.attributes;
};
const removeAttribute = async () => {
await FirebasePerformance.removeAttribute({
traceName: 'test_trace',
attribute: 'user_id',
});
};
启用或禁用性能监测
在运行时启用或禁用性能监测,例如基于用户的同意. 设置随应用程序的下个启动而应用 :
import { FirebasePerformance } from '@capacitor-firebase/performance';
const setEnabled = async () => {
await FirebasePerformance.setEnabled({ enabled: true });
};
const isEnabled = async () => {
const result = await FirebasePerformance.isEnabled();
return result.enabled;
};
手动记录追踪
记录已完成的任务的追踪,提供开始时间和持续时间。 仅在网上提供 :
import { FirebasePerformance } from '@capacitor-firebase/performance';
const record = async () => {
await FirebasePerformance.record({
traceName: 'test_trace',
startTime: Date.now(),
duration: 1000,
options: {
metrics: {
item_cache_hit: 1,
},
attributes: {
user_id: '123',
},
},
});
};
API 密码
startTrace(...)stopTrace(...)incrementMetric(...)setEnabled(...)isEnabled()putAttribute(...)getAttribute(...)getAttributes(...)removeAttribute(...)putMetric(...)getMetric(...)record(...)- 接口
- 类型异名
启动 Trace (...)
startTrace(options: StartTraceOptions) => Promise<void>
开始追踪.
| 参数 | 类型 |
|---|---|
options | StartTraceOptions |
自: 0.1.0 (中文(简体) )
停止追踪(...)
stopTrace(options: StopTraceOptions) => Promise<void>
停止追踪.
| 参数 | 类型 |
|---|---|
options | StopTraceOptions |
自: 0.1.0 (中文(简体) )
递增量(...)
incrementMetric(options: IncrementMetricOptions) => Promise<void>
原子递增度量,以选定微量的给定名称表示 incrementBy 数值.
| 参数 | 类型 |
|---|---|
options | IncrementMetricOptions |
自: 0.1.0 (中文(简体) )
设置可启用(...)
setEnabled(options: SetEnabledOptions) => Promise<void>
启用或禁用性能监测. 将在应用程序的下一个启动时应用 .
| 参数 | 类型 |
|---|---|
options | SetEnabledOptions |
自: 0.1.0 (中文(简体) )
已启用
isEnabled() => Promise<IsEnabledResult>
确定是否启用或禁用性能监测.
回返情况: Promise<IsEnabledResult>
自: 0.1.0 (中文(简体) )
设置属性(...)
putAttribute(options: PutAttributeOptions) => Promise<void>
设置给定值的自定义属性.
| 参数 | 类型 |
|---|---|
options | PutAttributeOptions |
自: 6.3.0 (单位:千美元)
获取属性(...)
getAttribute(options: GetAttributeOptions) => Promise<GetAttributeResult>
返回一个跟踪的自定义属性的值.
| 参数 | 类型 |
|---|---|
options | GetAttributeOptions |
回返情况: Promise<GetAttributeResult>
自: 6.3.0 (单位:千美元)
获取属性(...)
getAttributes(options: GetAttributesOptions) => Promise<GetAttributesResult>
以它们的值获取一个跟踪的所有自定义属性.
| 参数 | 类型 |
|---|---|
options | GetAttributesOptions |
回返情况: Promise<GetAttributesResult>
自: 6.3.0 (单位:千美元)
删除属性(...)
removeAttribute(options: RemoveAttributeOptions) => Promise<void>
从给定名称的跟踪中删除自定义属性.
| 参数 | 类型 |
|---|---|
options | GetAttributeOptions |
自: 6.3.0 (单位:千美元)
putMetric (...) 数据
putMetric(options: PutMetricOptions) => Promise<void>
设置自定义度量衡的值.
| 参数 | 类型 |
|---|---|
options | PutMetricOptions |
自: 6.3.0 (单位:千美元)
获取Metric (...)
getMetric(options: GetMetricOptions) => Promise<GetMetricResult>
按名称获取自定义计量值.
| 参数 | 类型 |
|---|---|
options | GetMetricOptions |
回返情况: Promise<GetMetricResult>
自: 6.3.0 (单位:千美元)
记录(...)
record(options: RecordOptions) => Promise<void>
记录一下它的名字和选择.
仅在网上提供.
| 参数 | 类型 |
|---|---|
options | RecordOptions |
自: 6.3.0 (单位:千美元)
接口
启动跟踪选项
| Prop | 类型 | 说明 | 自兹 |
|---|---|---|---|
traceName | string | 自定义踪迹名称 。 自定义代码痕迹的名称必须满足以下要求:没有前导或后导的白空间,没有前导的下划线( )字符,最大长度为100个字符. | 0.1.0 (中文(简体) ) |
停止跟踪选项
| Prop | 类型 | 说明 | 自兹 |
|---|---|---|---|
traceName | string | 设定的追踪名称 startTrace。 。 。 . | 0.1.0 (中文(简体) ) |
增量计量选项
| Prop | 类型 | 说明 | 默认 | 自兹 |
|---|---|---|---|---|
traceName | string | 设定的追踪名称 startTrace。 。 。 . | 0.1.0 (中文(简体) ) | |
metricName | string | 要递增的衡量标准名称. | 0.1.0 (中文(简体) ) | |
incrementBy | number | 计量标准需要递增的金额. | 1 | 0.1.0 (中文(简体) ) |
设置可选选项
| Prop | 类型 | 说明 | 自兹 |
|---|---|---|---|
enabled | boolean | 如能进行业绩监测. | 0.1.0 (中文(简体) ) |
已启用结果
| Prop | 类型 | 说明 | 自兹 |
|---|---|---|---|
enabled | boolean | true 如果启用了性能监测,否则 false。 。 。 . | 0.1.0 (中文(简体) ) |
配置选项
| Prop | 类型 | 说明 | 自兹 |
|---|---|---|---|
traceName | string | 确定属性的追踪名称 . | 6.3.0 (单位:千美元) |
attribute | string | 设置其值的属性名称 . | 6.3.0 (单位:千美元) |
value | string | 要设置到属性的值 . | 6.3.0 (单位:千美元) |
获取属性结果
| Prop | 类型 | 说明 | 自兹 |
|---|---|---|---|
value | string | null | 自定义属性的值 . | 6.3.0 (单位:千美元) |
获取属性选项
| Prop | 类型 | 说明 | 自兹 |
|---|---|---|---|
traceName | string | 确定属性的追踪名称 . | 6.3.0 (单位:千美元) |
attribute | string | 获取其值的属性名称 . | 6.3.0 (单位:千美元) |
获取属性
| Prop | 类型 | 说明 | 自兹 |
|---|---|---|---|
attributes | { [key: string]: string; } | 一张带有其价值的痕量的所有自定义属性的地图. | 6.3.0 (单位:千美元) |
获取属性选项
| Prop | 类型 | 说明 | 自兹 |
|---|---|---|---|
traceName | string | 追踪的命名以获得其属性. | 6.3.0 (单位:千美元) |
设置计量选项
| Prop | 类型 | 说明 | 自兹 |
|---|---|---|---|
traceName | string | 追踪器的名称来设定其度量. | 6.3.0 (单位:千美元) |
metricName | string | 度量衡名称. | 6.3.0 (单位:千美元) |
num | number | 为度量衡设定的值 。 给定值下至最接近的整数. | 6.3.0 (单位:千美元) |
获取医学结果
| Prop | 类型 | 说明 | 自兹 |
|---|---|---|---|
value | number | 如果存在衡量标准,则其价值. | 6.3.0 (单位:千美元) |
获得计量选项
| Prop | 类型 | 说明 | 自兹 |
|---|---|---|---|
traceName | string | 追踪器的名称来得到它的度量. | 6.3.0 (单位:千美元) |
metricName | string | 度量衡名称. | 6.3.0 (单位:千美元) |
记录选项
| Prop | 类型 | 说明 | 自兹 |
|---|---|---|---|
traceName | string | 追踪记录的名称. | 6.3.0 (单位:千美元) |
startTime | number | 追踪的开始时间 以毫秒计. | 6.3.0 (单位:千美元) |
duration | number | 追踪持续时间以毫秒计. | 6.3.0 (单位:千美元) |
options | { metrics?: { [key: string]: number; }; attributes?: { [key: string]: string; }; } | 一个可选对象,它持有自定义度量和属性的可选地图. | 6.3.0 (单位:千美元) |
类型异名
删除属性选项
财务问题
我该如何衡量我应用程序中一项具体任务的持续时间?
启动自定义代码跟踪 startTrace(...) 在任务开始和停止之前 stopTrace(...) 如本报告所示,一旦任务完成,将立即完成 使用示例 页:1 可以在阻止后用自定义的度量和属性来丰富痕量.
对自定义微量名称有何要求?
自定义代码痕迹的名称不得包含正后方或后方的白空间,不得从下划线开始(_)),并可能最长有100个字符.
度量衡和属性有什么区别?
度量衡是微量的数值,例如缓存点击的计数器,设置在 putMetric(...) 或随 incrementMetric(...)。请注意,测量值下至最接近的整数。 属性是一个微量的字符串值,例如用户代号,它与 putAttribute(...) 并可用于分割您的性能数据.
用户能否在运行时禁用性能监控 ?
是的,打电话 setEnabled(...) 以启用或禁用性能监测,例如基于用户的同意。 设置随应用程序的下个开始而被应用. 使用 isEnabled() 用于确定当前是否启用或禁用性能监测.
为什么 record 方法不工作 在Android和iOS?
这个 record(...) 方法只在网络上提供。 在Android和iOS上,请使用 startTrace(...) 财务报告和审定财务报表 stopTrace(...) 以衡量任务的持续时间.
相关插件
通讯
随时更新有关卡帕韦索姆、Capacitor和Ionic生态系统的最新消息和最新消息,因为我们 《卡帕索克通讯》。 。 。 .
更改日志
见 变动情况。 。 。 .
许可证
见 自由主义。 。 。 .
[^1]: 这个项目不附属于Google LLC或其任何子公司或子公司,也不获得其认可、支持、赞助或批准.