博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WebPagetest网页前端性能测试工具和实现分析
阅读量:6686 次
发布时间:2019-06-25

本文共 2654 字,大约阅读时间需要 8 分钟。

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

Google Code: 

部署WebPageTest 私有实例参考资料

 

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

the networking stack on Windows from a browser’s perspective

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

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)

转载地址:http://trqao.baihongyu.com/

你可能感兴趣的文章
[Android Pro] Android权限设置android.permission完整列表
查看>>
headfirst设计模式(6)—单例模式
查看>>
地图坐标服务
查看>>
focus()无效问题
查看>>
python ConfigParser 学习
查看>>
JS 判断中英文字符长度
查看>>
小程序模板
查看>>
raw deferreds vs deferredGenerator vs inlineCallbacks
查看>>
Python中四种样式的99乘法表
查看>>
对于快速排序算法的递归栈深度的一点改进
查看>>
模拟锁定文件
查看>>
矩阵乘法2(codevs3147)
查看>>
如何修复Kindle频繁自动锁屏和解锁
查看>>
Sicily 4190. Prime Palindromes 解题报告
查看>>
MongoDB在Windows下安装配置
查看>>
CAFFE安装(3):cuDNN v4
查看>>
hdu 1016 Prime Ring Problem
查看>>
Spring+SpringMVC+MyBatis深入学习及搭建(一)——MyBatis的基础知识
查看>>
如何把写好的文件放到提供的地址上提交代码
查看>>
mysql 导入
查看>>