Initial revision

This commit is contained in:
Doug MacEachern committed 2004-06-21 22:37:04 +00:00
1 parent 1a7957fb1e
commit dffe0da855
207 files changed
+34390

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
this directory contains some experiments that are not in the codebase yet.
may or may not move forward, but would prefer not to loose these stuffs.
+24
View File
@@ -0,0 +1,24 @@
#include <stdio.h>
#include <kstat.h>
/* gcc -lkstat -o dump_kstats dump_kstats.c */
static const char *kstat_type_names[] = {
"raw", "named", "intr", "io", "timer"
};
int main(int argc, char **argv) {
kstat_ctl_t *kc = kstat_open();
kstat_t *kp;
for (kp = kc->kc_chain; kp != 0; kp = kp->ks_next) {
if (strncmp(kp->ks_name, "kstat_", 6) == 0) {
continue;
}
fprintf(stdout, "%-5s %s\n",
kstat_type_names[kp->ks_type],
kp->ks_name);
}
kstat_close(kc);
}
+211
View File
@@ -0,0 +1,211 @@
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
/*
* eam can provide per-process measurements, but at the moment requires
* a pid. something we cannot store in the database. however, we could
* store a service port in the database (e.g. 8009 for tomcat ajp) and
* figure out the pid given that.
*
* it is possible via /proc/net/tcp and /proc/$pid/fd/
* to map a tcp port to one (or more if forked) process id(s).
* caveats: expensive to scan /proc/$pid/fd
* must own process or be root to read /proc/$pid/fd
* brutal to provide similar functionality on other platforms,
* tho possible (see lsof).
*/
static char *sigar_skip_token(char *p)
{
while (isspace(*p)) p++;
while (*p && !isspace(*p)) p++;
return p;
}
static char *sigar_skip_multiple_token(char *p, int count)
{
int i;
for (i = 0; i < count; i++) {
p = sigar_skip_token(p);
}
return p;
}
static int get_process_ppid(char *pid, char *buf, int buflen)
{
FILE *fp;
char buffer[1024], *ptr, *ptr2;
sprintf(buffer, "/proc/%s/stat", pid);
if (!(fp = fopen(buffer, "r"))) {
return errno;
}
ptr = fgets(buffer, sizeof(buffer), fp);
fclose(fp);
ptr = sigar_skip_multiple_token(ptr, 3);
while (isspace(*ptr)) {
++ptr;
}
ptr2 = strchr(ptr, ' ');
*ptr2 = '\0';
strncpy(buf, ptr2, buflen);
buf[buflen] = '\0';
return 0;
}
typedef struct {
int port;
int inode;
int uid;
int pid;
char name[1024];
} portmap_t;
static int portmap_lookup_inode(portmap_t *map) {
FILE *fp;
char buffer[8192], *ptr;
int inode = 0;
if ((fp = fopen("/proc/net/tcp", "r")) < 0) {
return -1;
}
fgets(buffer, sizeof(buffer), fp); /* skip header */
while ((ptr = fgets(buffer, sizeof(buffer), fp))) {
ptr = sigar_skip_token(ptr);
if ((ptr = strchr(ptr, ':'))) {
unsigned long port = strtoul(++ptr, &ptr, 16);
if (!(map->port == (port & 0xffff))) {
continue;
}
}
ptr = sigar_skip_multiple_token(ptr, 5);
map->uid = strtoul(ptr, &ptr, 10);
ptr = sigar_skip_token(ptr);
inode = map->inode = strtoul(ptr, &ptr, 10);
break;
}
fclose(fp);
return inode ? 0 : ENOENT;
}
static int portmap_lookup_pid(portmap_t *map, char *pid) {
DIR *dirp;
struct dirent *dp;
char fname[1024], dname[1024];
map->pid = -1;
sprintf(dname, "/proc/%s/fd", pid);
if (!(dirp = opendir(dname))) {
return errno;
}
while ((dp = readdir(dirp))) {
struct stat statbuf;
if (!isdigit(*dp->d_name)) {
continue;
}
sprintf(fname, "%s/%s", dname, dp->d_name);
//printf("check %s\n", fname);
if (stat(fname, &statbuf)) {
continue;
}
if (statbuf.st_ino == map->inode) {
map->pid = atoi(pid);
break;
}
}
closedir(dirp);
return map->pid == -1 ? ENOENT : 0;
}
static int portmap_lookup_pid_scan(portmap_t *map) {
DIR *dirp;
struct dirent *dp;
char dname[1024];
if (!(dirp = opendir("/proc"))) {
return -1;
}
map->pid = -1;
while ((dp = readdir(dirp))) {
struct stat statbuf;
if (!isdigit(*dp->d_name)) {
continue;
}
sprintf(dname, "/proc/%s", dp->d_name);
if (stat(dname, &statbuf)) {
continue;
}
if (!(statbuf.st_uid == map->uid)) {
continue;
}
if (portmap_lookup_pid(map, dp->d_name) == 0) {
#if 0
char *pid = dp->d_name;
char ppid[16];
get_process_ppid(pid, ppid, sizeof(ppid));
#endif
//break;
printf("%s has inode %d\n", dp->d_name, map->inode);
}
}
closedir(dirp);
return map->pid == -1 ? ENOENT : 0;
}
int main(int argc, char **argv) {
portmap_t map;
if (argc != 2) {
printf("usage: %s port\n", argv[0]);
}
map.port = atoi(argv[1]);
if (portmap_lookup_inode(&map) == 0) {
if (portmap_lookup_pid_scan(&map) == 0) {
printf("inode=%d, pid=%d\n", map.inode, map.pid);
}
}
return 1;
}
+84
View File
@@ -0,0 +1,84 @@
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Xeon(TM) CPU 2.80GHz
stepping : 7
cpu MHz : 2787.455
cache size : 512 KB
physical id : 0
siblings : 2
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm
bogomips : 5557.45
processor : 1
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Xeon(TM) CPU 2.80GHz
stepping : 7
cpu MHz : 2787.455
cache size : 512 KB
physical id : 0
siblings : 2
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm
bogomips : 5570.56
processor : 2
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Xeon(TM) CPU 2.80GHz
stepping : 7
cpu MHz : 2787.455
cache size : 512 KB
physical id : 3
siblings : 2
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm
bogomips : 5570.56
processor : 3
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Xeon(TM) CPU 2.80GHz
stepping : 7
cpu MHz : 2787.455
cache size : 512 KB
physical id : 3
siblings : 2
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm
bogomips : 5570.56
+84
View File
@@ -0,0 +1,84 @@
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 10
model name : Pentium III (Cascades)
stepping : 1
cpu MHz : 699.331
cache size : 1024 KB
physical id : 0
siblings : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 mmx fxsr sse
bogomips : 1395.91
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 10
model name : Pentium III (Cascades)
stepping : 1
cpu MHz : 699.331
cache size : 1024 KB
physical id : 0
siblings : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 mmx fxsr sse
bogomips : 1395.91
processor : 2
vendor_id : GenuineIntel
cpu family : 6
model : 10
model name : Pentium III (Cascades)
stepping : 1
cpu MHz : 699.331
cache size : 1024 KB
physical id : 0
siblings : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 mmx fxsr sse
bogomips : 1395.91
processor : 3
vendor_id : GenuineIntel
cpu family : 6
model : 10
model name : Pentium III (Cascades)
stepping : 1
cpu MHz : 699.331
cache size : 1024 KB
physical id : 0
siblings : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 mmx fxsr sse
bogomips : 1395.91
+88
View File
@@ -0,0 +1,88 @@
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Xeon(TM) CPU 2.40GHz
stepping : 7
cpu MHz : 2392.082
cache size : 512 KB
physical id : 0
siblings : 2
runqueue : 0
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm
bogomips : 4771.02
processor : 1
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Xeon(TM) CPU 2.40GHz
stepping : 7
cpu MHz : 2392.082
cache size : 512 KB
physical id : 3
siblings : 2
runqueue : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm
bogomips : 4771.02
processor : 2
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Xeon(TM) CPU 2.40GHz
stepping : 7
cpu MHz : 2392.082
cache size : 512 KB
physical id : 0
siblings : 2
runqueue : 0
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm
bogomips : 4771.02
processor : 3
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Xeon(TM) CPU 2.40GHz
stepping : 7
cpu MHz : 2392.082
cache size : 512 KB
physical id : 3
siblings : 2
runqueue : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm
bogomips : 4771.02
+18
View File
@@ -0,0 +1,18 @@
cpu 35136407 290023172 43449938 374366755
cpu0 11428264 67278276 12035936 1168743416
cpu1 5905554 81357812 9496308 1162726218
cpu2 11675543 74058184 12357744 1161394421
cpu3 6127046 67328900 9559950 1176469996
page 1313466877 1018279755
swap 2502992 5804383
intr 836975522 1259485892 143 0 0 665 0 102 0 2 0 189299694 1917217665 393
0 1849 1765936413 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
disk_io: (2,0):(66,66,84,0,0)
ctxt 4284712155
btime 1074702658
processes 33854757