#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
int fd = 0;
int fd1 = 0;
char buf[1024];
char buf1[1024];
int x1 = 0;
int x2 = 0;
int x3 = 0;
int x4 = 0;
int x5 = 0;
int main() {
int i;
int r=-1;
for (i=0; i<50000; i++) {
fd = open("/ora/app/oracle/product/8.1.7/rdbms/mesg/oraus.msb", o_rdonly);
fd1 = open("/ora/app/oracle/product/8.1.7/rdbms/mesg/oraus.msb_1", o_rdonly);
/* fprintf(stderr, "fd = %d fd1 = %d \n", fd, fd1);
*/
r = fcntl(fd, f_setfd);
lseek(fd, 0, seek_set);
read(fd, &buf, 256);
r = fcntl(fd1, f_setfd);
lseek(fd1, 0, seek_set);
read(fd1, &buf1, 256);
x1 = memcmp(&buf1, &buf, 256);
if (x1 != 0 ) {
fprintf(stderr, "x1 did not mach %d\n", x1);
}
lseek(fd, 512, seek_set);
read(fd, &buf, 512);
lseek(fd1, 512, seek_set);
read(fd1, &buf1, 512);
x2 = memcmp(&buf1, &buf, 512);
if (x2 != 0 ) {
fprintf(stderr, "x2 did not mach %d \n", x2);
}
lseek(fd, 1024, seek_set);
read(fd, &buf, 512);
lseek(fd1, 1024, seek_set);
read(fd1, &buf1, 512);
x3 = memcmp(&buf1, &buf, 512);
if (x3 != 0 ) {
fprintf(stderr, "x3 did not mach \n");
}
lseek(fd, 39936, seek_set);
read(fd, &buf, 512);
lseek(fd1, 39936, seek_set);
read(fd1, &buf1, 512);
x4 = memcmp(&buf1, &buf, 512);
if (x4 != 0 ) {
fprintf(stderr, "x4 did not mach \n");
}
close(fd);
close(fd1);
}
}
a7. test_v.sh
this is a wrapper for testing test_v.c.
#!/bin/bash export ld_preload=/usr/lib/cache_oraus.so export ld_preload=./cache_oraus.so time ./test_v
a8. c.sh
#!/bin/bash
path=/opt/sunwspro/bin/:$path
export path;
cc -fast -xarch=v8plusa -xdepend -xvector -xstrconst -xprefetch -g -o
cache_open_calls.so cache_open_calls.c -ldl
cc -fast -xdepend -xvector -xstrconst -xarch=v8plusa -xprefetch -g -o
cache_oraus.so cache_oraus.c -ldl
cc -fast -xstrconst -xvector -xdepend -xarch=v8plusa -xprefetch -o
test test.c -ldl
cc -fast -xstrconst -xvector -xdepend -xarch=v8plusa -xprefetch -o
test_v test_v.c -ldl
a9. c64.sh
#!/bin/bash
# changes to source cache_oraus.c for 64 bit support was made
# by ben humphreys
path=/opt/sunwspro/bin/:$path
export path;
cc -fast -xarch=v9a -xcode=abs64 -xdepend -xvector -xstrconst -xprefetch -g -o
cache_open_calls.so cache_open_calls.c -ldl
cc -fast -xarch=v9a -xcode=abs64 -xdepend -xvector -xstrconst -xprefetch -g -o
cache_oraus.so cache_oraus.c -ldl
cc -fast -xarch=v9a -xcode=abs64 -xstrconst -xvector -xdepend -xprefetch -o
test test.c -ldl
cc -fast -xarch=v9a -xcode=abs64 -xstrconst -xvector -xdepend -xprefetch -o
test_v test_v.c -ldl
< name=a10>
a10. cache_open_calls.c
/*
date: april 18, 02
author: nagendra nagarajayya
description: caches open, and close calls to oraus.msb file
*/
#include <stdio.h>
#include <unistd.h>
#include <dlfcn.h>
#include <string.h>
#include <stdlib.h>
static int k_bm_fd = -1;
int open(const char *path, int oflag, mode_t mode) {
static int (*fptr)() = 0;
if (fptr == 0) {
fptr = (int (*)())dlsym(rtld_next, "open");
if (fptr == null) {
fprintf(stderr, "dlopen: %s \n", dlerror());
return 0;
}
}
if (strcmp(path, "/oracle/app/oracle/product/8.1.7/rdbms/mesg/oraus.msb") == 0) {
if (k_bm_fd == -1) {
k_bm_fd = ((*fptr)(path, oflag, mode));
if (k_bm_fd <= 0) {
perror(path);
exit(1);
}
/* fstat(k_bm_fd, &k_bm_stat_buf);
fprintf(stderr, "open the file %d\n",k_bm_fd);
*/
return k_bm_fd;
} else {
/* fprintf(stderr, "re-open the file %d\n",k_bm_fd);
*/
return k_bm_fd;
}
}
return ((*fptr)(path, oflag, mode));
}
int close(int fildes) {
static int (*fptr)() = 0;
if (fptr == 0) {
fptr = (int (*)())dlsym(rtld_next, "close");
if (fptr == null) {
fprintf(stderr, "dlopen: %s \n", dlerror());
return 0;
}
}
if (fildes == k_bm_fd) {
/* fprintf(stderr, "close the file %d\n",k_bm_fd);
*/
return 0;
}
return ((*fptr)(fildes));
}
about the author
nagendra nagarajayya has been at sun for more than 9 years. a staff engineer in market development engineering (mde/ipe), he works with telco isvs on architecture, performance tuning, sizing and scaling, benchmarking, porting, and so on. his interests include multithreading, concurrency and parallelism, ha, distributed computing, networking, and the java and solaris platforms.