Flash / Actionscript CPU 分析器

发布于 2024-07-10 06:55:14 字数 23 浏览 8 评论 0原文

你找到这样的工具并成功使用了吗?

Have you found such a tool and used it successfully?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

七婞 2024-07-17 06:55:14

我也在寻找 AS 分析器,但我想要一个与 FlashDevelop 和 Flex SDK 配合使用的免费软件/开源解决方案。 我没有找到。 所以我写了一个简单的Python脚本和一个更简单的AS类。 该脚本本质上采用任何 AS 文件并添加分析代码(即调用以 1 毫秒的精度测量该函数的总运行时间 - flash.utils.getTimer() 调用的分辨率)每个函数的定义。 脚本有时会出现错误,但这些错误通常很容易手动修复。 然后,您需要手动再添加一行:在某个时刻转储分析统计信息。 这种方法显然远不准确,但它仍然可以让您很好地了解代码中的瓶颈。 我用它成功地处理了 100k 的文件。

这是 AS 类:

package  {
    public class Profiler {
        private static var instance:Profiler;

        public static function get profiler():Profiler {
            if (!Profiler.instance) Profiler.instance = new Profiler;
            return Profiler.instance;
        }

        private var data:Object = {};

        public function profile(fn:String, dur:int):void {
            if (!data.hasOwnProperty(fn)) data[fn] = new Number(0);
            data[fn] += dur / 1000.0;
        }

        public function clear():void {
            data = { };
        }

        public function get stats():String {
            var st:String = "";
            for (var fn:String in data) {
                st += fn + ":\t" + data[fn] + "\n";
            }
            return st;
        }
    }
}

这是执行此操作的 python 脚本:

import sre, sys

rePOI = sre.compile(r'''\bclass\b|\bfunction\b|\breturn\b|["'/{}]''')
reFun = sre.compile(r'\bfunction\b\s*((?:[gs]et\s+)?\w*)\s*\(')
reCls = sre.compile(r'class\s+(\w+)[\s{]')
reStr = sre.compile(r'''(["'/]).*?(?<!\\)\1''')

def addProfilingCalls(body):
    stack = []
    pos = 0
    depth = 0
    retvar = 0
    klass = ""
    match = rePOI.search(body, pos)
    while match:
        poi = match.group(0)
        pos = match.start(0)
        endpos = match.end(0)

        if poi in '''"'/''':
            strm = reStr.match(body, pos)
            if strm and (poi != '/' or sre.search('[=(,]\s*

随意使用、分发和修改两者。

, body[:pos])): endpos = strm.end(0) elif poi == 'class': klass = reCls.match(body, pos).group(1) sys.stderr.write('class ' + klass + '\n') elif poi == 'function': fname = reFun.match(body, pos) if fname.group(1): fname = klass + '.' + fname.group(1) else: lastf = stack[-1] lastf['anon'] += 1 fname = lastf['name'] + '.anon' + str(lastf['anon']) sys.stderr.write('function ' + fname + '\n') stack.append({'name':fname, 'depth':depth, 'anon':0}) brace = body.find('{', pos) + 1 line = "\nvar __start__:int = flash.utils.getTimer();" body = body[:brace] + line + body[brace:] depth += 1 endpos = brace + len(line) elif poi == '{': depth += 1 elif poi == 'return': lastf = stack[-1] semicolon = body.find(';', pos) + 1 if sre.match('return\s*;', body[pos:]): line = "{ Profiler.profiler.profile('" + lastf['name'] + \ "', flash.utils.getTimer() - __start__); return; }" else: retvar += 1 line = "{ var __ret" + str(retvar) + "__:* =" + body[pos+6:semicolon] + \ "\nProfiler.profiler.profile('" + lastf['name'] + \ "', flash.utils.getTimer() - __start__); return __ret" + str(retvar) + "__; }" body = body[:pos] + line + body[semicolon:] endpos = pos + len(line) elif poi == '}': depth -= 1 if len(stack) > 0 and stack[-1]['depth'] == depth: lastf = stack.pop() line = "Profiler.profiler.profile('" + lastf['name'] + \ "', flash.utils.getTimer() - __start__);\n" body = body[:pos] + line + body[pos:] endpos += len(line) pos = endpos match = rePOI.search(body, pos) return body def main(): if len(sys.argv) >= 2: inf = open(sys.argv[1], 'rU') else: inf = sys.stdin if len(sys.argv) >= 3: outf = open(sys.argv[2], 'wU') else: outf = sys.stdout outf.write(addProfilingCalls(inf.read())) inf.close() outf.close() if __name__ == "__main__": main()

