in Education by
Have you found such a tool and used it successfully? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
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*$', 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.

Related questions

0 votes
    Have you found such a tool and used it successfully? JavaScript questions and answers, JavaScript questions pdf ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 29, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    I want to check whether the color = a certain color then appropriately react. This is done in flash ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    The profiler can be turned off by passing _________ to Rprof(). (a) 0 (b) 1 (c) 2 (d) NULL The ... and Data Analysis of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Which of the below is not a Java Profiler? (a) JVM (b) JConsole (c) JProfiler (d) Eclipse ... java programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    Which of the following statements is/are not true for SQL profiler? (a) Enables you to monitor events ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Which of the following statements is/are not true for SQL profiler? (a) Enables you to monitor events ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Choose the operations that can be captured by database profiler? (1)Read operations (2)Write operations (3)Cursor Operations (4)All the Options...
asked May 22, 2021 in Technology by JackTerrance
0 votes
+1 vote
    Choose the operations that can be captured by database profiler? (1)Read operations (2)Write operations (3)Cursor Operations (4)All the Options...
asked Oct 13, 2020 in Technology by JackTerrance
0 votes
    _____ is a small, portable flash memory card that plugs into a computer’s USB port and functions as a portable hard drive ? 1. Flash drive 2. CD-RW 3. DVD-ROM 4. CD-ROM...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
...