Reference no: EM132528298
ENGR9881 Computer Networks - Flinders University
Monitoring
Demonstrate the design and implementation of simple process and network level programs
Task 1 Write a program that calculates and prints the elapsed time of a loop to an accuracy of microseconds.
1. Use the structure timeval to store times form the following C header file;
#include <sys/time.h>
3. In a loop that executes 100 times
• Use gettimeofday() to get the time
• Iterate through a loop 1,000,000 times
• Use gettimeofday() to get the clasped time
4. Calculate and print the time taken in microseconds for each loop and entire program execution
Task 2
Write a program that uses the function getopt() to parse command line options, print provided options.
1. Call a function usage() if there are no command line arguments
2. With in a suitable loop (refer to the getopt man page for example code
1. Use getopt() to parse the command line options
2. With in a switch/case statement
1. Process arguments and print each option and argument
2. In the switch control structure set the default case and ‘?' to call usage() if incorrect arguments are provided
void usage () {
printf("Usage: programname -f filename");
}
Task 3
Write a program that uses stat() to collect the metadata about a file and print out each of the fields, display all the relevant time and/or date related fields.
1. Use getopt() to provide a the command line argument of the file name
2. Use the following C header file; #include <sys/stat.h>
3. Use stat() and the structure in the stat man page to find the metadata about the provided file
4. Print each of the time related elements of the structure with the appropriate format and description;
struct stat {
dev_t st_dev; /* device inode resides on */
ino_t st_ino; /* inode's number */
mode_t st_mode; /* inode protection mode */
...
}
5. Using the above comments in the structure in the man page;
printf("device inode resides on: ‘%d'\n", file->st_dev);
...
6. How can the time stamp on files be used to determine performance and timing?
Task 4
Copy the source code for Part 1 and add DEBUG statements around the timing functionality to allow optional use of timing.
• Part 1
1. add a #define statement at the top of your code for DEBUG 1 for true and DEBUG 0 for false
2. Use an if statement to allow for conditional execution of the timing functions
3. Collect run time information in the shell with the command time, for each of DEBUG 1 and DEBUG 0
• Part 2
4. add a #define statement at the top of your code for DEBUG
5. Use an #ifdef and #endif statement to allow for conditional compilation and execution of the timing functions
6. Collect run time information in the shell with the command time, for each of DEBUG 1 and DEBUG 0
• Part 3
7. Is it possible to measure any difference between using the techniques in part 1 and part 2?
8. Is it possible to measure the difference in execution time with the command line time?
Attachment:- Computer Networks.rar