viewerPerformanceWatchdogMixin是一个Cesium.js的混合对象,用于监测Cesium Viewer的性能表现。
var viewer = new Cesium.Viewer('cesiumContainer');
Cesium.viewerPerformanceWatchdogMixin(viewer);
用于指定该混合对象是属于Cesium的,避免命名冲突。
Cesium PerformanceWatchdog对象,用于监测Cesium Viewer的性能表现。
当Cesium Viewer的帧率低于可接受的范围时,显示在控制台的消息文本。默认值为 The rendering engine is not keeping up with the expected framerate.
当Cesium Viewer的帧率恢复到可接受的范围时,所执行的回调函数。该回调被传入当前 Viewer 对象以及实时帧率(以 Hz 为单位)。
function goodFrameRateCallback(viewer, fps) {
console.log("Viewer's FPS:", fps);
}
当Cesium Viewer的帧率低于可接受的范围时,所执行的回调函数。该回调被传入当前 Viewer 对象以及实时帧率(以 Hz 为单位).
function lowFrameRateCallback(viewer, fps) {
console.warn("Viewer's FPS is too low:", fps);
}
定义了低帧率下限。如果帧率低于这个下限,它会触发lowFrameRateCallback
。默认值是5。
var performanceWatchdog = viewer.performanceWatchdog;
performanceWatchdog.lowFrameRateTrigger = 10;
定义的performanceWatchdog
的足够高的帧率是多少。默认值是20。
定义从c位置开始之前的帧范围,在该时间范围内,帧率的平均值将被监控。默认值是30.
var performanceWatchdog = viewer.performanceWatchdog;
performanceWatchdog.samplingWindow = 60;
以秒为单位定义performanceWatchdog
冷启动阶段的持续时间。在此期间, performanceWatchdog
将仅仅持续记录帧率。当过去的时间超过这个值后,performanceWatchdog
将开始触发goodFrameRateCallback
,lowFrameRateCallback
将在触发之前立即触发前缀事件。默认值为5.
var performanceWatchdog = viewer.performanceWatchdog;
performanceWatchdog.warmupPeriod = 10;
开始统计帧率
var performanceWatchdog = viewer.performanceWatchdog;
performanceWatchdog.evenStart();
结束统计帧率
var performanceWatchdog = viewer.performanceWatchdog;
performanceWatchdog.eventEnd();
更新性能监控的触发器。这将更新当前帧率,并根据活动的值调用回调。
var performanceWatchdog = viewer.performanceWatchdog;
performanceWatchdog.update();
删除已设定的性能监控触发器。
var performanceWatchdog = viewer.performanceWatchdog;
performanceWatchdog.destroy();
var viewer = new Cesium.Viewer('cesiumContainer');
Cesium.viewerPerformanceWatchdogMixin(viewer);
var performanceWatchdog = viewer.performanceWatchdog;
performanceWatchdog.lowFrameRateCallback = function(viewer, fps) {
console.warn("Viewer's FPS is too low:", fps);
};
performanceWatchdog.goodFrameRateCallback = function(viewer, fps) {
console.log("Viewer's FPS:", fps);
};
performanceWatchdog.lowFrameRateTrigger = 10;
performanceWatchdog.minimumFrameRateAfterWarmup = 20;
performanceWatchdog.samplingWindow = 60;
performanceWatchdog.warmupPeriod = 10;
performanceWatchdog.watchFrameRate();