如何从HAR文件中获取总页面响应时间? [英] How to get total web page response time from a HAR file?

查看:251
本文介绍了如何从HAR文件中获取总页面响应时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下图中,我想要来自网页的总响应时间。我似乎无法在文件显示的时间不同,因为它们分开根据两个请求之间经过的时间将请求分成不同的阶段。然后,他们计算从每个阶段的第一个请求到最后一个请求的时间跨度,并总结那些时间跨度。


In the following image, I want the total response time from the webpage. I can't seem to find it in the file sample HAR file, i.e. 38.79s in this case. Does anyone know how to get this?

I am going to use Selenium along with Firebug and NetExport to export the HAR file, but right now I am trying to do it manually. Adding the individual responses does not give correct numbers.

At some point I would like a Java program to find and extract the total response time.

解决方案

The total load time is not calculated by summarizing all request times but by the latest request end time. Graphically spoken it is the right end of the request bar ending at the far right. In your example screenshot it's either the last, third to last or fourth to last request.

The request end time is calculated by the request start time indicated by the startedDateTime property of a request plus the time span needed for the response, which is available through the time property of each request. To get the maximum request end time, you need to loop over all requests and compare the end time of each request. See the following code:

var startTime = new Date(har.log.pages[0].startedDateTime);
var loadTime = 0;

// Loop over all entries to determine the latest request end time
// The variable 'har' contains the JSON of the HAR file
har.log.entries.forEach(function(entry) {
  var entryLoadTime = new Date(entry.startedDateTime);
  // Calculate the current request's end time by adding the time it needed to load to its start time
  entryLoadTime.setMilliseconds(entryLoadTime.getMilliseconds() + entry.time);
  // If the current request's end time is greater than the current latest request end time, then save it as new latest request end time
  if (entryLoadTime > loadTime) {
    loadTime = entryLoadTime;
  }
});

var loadTimeSpan = loadTime - startTime;

Executing this code the variable loadTimeSpan will contain the wanted time span in milliseconds.

Important note:

The so calculated time span may still differ from the time displayed by Firebug or the online HAR Viewer, because they split the requests into different phases depending on the time elapsed between two requests. They then calculate the time span from the first to the last request of each phase and summarize those time spans in the end.

这篇关于如何从HAR文件中获取总页面响应时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