随意使用、分发和修改两者。

I was also looking for a profiler for AS, but I wanted an freeware/open source solution that works with FlashDevelop and Flex SDK. I found none. So I wrote a simple python script and an even simpler AS class. The script essentially takes any AS file and adds profiling code (i.e. calls to measure the total runtime of that function with an accuracy of 1 ms - the resolution of the flash.utils.getTimer() call) to each function definition. The script sometimes makes mistakes, but these are usually easy to fix by hand. Then you need to add one more line manually: dump the profiling statistics somewhere at some point. This method is obviously far from accurate, but it nonetheless gives you good feel of bottlenecks in your code. I used it for a 100k file with success.

Here is the AS class:

package  {
    public class Profiler {
        private static var instance:Profiler;

        public static function get profiler():Profiler {
            if (!Profiler.instance) Profiler.instance = new Profiler;
            return Profiler.instance;
        }

        private var data:Object = {};

        public function profile(fn:String, dur:int):void {
            if (!data.hasOwnProperty(fn)) data[fn] = new Number(0);
            data[fn] += dur / 1000.0;
        }

        public function clear():void {
            data = { };
        }

        public function get stats():String {
            var st:String = "";
            for (var fn:String in data) {
                st += fn + ":\t" + data[fn] + "\n";
            }
            return st;
        }
    }
}

And here is the python script that does the trick:

import sre, sys

rePOI = sre.compile(r'''\bclass\b|\bfunction\b|\breturn\b|["'/{}]''')
reFun = sre.compile(r'\bfunction\b\s*((?:[gs]et\s+)?\w*)\s*\(')
reCls = sre.compile(r'class\s+(\w+)[\s{]')
reStr = sre.compile(r'''(["'/]).*?(?<!\\)\1''')

def addProfilingCalls(body):
    stack = []
    pos = 0
    depth = 0
    retvar = 0
    klass = ""
    match = rePOI.search(body, pos)
    while match:
        poi = match.group(0)
        pos = match.start(0)
        endpos = match.end(0)

        if poi in '''"'/''':
            strm = reStr.match(body, pos)
            if strm and (poi != '/' or sre.search('[=(,]\s*

Feel free to use, distribute and modify both.

, body[:pos])): endpos = strm.end(0) elif poi == 'class': klass = reCls.match(body, pos).group(1) sys.stderr.write('class ' + klass + '\n') elif poi == 'function': fname = reFun.match(body, pos) if fname.group(1): fname = klass + '.' + fname.group(1) else: lastf = stack[-1] lastf['anon'] += 1 fname = lastf['name'] + '.anon' + str(lastf['anon']) sys.stderr.write('function ' + fname + '\n') stack.append({'name':fname, 'depth':depth, 'anon':0}) brace = body.find('{', pos) + 1 line = "\nvar __start__:int = flash.utils.getTimer();" body = body[:brace] + line + body[brace:] depth += 1 endpos = brace + len(line) elif poi == '{': depth += 1 elif poi == 'return': lastf = stack[-1] semicolon = body.find(';', pos) + 1 if sre.match('return\s*;', body[pos:]): line = "{ Profiler.profiler.profile('" + lastf['name'] + \ "', flash.utils.getTimer() - __start__); return; }" else: retvar += 1 line = "{ var __ret" + str(retvar) + "__:* =" + body[pos+6:semicolon] + \ "\nProfiler.profiler.profile('" + lastf['name'] + \ "', flash.utils.getTimer() - __start__); return __ret" + str(retvar) + "__; }" body = body[:pos] + line + body[semicolon:] endpos = pos + len(line) elif poi == '}': depth -= 1 if len(stack) > 0 and stack[-1]['depth'] == depth: lastf = stack.pop() line = "Profiler.profiler.profile('" + lastf['name'] + \ "', flash.utils.getTimer() - __start__);\n" body = body[:pos] + line + body[pos:] endpos += len(line) pos = endpos match = rePOI.search(body, pos) return body def main(): if len(sys.argv) >= 2: inf = open(sys.argv[1], 'rU') else: inf = sys.stdin if len(sys.argv) >= 3: outf = open(sys.argv[2], 'wU') else: outf = sys.stdout outf.write(addProfilingCalls(inf.read())) inf.close() outf.close() if __name__ == "__main__": main()

