CS 127 Final Project, Spring 1997

Due 5:00 PM, Wednesday, 6/11/97

What to hand in

By 5:00 Wednesday, June 11, submitted using HSP. The items of documentation listed below should be included in a single text file, and can be brief.

Grading Criteria

Project Option #1: C Profiler

A profiler is a program that collects data for you about the run-time behavior of your programs. For example, a "line-count" profiler will print out your source code with a count of the number of times each line of code was executed during a run of the program. Other profilers print out the total time consumed by the running of various portions of your program.

Profilers are most frequently used to help programmers improve their programs' performance. By first finding out what portions of your code get executed most frequently and for the longest total time, you can concentrate your fine-tuning efforts where they will have the greatest effect. It also turns out that profilers can help in tracking down tricky bugs. You can find an interesting discussion of profilers in More Programming Pearls, Confessions of a Coder, by Jon Bentley, Addison-Wesley 1988.

For this project, your job is to write a program that will take C source code as input, and produce C source code as output. The output source, when compiled and run, will perform its expected task, but will also dump profiling information to a file.

Your profiler should report the number of times each of your functions (including main()) gets called, and the total time consumed by each function.

If you get your timing and function-call-counting done, you might try to implement line-count profiling.

You could also modify your timing reports to take into account the fact that functions call other functions. For example, suppose main() calls bigfunction(), which in turn calls littlefunction(), and none of them calls any other functions. If the entire program takes 2 seconds to run and bigfunction() takes 1.5 seconds to run, and littlefunction() takes .2 seconds to run, you could report:


main:  2 s
bigfunction: 1.5 s
littlefunction: .2 s
On the other hand, it might be more useful to report

main:  .5 s
bigfunction: 1.3 s
littlefunction: .2 s
This way, you are reporting the time each function spends running, not including the time the functions it calls take to run. The total run-time of the program will thus be the sum of the run-times of the separate functions.

Project Option #2: C Style Enforcer

For this option, you will write a program that takes a C source file as input, and fixes its style. For example, if the input source looks like this:

#include


void main   (void){
int         i;
for(i=0;i<10;i++) printf("Hello\n");}
the output might look like this:

#include     

void main( void )
{
    int     i;

    for( i=0; i < 10; i++ )
        printf( "Hello\n" );
}
The most important style points you should concentrate on are indentation and placement of braces.

Once you have indentation and bracing working well, some other style elements you could work on include spacing within for, while, and if statements, spacing in parameter lists in function headers and function calls, consistent spacing in assignment and arithmetic statements, blank lines placed after local variable declarations, etc.

If you have time and inclination, you could have your program offer the user multiple styles. For example, the bracing convention I use:


    if( this == that )
    {
        dosomething();
    }
is different from Kernighan and Ritchie's

    if( this == that ){
        dosomething();
    }




Jeff Ondich, Department of Mathematics and Computer Science, Carleton College, Northfield, MN 55057
(507) 646-4364, jondich@carleton.edu