WebPagetest网页前端性能测试工具和实现分析

简介: WebPageTest 原本是由AOL开发内部使用的工具,后来在Google Code上开源, 是一款非常优秀的网页前端性能测试工具。 在线版本http://www.webpagetest.orgGoogle Code: http://code.

WebPageTest 原本是由AOL开发内部使用的工具,后来在Google Code上开源, 是一款非常优秀的网页前端性能测试工具。 在线版本http://www.webpagetest.org

Google Code: http://code.google.com/p/webpagetest/

部署WebPageTest 私有实例参考资料

http://testing.etao.com/node/303

http://testing.etao.com/node 

如下是作者提供的客户端实现分析  

the networking stack on Windows from a browser’s perspective

wps_clip_image-28040

Function Interception

The key to how WebPagetest works is its ability to intercept arbitrary function calls

and inspect or alter the request or response before passing it on to the original imple-mentation (or choosing not to pass it on at all). Luckily someone else did most of the

heavy lifting and provided a nice open source library (http://newgre.net/ncodehook) that

can take care of the details for you but it basically works like this:

• Find the target function in memory (trivial if it is exported from a dll).

• Copy the first several bytes from the function (making sure to keep x86 instructions

intact).

• Overwrite the function entry with a jmp to the new function.

• Provide a replacement function that includes the bytes copied from the original

function along with a jmp to the remaining code.

It’s pretty hairy stuff and things tend to go very wrong if you aren’t extremely careful,

but with well-defined functions (like all of the Windows APIs), you can pretty much

intercept anything you’d like.

One catch is that you can only redirect calls to code running in the same process as the

original function, which is fine if you wrote the code but doesn’t help a lot if you are

trying to spy on software that you don’t control which leads us to…

Code Injection

Lucky for me, Windows provides several ways to inject arbitrary code into processes.

There is a good overview of several different techniques here: http://www.codeproject

.com/KB/threads/winspy.aspx, and there are actually more ways to do it than that but

it covers the basics. Some of the techniques insert your code into every process but I

wanted to be a lot more targeted and just instrument the specific browser instances

that we are interested in, so after a bunch of experimentation (and horrible failures), I

ended up using the CreateRemoteThread/LoadLibrary technique which essentially lets

you force any process to load an arbitrary dll and execute code in it (assuming you have

the necessary rights).

Resulting Browser Architecture

wps_clip_image-8319

Get the Code

Since WebPagetest is under a BSD license you are welcome to reuse any of the code for

whatever purposes you’d like. The project lives on Google Code here: (http://code.goo

gle.com/p/webpagetest/) and some of the more interesting files are:

• Winsock  API  interception  code  (http://webpagetest.googlecode.com/svn/trunk/

agent/wpthook/hook_winsock.cc)

• Code injection (http://webpagetest.googlecode.com/svn/trunk/agent/wpthook/inject

.cc)

相关实践学习
通过性能测试PTS对云服务器ECS进行规格选择与性能压测
本文为您介绍如何利用性能测试PTS对云服务器ECS进行规格选择与性能压测。
相关文章
|
15天前
|
Web App开发 安全 测试技术
网页测试
【4月更文挑战第8天】网页测试
24 1
|
1月前
|
XML 前端开发 JavaScript
AJAX 前端开发利器:实现网页动态更新的核心技术
**AJAX** 允许网页在不刷新的情况下更新内容,实现异步与服务器交换数据。通过JavaScript的XMLHttpRequest对象,可发送和接收数据。当用户触发事件(如点击),函数向服务器发送GET请求,服务器响应后更新指定HTML部分。AJAX并非编程语言,而是利用浏览器内置对象、JavaScript和DOM技术。核心是XMLHttpRequest对象,它有多种方法(如`open()`和`send()`)和属性(如`onreadystatechange`、`readyState`和`status`)来处理请求和响应。
54 2
AJAX 前端开发利器:实现网页动态更新的核心技术
|
1月前
|
前端开发
web前端---------网页中的选项
web前端---------网页中的选项
21 0
|
1月前
|
前端开发 数据安全/隐私保护
web前端----------网页中的输入框
web前端----------网页中的输入框
22 0
|
1月前
|
前端开发
Web前端开发------网页分组元素
Web前端开发------网页分组元素
23 0
|
1月前
|
jenkins 测试技术 持续交付
提升软件测试效率与准确性的策略分析
【2月更文挑战第28天】 在快速迭代的软件发展周期中,高效的测试流程是确保产品质量和用户满意度的关键。本文旨在探讨提高软件测试效率和准确性的策略,包括自动化测试工具的选择、测试用例的优化设计以及持续集成的实践。通过分析当前软件测试领域面临的挑战,提出了相应的解决方案,并通过案例分析来展示这些策略的实际应用效果。文章的目的是为软件测试工程师提供实用的指导和参考,帮助他们在保证测试质量的同时,缩短测试周期,降低成本。
40 1
|
2月前
|
人工智能 前端开发 搜索推荐
前端技术发展趋势分析与展望
【2月更文挑战第9天】 随着移动互联网的快速发展,前端技术在不断演进,从最初的HTML、CSS到如今的React、Vue等前端框架,技术发展日新月异。本文将从移动端、跨平台、人工智能等多个角度分析前端技术的发展趋势,并展望未来的发展方向。
|
5天前
R语言估计多元标记的潜过程混合效应模型(lcmm)分析心理测试的认知过程
R语言估计多元标记的潜过程混合效应模型(lcmm)分析心理测试的认知过程
24 0
|
11天前
|
Web App开发 前端开发 Java
框架分析(11)-测试框架
框架分析(11)-测试框架
|
12天前
|
缓存 前端开发 JavaScript
如何优化前端网页加载速度:7个实用技巧
在当今互联网时代,网页加载速度对用户体验至关重要。本文将介绍7个实用的技巧,帮助前端开发者优化网页加载速度,提升用户体验。从压缩资源到异步加载,从图片优化到缓存策略,这些技巧将帮助你在前端开发中取得更好的效果。