Building a performance static analyser


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Building a performance static analyser
# 1  
Old 06-16-2010
Building a performance static analyser

I was wondering if someone could let me know if tools exist that check for performance degrading coding practices. There is of course the well known Valgrind (Valgrind Home), but the question is more if it is possible at a fundamental level. Do generic test cases exist for checking statically for coding practices that hamper performance for when the program is run?
# 2  
Old 06-16-2010
Unless you mean you have a list of very specific bad practices for it to check for, it is difficult for an algorithm to deduce the intent of a program well enough to see whether it's a good or poor solution to the problem, except at very small scopes.

To a certain degree that's what an optimizing compiler does; taking a close look at what's been optimized where might be illuminating if your compiler can be convinced to be sufficiently spammy.

Tracing your program's system and library calls would also be a place to start. What does the program spend most of its time doing? Does it really need to be waiting when it is? Is it doing I/O efficiently? Is it polling when it could be using a blocking call instead? Is it doing inexplicable repetitive things? Is it calling malloc way more often than a sane program would need to? etc. etc.
# 3  
Old 06-16-2010
Thank you for your answer. Some more guidelines to consider:
1- Static code analysers already check code for bad practices. That is of course not to say that resolving those issues would lead to a better performing program.
2- Recursion is usually a good place to start looking for performance issues.
3- The creation of very large arrays is usually a sign of poor performance, because most of the time only a small portion is needed.
4- Repeated use of input validation. You can never be truly sure the data that the program is operating on is sufficiently sane, so there is a risk trade off between performance and data sanity.

Implementing performance measures always has the downside of micro-optimisation, so that the measures work in only one set up or on a specific data set.

Any more ideas are welcome.
# 4  
Old 06-16-2010
Another approach is to use a profiler:
gcc example
Code:
gcc -p -p -o myprog myprog.c
./myprog [argument1..argument2]
grpof myprog

gprof produces all kinds of performance analysis information. This is not static, like you wanted for the reasons corona describes above - it is hard to tell what the intent of code is, but when code runs you can analyze it's effectiveness.
# 5  
Old 06-16-2010
The creation of large unused arrays is certainly a red flag for cargo cult programming (if I make this bigger, it stops crashing! All done.) but it doesn't seem to me much of a performance issue, unless it's significant enough to eat into swap.
# 6  
Old 06-16-2010
I hadn't heard of grpof before, but certainly worthwhile to put on the list.
Also, clang ("clang" C Language Family Frontend for LLVM) has a built in profiler.
Another issue I had given some thought is that I expect a static performance analyser to produce many false positives, or anyway alert on breaks that do not have a good alternative or actually meet good design practices from a functional standpoint. So such an analyser will unlikely be very robust on the input given.
# 7  
Old 06-16-2010
In my experience, static analysis tools aren't going to be able to get you much if you want to avoid performance bottlenecks. The tools already mentioned (and I'll add memusage to that list, to look for memory leaks) do a great job of showing you where your real performance bottlenecks are, which makes sense, since performance is a matter of both the code (known) and the input (often unknown).

However, code review by other programmers, peer programming, and general sets of best practices for coding can be of great use here.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. OS X (Apple)

Text mode AF spectrum analyser.

Well guys, this MUST be a first. This is DEMO code only and has NO error detection or correction, nor out of bounds checking. I have succumbed to Python and scipy to do the FFT heavy lifting as I have absolutely no idea where to start do such a thing using AWK. This is a taster for me to... (7 Replies)
Discussion started by: wisecracker
7 Replies

2. Infrastructure Monitoring

Awstats webserver analyser

Need assistance in troubleshooting I have configured awstats 7.3 version on RedHat linux and I am stuck at getting the updates from the website . Please let me know if anybody can give me some inputs I can see the webpages but it gives "Never updated (See 'Build/Update' on awstats_setup.html... (2 Replies)
Discussion started by: ajayram_arya
2 Replies

3. Programming

Even the Static cURL Library Isn't Static

I'm writing a program which uses curl to be run on Linux PCs which will be used by a number of different users. I cannot make the users all install curl on their individual machines, so I have tried to link curl in statically, rather than using libcurl.so. I downloaded the source and created a... (8 Replies)
Discussion started by: BrandonShw
8 Replies

4. IP Networking

I need HELP to Set up Coyote Linux router with 1 static IP & 64 internal static IP

hello, i need help on setting my coyote linux, i've working on this for last 5 days, can't get it to work. I've been posting this message to coyote forum, and other linux forum, but haven't get any answer yet. Hope someone here can help me...... please see my attached picture first. ... (0 Replies)
Discussion started by: dlwoaud
0 Replies

5. Shell Programming and Scripting

How to change a Makefile from building static library to shared library?

Hi: I have a library that it only offers Makefile for building static library. It built libxxx.a file. How do I in any way build a shared library? (either changin the Makefile or direct script or command to build shared library) Thanks. (1 Reply)
Discussion started by: cpthk
1 Replies
Login or Register to Ask a Question