Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 222 Systems Programming Time, Errors, and File Access Dr. Jim Holten.

Similar presentations


Presentation on theme: "CSE 222 Systems Programming Time, Errors, and File Access Dr. Jim Holten."— Presentation transcript:

1 CSE 222 Systems Programming Time, Errors, and File Access Dr. Jim Holten

2 CSE 222 2 01/21/09 Performance Measuring Timing Program Activities Time Measurement Resolution Improving Accuracy Activity Types to Time

3 Measuring Time Offset Grab start time Run activity Grab end time Get difference

4 Grab Wallclock Time time(2) -- seconds since epoch gettimeofday(2) -- returns timeval structure –tv_sec -- seconds since epoch –tv_usec -- microseconds after last second times(2), clock(2) for user/system times

5 How? Look at the man pages Need header files –#include for time(2) –#include for gettimeofday(2) Other times are more complex

6 Resolution and Accuracy Resolution of timer clocks Variability in concurrent system activities Fast activities may be repeated many times, then get the averaged Longer activities may be repeated several times, then use the minimum

7 What do you time? Code algorithms File I/O delays Communications delays

8 UNIX Errors (1) system calls return null instead of a pointer, or -1 instead of an nonnegative integer errno(3) -- the error for that system call, it is NOT set if there is no error (retains any old errno value) strerror(3) -- the standard explanatory string for the errno.

9 UNIX Errors (2) #include to access errno #include to access strerror Note the possible errors for each system call as listed in the system call's man page!

10 Stream File Access fopen(3), freopen(3), fclose(3) fprintf(3), fscanf(3) (formatted string I/O) fgets(3), fputs(3), fgetc(3), fputc(3) All use pointers to FILE for the stream #include

11 fopen(), freopen() Parameters A string for the file path, absolute or relative to the current working directory A string of access mode characters –r, r+ –w, w+ –a, a+

12 Descriptor File Access open(2), creat(2), close(2) read(2), write(2) A file descriptor is an "int" #include

13 open() Parameters file path string open flags (OR'ed together) –O_CREAT, O_EXCL, O_TRUNC, O_APPEND mode -- combined with umask for new file permissions (mode & !umask)

14 Useful Calls fdopen(3) -- file descriptor to FILE pointer fileno(3) -- FILE pointer to its file descriptor feof(3) -- returns nonzero if eof was found fcntl(2) -- control behavior for file descriptor stat(2), fstat(2), and lstat(2)

15 More Useful Calls chmod(2) – change permissions on file chown(2) – change file ownership and group unlink(2) – delete a file mkdir(2), rmdir(2), chdir(2), getcwd(3)

16 Assignment MP2 (1) Write a C program to time how long it takes to fopen(), fgets() once, and fclose() 100 files, printing out the total time in seconds, and compute and print the average time in milliseconds. Then repeat using only the first (0) file, accessing it 100 times.

17 Assignment MP2 (2) Then access file "MP2_Problem", detecting all the possible errors for fopen(), fgets(), and fclose(), printing the error string and errno for any errors found, but continuing to the next operation even if the current operation fails. The files are all in "~jholten/cs222_files/"

18 Assignment MP2 (3) Include the UG and Journal. Include a single output file with the results of the three tests concatenated into the file. Include all source code.


Download ppt "CSE 222 Systems Programming Time, Errors, and File Access Dr. Jim Holten."

Similar presentations


Ads by Google