Feel free to use, distribute and modify both.

清秋悲枫 2024-07-17 06:55:14

Adobe 最近发布了一款名为 Adob​​e Scout 的新 Flash 分析工具:

http://gaming.adobe.com/ Technologies/scout/

这是对旧版 Flash Builder 分析器的巨大改进 - 它为您提供了 CPU 时间的详细细分,包括 ActionScript 执行以及渲染和网络等内部播放器功能。

试用期免费 - 您只需注册一个免费的 Creative Cloud 帐户。 之后,将继续提供免费的基本版本,完整版本作为付费 Creative Cloud 帐户的一部分提供。

Adobe have recently released a new profiling tool for Flash called Adobe Scout:

http://gaming.adobe.com/technologies/scout/

It's a massive improvement on the old Flash Builder profiler - it gives you a detailed breakdown of CPU time, both for ActionScript execution, and internal player functions like rendering and networking.

It's free for a trial period - you just need to register for a free Creative Cloud account. After that, there will continue to be a free basic version, with the full version available as part of a paid Creative Cloud account.

鹿港巷口少年归 2024-07-17 06:55:14

值得注意的是,Flash Player 的实现在每个平台上以及在某种程度上每个浏览器上都不同,因此预计速度会有显着差异。 因此,如果您正在开发资源密集型应用程序,您应该使用特定于您目标的每个操作系统的分析工具,例如 OS X 上的工具,当然还要测试每个浏览器中的性能。

It's important to note that the Flash Player implementation is different on each platform and to an extent each browser, so expect notable speed differences. So if you're developing a resource intensive application you should be using profiling tools specific to each OS you're targeting, like for example Instruments on OS X and of course test the performance in each browser.

痴者 2024-07-17 06:55:14

我使用了 Flex Builder 3 附带的分析器,取得了一定的成功。 我发现它对于查找内存泄漏和/或 GC 问题特别有用。

由于相关应用程序的异步性质以及给予 [onEnterFrame] 和其他内部方法的时间量,它在方法时间性能方面对我来说没那么有用,尽管我仍然能够做出一些基于输出的优化。

I've used the profiler that comes with Flex Builder 3 with moderate success. I find out especially useful in finding memory leaks and or GC issues.

It was much less useful for me in the area of time-in-method performance due to the asynchronous nature of the application in question and the amount of time given to [onEnterFrame] and other internal methods, though I was still able to make some optimisations based on the output.

剪不断理还乱 2024-07-17 06:55:14

