This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-client-js.git

commit 50cff057398bd3dee4697eb50decf7d85cf758b6
Author: Qiuxia Fan <[email protected]>
AuthorDate: Mon Apr 13 17:32:25 2020 +0800

    fix: update perfDetail
---
 src/performance/index.ts | 28 +++++++++++++++-------------
 src/performance/perf.ts  | 14 ++++++++------
 2 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/src/performance/index.ts b/src/performance/index.ts
index 5723398..65e0bb6 100644
--- a/src/performance/index.ts
+++ b/src/performance/index.ts
@@ -23,21 +23,23 @@ import pagePerf from './perf';
 class TracePerf {
   private isPerf: boolean = true;
   private perfConfig = {
-    resources: [],
+    // resources: [],
     perfDetail: {},
   } as any;
 
-  public async recordPerf(options: CustomPerfOptionsType) {
-    if (this.isPerf) {
-      this.perfConfig.performance = await pagePerf.getPerfTiming();
-    }
-    const perfInfo = {
-      perfDetail: this.perfConfig.perfDetail,
-      resources: this.perfConfig.resources,
-      ...options,
-    };
-    new Report(options.reportUrl).sendByXhr(perfInfo);
-    this.clearPerf();
+  public recordPerf(options: CustomPerfOptionsType) {
+    setTimeout(async () => {
+      if (this.isPerf) {
+        this.perfConfig.perfDetail = await pagePerf.getPerfTiming();
+      }
+      const perfInfo = {
+        perfDetail: this.perfConfig.perfDetail,
+        // resources: this.perfConfig.resources,
+        ...options,
+      };
+      new Report(options.reportUrl).sendByXhr(perfInfo);
+      this.clearPerf();
+    }, 100);
   }
 
   private clearPerf() {
@@ -46,7 +48,7 @@ class TracePerf {
     }
     window.performance.clearResourceTimings();
     this.perfConfig = {
-      resources: [],
+      // resources: [],
       perfDetail: {},
     };
   }
diff --git a/src/performance/perf.ts b/src/performance/perf.ts
index 0a2f73e..5943e8b 100644
--- a/src/performance/perf.ts
+++ b/src/performance/perf.ts
@@ -26,26 +26,28 @@ class PagePerf {
       }
       const { timing } = window.performance;
       const loadTime = timing.loadEventEnd - timing.loadEventStart;
+      const navigationStart = timing.navigationStart;
+
       if (loadTime < 0) {
         setTimeout(() => {
           this.getPerfTiming();
         }, 300);
         return;
       }
-      const perfTime = {
+
+      return {
         redirectTime: timing.redirectEnd - timing.redirectStart,
         dnsTime: timing.domainLookupEnd - timing.domainLookupStart,
-        ttfbTime: timing.responseStart - timing.navigationStart,
+        ttfbTime: timing.responseStart - navigationStart,
         appcacheTime: timing.domainLookupStart - timing.fetchStart,
         unloadTime: timing.unloadEventEnd - timing.unloadEventStart,
         tcpTime: timing.connectEnd - timing.connectStart,
         reqTime: timing.responseEnd - timing.responseStart,
         analysisTime: timing.domComplete - timing.domInteractive,
-        blankTime: timing.domLoading - timing.navigationStart,
-        domReadyTime: timing.domContentLoadedEventEnd - timing.navigationStart,
-        loadPage: timing.loadEventEnd - timing.navigationStart,
+        blankTime: timing.domLoading - navigationStart,
+        domReadyTime: timing.domContentLoadedEventEnd - navigationStart,
+        loadPage: timing.loadEventEnd - navigationStart,
       };
-      return perfTime;
     } catch (e) {
       throw e;
     }

Reply via email to