我不久前写了一个基于flasm的flash分析器(http://snow.prohosting.com/ bensch/flasp.html)您需要使用flasm插入分析asm,然后运行程序。

另一种(也许)更好的方法是使用 David Chang 的分析代码,它根本不需要 flasm。 www.nochump.com/asprof/

干杯

I wrote a flash profiler based on flasm a while ago (http://snow.prohosting.com/bensch/flasp.html) You need to use flasm to insert the profiling asm and then run the program.

Another (maybe) better way is to use David Chang's profiling code which doesn't require flasm at all. www.nochump.com/asprof/

cheers

白色秋天 2024-07-17 06:55:14

这是我个人最喜欢的。
请注意,它是基于 java 且开源的。
http://github.com/bengarney/PBLabsProfiler

它使用 flash/flex 编译器的未记录功能。
Flash Builder 内置探查器使用相同的内容。
是的! 我已经成功地使用它来优化我的一些 Flash 代码。

This one is my personal favorite.
Note that it's built on java and open source.
http://github.com/bengarney/PBLabsProfiler

It uses undocumented features of flash/flex compiler.
The same ones Flash Builder built-in profiler uses.
And yes! I have successfully used it to optimize some of my flash code.

一抹淡然 2024-07-17 06:55:14

Flex Builder 3 包含性能和内存分析器。 我没用过,但看起来很时髦。 我不确定它是否可以用于非 Flex 内容,但它肯定只适用于 AS3。

除此之外,多年来我发现了一些用于一定级别的分析的可行方法。 最简单的是,您显然可以构建一个 FPS 仪表并观察其行为。 有关代码密集型应用程序的更多信息,我所做的一件事是创建一个简单的框架,用于在方法的开头和结尾进行 getTimer() 调用并跟踪累积时间,但我'我从未为此使用过任何预制工具。 在实践中,对于代码量大的工作来说,瓶颈通常是非常明显的,在这些情况下,我只是将计时器直接放在我想要优化的地方。

当瓶颈出现在渲染中时,首先要尝试的就是简单地以目标 FPS 进行发布,并使用 FPS 仪表来跟踪实际播放何时低于该值(在目标硬件上)。 例如,您可以通过调用 refreshAfterUpdate 调用 1ms 超时并监视刷新之间的实际时间来获取有关渲染的更多详细信息。 不幸的是,您无法获得比“每次刷新”更精细的信息 - 您无法直接看到光栅化、合成等花费了多少时间(尽管您经常可以推断出这些事情。例如,您可以启用位图缓存在矢量密集的对象上取消光栅化,并观察结果。)

Flex Builder 3 includes a performance and memory profiler. I haven't used it, but it looks pretty snazzy. I'm not sure if it can be used for non-Flex content, but it will definitely only work for AS3.

Apart from that, over the years I've found a couple of workable methods for a certain level of profiling. At the simplest you can obviously just build an FPS meter and watch how it behaves. For more info about code-heavy applications one thing I've done is to whip up a simple framework for making getTimer() calls at the beginning and end of methods and tracking the cumulative time, but I've never used any pre-made tools for that. In practice it's usually pretty obvious where the bottlenecks are for code-heavy work, and in those cases I just put timer directly around what I'm trying to optimize.

When the bottlenecks are in rendering, the first thing to try is to simply publish at your target FPS, and use an FPS meter to track when actual playback falls below that (on target hardware). You can get more detailed information about rendering by, for example, invoking a 1ms timeout that calls refreshAfterUpdate, and monitoring the actual time between refreshes. Unfortunately you can't get any more granular than "per refresh" though - you can't directly see how much time is spent rasterizing, compositing, etc. (Though you can often infer these things. For example, you can enable bitmap caching on vector-heavy objects to take rasterization off the table, and observe the results.)

野稚 2024-07-17 06:55:14

我发现 The Miner 非常有用,而且对于非商业项目来说是免费的。 它具有广泛的功能,但标有“性能分析器”的选项卡是最有帮助的。 我发现这是查找代码中瓶颈的好方法,或者至少知道主要原因是什么(渲染、文本、网络等)。

我花了一些时间才找到安装说明,但它非常简单。 将 .swc 文件包含在您的项目中,然后在文档类构造函数中添加 1 行代码。

this.addChild(new TheMiner(true));

更多信息:http://www.sociodox.com/theminer/support.html

I have found The Miner to be very useful, and it's free for non-commercial projects. It has a wide range of features but the tab labelled "Performance Profiler" has been the most helpful. I find that it's a great way to find bottlenecks in your code, or at least know what the main cause is (Rendering, Text, Network, etc..).

It took me a bit to find the installation instructions, but it's pretty simple. Include the .swc file in your project, then add 1 line of code in your document class constructor.

this.addChild(new TheMiner(true));

More info: http://www.sociodox.com/theminer/support.html

唠甜嗑 2024-07-17 06:55:14

有一个FlashPreloaderProfiler:
http://jpauclair.net/flashpreloadprofiler

它是用 ActionScript 编写的,不需要在背景并具有更多功能,例如内存分析器。

但我也更喜欢 PBLabsProfiler :)

There is a FlashPreloaderProfiler:
http://jpauclair.net/flashpreloadprofiler

It's written in actionscript, doesn't need a java-application running in the background and have some more features like Memory Profiler.

But I prefer PBLabsProfiler too :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文