This commit is contained in:
parent
b94783b9ad
commit
9dbbcce60a
|
@ -1,2 +0,0 @@
|
|||
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.
|
21
exp/argv.pl
21
exp/argv.pl
|
@ -1,21 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
#generate a process with large argv for proc_args testing
|
||||
|
||||
use strict;
|
||||
|
||||
if (@ARGV) {
|
||||
print "pid=$$\n";
|
||||
<STDIN>;
|
||||
}
|
||||
else {
|
||||
my(@argv);
|
||||
my $nargs = 26;
|
||||
my $arglen = 4256;
|
||||
my $arg = 'a';
|
||||
for (my $i=0; $i<$nargs; $i++) {
|
||||
push @argv, $arg++ x $arglen;
|
||||
}
|
||||
print "$^X $0\n";
|
||||
exec $^X, $0, @argv or die $!;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
#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::%s.%s[%d]\n",
|
||||
kstat_type_names[kp->ks_type],
|
||||
kp->ks_class, kp->ks_module, kp->ks_name, kp->ks_instance);
|
||||
}
|
||||
|
||||
kstat_close(kc);
|
||||
}
|
27
exp/fork.pl
27
exp/fork.pl
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
|
||||
#create processes to benchmark ptql stuff
|
||||
|
||||
my $num = shift || 10;
|
||||
my @kids;
|
||||
my $pid;
|
||||
|
||||
for (my $i=0; $i<$num; $i++) {
|
||||
if (!defined($pid = fork())) {
|
||||
die "cannot fork: $!";
|
||||
}
|
||||
elsif ($pid) {
|
||||
#parent
|
||||
push @kids, $pid;
|
||||
}
|
||||
else {
|
||||
#child
|
||||
sleep 10 while 1;
|
||||
}
|
||||
}
|
||||
|
||||
for $pid (@kids) {
|
||||
waitpid($pid, 0);
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
#common cpu model names
|
||||
#linux /proc/cpuinfo model name
|
||||
#win32 HKLM/HARDWARE/DESCRIPTION/System/CentralProcessor/0/ProcessorNameString
|
||||
|
||||
Intel(R) Xeon(TM) CPU 2.40GHz
|
||||
Pentium III (Cascades)
|
||||
Celeron (Mendocino)
|
||||
Pentium III (Coppermine)
|
||||
Pentium 75 - 200
|
||||
AMD-K6(tm)-III Processor
|
||||
AMD Opteron(tm) Processor 246
|
||||
Opteron MP w/ 1MB
|
||||
Intel(R) XEON(TM) CPU 1.80GHz
|
||||
Pentium II (Deschutes)
|
||||
Intel(R) Pentium(R) 4 CPU 1.80GHz
|
||||
AMD-K6(tm) 3D+ Processor
|
||||
AMD Athlon(tm) processor
|
||||
AMD Athlon(tm) XP 1900+
|
||||
Intel(R) Celeron(R) CPU 1.70GHz
|
||||
AMD Athlon(TM) XP 2400+
|
||||
AMD Athlon (TM)
|
||||
Pentium Pro
|
||||
Pentium III (Katmai)
|
||||
mobile AMD Athlon(tm) 4 Processor
|
||||
AMD Duron(tm) Processor
|
||||
AMD Athlon(TM) XP1700+
|
||||
Pentium II (Klamath)
|
||||
Pentium III (Katmai)
|
||||
AMD Athlon(tm) MP Processor 1800+
|
||||
Pentium MMX
|
||||
Intel(R) Pentium(R) 4 Mobile CPU 1.60GHz
|
||||
Intel(R) Celeron(TM) CPU 1200MHz
|
||||
Intel(R) Pentium(R) III CPU family 1400MHz
|
||||
Mobile Intel(R) Pentium(R) 4 - M CPU 2.00GHz
|
||||
Intel(R) Celeron(R) CPU 2.30GHz
|
||||
Intel(R) Pentium(R) M processor 1500MHz
|
||||
Intel(R) Xeon(TM) MP CPU 2.80GHz
|
26
exp/lspv.pl
26
exp/lspv.pl
|
@ -1,26 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
|
||||
my $lspv = "/usr/sbin/lspv";
|
||||
|
||||
open LSPV, "$lspv|" or die;
|
||||
my(@lspv) = <LSPV>;
|
||||
close LSPV;
|
||||
|
||||
my $dlm = ("-" x 25) . "\n";
|
||||
|
||||
print "$lspv\n", @lspv;
|
||||
print $dlm;
|
||||
|
||||
for my $line (@lspv) {
|
||||
my $disk = (split /\s+/, $line)[0];
|
||||
next unless $disk;
|
||||
next if $line =~ / None/;
|
||||
my $cmd = "$lspv -l $disk";
|
||||
open LSPV, "$cmd|" or die;
|
||||
my(@pv) = <LSPV>;
|
||||
close LSPV;
|
||||
print "$cmd\n", @pv;
|
||||
print $dlm;
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
#!perl
|
||||
|
||||
use strict;
|
||||
|
||||
my $match = $ARGV[0];
|
||||
|
||||
my $proc = $ENV{PROC_FS} || "/proc";
|
||||
opendir DH, $proc or die;
|
||||
chdir $proc;
|
||||
local $/;
|
||||
|
||||
while (my $pid = readdir DH) {
|
||||
next unless $pid =~ /^\d+$/;
|
||||
open FH, "$pid/cmdline" or next;
|
||||
my(@cmdline) = split /\000/, <FH>;
|
||||
close FH;
|
||||
if ($match) {
|
||||
next unless grep { /$match/o } @cmdline;
|
||||
}
|
||||
|
||||
print "-------------------------------\n";
|
||||
|
||||
my $i=0;
|
||||
print "pid=$pid\n";
|
||||
for my $arg (@cmdline) {
|
||||
print "$i='$arg'\n";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
closedir DH;
|
|
@ -1,21 +0,0 @@
|
|||
#!perl
|
||||
|
||||
use strict;
|
||||
#examine specific field from /proc/*/stat
|
||||
my $field = shift;
|
||||
|
||||
my $proc = $ENV{PROC_FS} || "/proc";
|
||||
opendir DH, $proc or die;
|
||||
chdir $proc;
|
||||
local $/;
|
||||
|
||||
while (my $pid = readdir DH) {
|
||||
next unless $pid =~ /^\d+$/;
|
||||
open FH, "$pid/stat" or next;
|
||||
my $data = <FH>;
|
||||
close FH;
|
||||
my(@fields) = split /\s+/, $data;
|
||||
print "$pid $fields[1] -> $fields[$field]\n";
|
||||
}
|
||||
|
||||
closedir DH;
|
57
exp/ptql.c
57
exp/ptql.c
|
@ -1,57 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include "sigar.h"
|
||||
#include "sigar_ptql.h"
|
||||
|
||||
int ptql_test(sigar_t *sigar, char *ptql) {
|
||||
int status, i;
|
||||
sigar_proc_list_t proclist;
|
||||
sigar_ptql_query_t *query;
|
||||
sigar_ptql_error_t error;
|
||||
|
||||
status =
|
||||
sigar_proc_list_get(sigar, &proclist);
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status =
|
||||
sigar_ptql_query_create(&query, ptql, &error);
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
for (i=0; i<proclist.number; i++) {
|
||||
sigar_pid_t pid = proclist.data[i];
|
||||
if (sigar_ptql_query_match(sigar, query, pid) == SIGAR_OK) {
|
||||
sigar_proc_state_t state;
|
||||
sigar_proc_state_get(sigar, pid, &state);
|
||||
printf("name=%s, pid=%d\n", state.name, (int)pid);
|
||||
}
|
||||
}
|
||||
|
||||
sigar_proc_list_destroy(sigar, &proclist);
|
||||
|
||||
sigar_ptql_query_destroy(query);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
sigar_t *sigar;
|
||||
|
||||
if (sigar_open(&sigar) != SIGAR_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i=0; i<argc; i++) {
|
||||
ptql_test(sigar, argv[i]);
|
||||
}
|
||||
|
||||
sigar_close(sigar);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
#include <sigar.h>
|
||||
#include <stdio.h>
|
||||
/*
|
||||
gcc -g -o sigar_proc_args -lsocket \
|
||||
-L ../bindings/java/sigar-bin/lib -lsigar-sparc-sun-solaris-2.x \
|
||||
-I ../include sigar_proc_args.c
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
sigar_t *sigar;
|
||||
sigar_proc_list_t procs;
|
||||
sigar_proc_args_t args;
|
||||
int n;
|
||||
|
||||
if (sigar_open(&sigar) != SIGAR_OK) {
|
||||
fprintf(stderr, "Error opening sigar!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
sigar_proc_list_get(sigar, &procs);
|
||||
|
||||
for (n=0; n<procs.number; n++) {
|
||||
pid_t pid = procs.data[n];
|
||||
int status =
|
||||
sigar_proc_args_get(sigar, pid, &args);
|
||||
|
||||
printf("-------------------------------\n");
|
||||
|
||||
if (status == SIGAR_OK) {
|
||||
int i;
|
||||
|
||||
printf("pid=%d\n", pid);
|
||||
|
||||
for (i=0; i<args.number; i++) {
|
||||
printf("%d='%s'\n", i, args.data[i]);
|
||||
}
|
||||
|
||||
sigar_proc_args_destroy(sigar, &args);
|
||||
}
|
||||
else {
|
||||
printf("pid=%d error=%d...%s\n",
|
||||
pid, status, sigar_strerror(sigar, status));
|
||||
}
|
||||
}
|
||||
|
||||
sigar_proc_list_destroy(sigar, &procs);
|
||||
sigar_close(sigar);
|
||||
|
||||
return 0;
|
||||
}
|
83
exp/sizeof.c
83
exp/sizeof.c
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
#!perl -l
|
||||
use Config;
|
||||
my $prg = "$0.out";
|
||||
my $cmd = "gcc -Wall -D$^O -o $prg $0; ./$prg; rm $prg";
|
||||
print $cmd; system $cmd;
|
||||
__END__
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
unsigned int size;
|
||||
} sizeof_info_t;
|
||||
|
||||
#define SIZEOF_INFO(v) \
|
||||
{#v, sizeof(v)}
|
||||
|
||||
#ifdef solaris
|
||||
|
||||
#include <sys/kstat.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <procfs.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/user.h>
|
||||
|
||||
static sizeof_info_t sizeof_info[] = {
|
||||
/* kstat */
|
||||
SIZEOF_INFO(kstat_named_t),
|
||||
SIZEOF_INFO(vminfo_t),
|
||||
SIZEOF_INFO(cpu_stat_t),
|
||||
SIZEOF_INFO(cpu_vminfo_t),
|
||||
SIZEOF_INFO(cpu_sys_stats_t),
|
||||
SIZEOF_INFO(kstat_io_t),
|
||||
/* procfs */
|
||||
SIZEOF_INFO(psinfo_t),
|
||||
SIZEOF_INFO(prusage_t),
|
||||
SIZEOF_INFO(prcred_t),
|
||||
SIZEOF_INFO(pstatus_t),
|
||||
SIZEOF_INFO(struct proc),
|
||||
SIZEOF_INFO(struct user),
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef hpux
|
||||
|
||||
#include <sys/pstat.h>
|
||||
#include <mntent.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <sys/mib.h>
|
||||
|
||||
static sizeof_info_t sizeof_info[] = {
|
||||
SIZEOF_INFO(struct pst_static),
|
||||
SIZEOF_INFO(struct pst_status),
|
||||
SIZEOF_INFO(struct pst_dynamic),
|
||||
SIZEOF_INFO(struct pst_swapinfo),
|
||||
SIZEOF_INFO(struct mntent),
|
||||
SIZEOF_INFO(struct statfs),
|
||||
SIZEOF_INFO(struct nmparms),
|
||||
SIZEOF_INFO(mib_ifEntry),
|
||||
SIZEOF_INFO(mib_ipRouteEnt),
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
static void print_sizeof_info(sizeof_info_t *info)
|
||||
{
|
||||
while (info->name) {
|
||||
printf("sizeof(%s) == %d\n", info->name, info->size);
|
||||
++info;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
system("uname -a");
|
||||
print_sizeof_info(sizeof_info);
|
||||
return 0;
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/processor.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <kstat.h>
|
||||
#include <procfs.h>
|
||||
|
||||
#define PROC_ERRNO ((errno == ENOENT) ? ESRCH : errno)
|
||||
|
||||
#define my_pread(fd, ptr, type, offset) \
|
||||
(pread(fd, ptr, sizeof(type), offset) == sizeof(type))
|
||||
|
||||
static int proc_psinfo_get(psinfo_t *psinfo, pid_t pid)
|
||||
{
|
||||
int fd, retval = 0;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
sprintf(buffer, "/proc/%d/psinfo", pid);
|
||||
|
||||
if ((fd = open(buffer, O_RDONLY)) < 0) {
|
||||
return ESRCH;
|
||||
}
|
||||
|
||||
if (!my_pread(fd, psinfo, psinfo_t, 0)) {
|
||||
retval = errno;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
DIR *dirp = opendir("/proc");
|
||||
struct dirent *ent;
|
||||
char *models[] = {
|
||||
"unknown", "32bit", "64bit"
|
||||
};
|
||||
|
||||
while ((ent = readdir(dirp))) {
|
||||
pid_t pid;
|
||||
psinfo_t psinfo;
|
||||
int retval;
|
||||
char buffer[BUFSIZ];
|
||||
char *argvb[56];
|
||||
char **argvp = argvb;
|
||||
|
||||
int n, fd;
|
||||
size_t nread = 0;
|
||||
unsigned int argv_size;
|
||||
|
||||
if (!isdigit(*ent->d_name)) {
|
||||
continue;
|
||||
}
|
||||
psinfo.pr_dmodel = 0;
|
||||
pid = strtoul(ent->d_name, NULL, 10);
|
||||
retval = proc_psinfo_get(&psinfo, pid);
|
||||
printf("---------------------------------\n");
|
||||
printf("pid=%d, status=%s, model=%s\n",
|
||||
pid, retval ? strerror(retval) : "OK",
|
||||
models[psinfo.pr_dmodel]);
|
||||
|
||||
argv_size = sizeof(*argvp) * psinfo.pr_argc;
|
||||
sprintf(buffer, "/proc/%d/as", pid);
|
||||
printf("argc=%d, argv_size=%d\n",
|
||||
psinfo.pr_argc, argv_size);
|
||||
|
||||
if ((fd = open(buffer, O_RDONLY)) < 0) {
|
||||
printf("open(%s) == %s\n",
|
||||
buffer, strerror(PROC_ERRNO));
|
||||
if (argvp != argvb) {
|
||||
free(argvp);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (argv_size > sizeof(argvb)) {
|
||||
argvp = malloc(argv_size);
|
||||
}
|
||||
|
||||
if ((nread = pread(fd, argvp, argv_size, psinfo.pr_argv)) <= 0) {
|
||||
close(fd);
|
||||
printf(" pread(%d, 0x%lx, %d, 0x%lx) == %d (%s)\n",
|
||||
fd, (unsigned long)argvp, argv_size,
|
||||
(unsigned long)psinfo.pr_argv,
|
||||
nread, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
|
||||
for (n = 0; n < psinfo.pr_argc; n++) {
|
||||
int alen;
|
||||
char *arg;
|
||||
|
||||
if ((nread = pread(fd, buffer, sizeof(buffer), (off_t)argvp[n])) <= 0) {
|
||||
close(fd);
|
||||
printf(" %-2d) pread(%d, 0x%lx, %d, 0x%lx) == %d (%s)\n",
|
||||
n, fd, (unsigned long)&buffer[0], sizeof(buffer),
|
||||
(unsigned long)argvp[n],
|
||||
nread, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
|
||||
printf(" %-2d) nread=%-4d, ", n, nread);
|
||||
fflush(stdout);
|
||||
alen = strlen(buffer)+1;
|
||||
printf(" alen=%-4d ", alen);
|
||||
fflush(stdout);
|
||||
arg = malloc(alen);
|
||||
memcpy(arg, buffer, alen);
|
||||
printf(" {%s}\n", arg);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
if (argvp != argvb) {
|
||||
free(argvp);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
#!perl
|
||||
|
||||
#create a .tar.gz of /proc/*/@proc_files
|
||||
|
||||
use strict;
|
||||
|
||||
my(@proc_files) = qw(cmdline stat statm status maps);
|
||||
my $cpname = "copy-proc";
|
||||
my $tmp = $ENV{TMPDIR} || "/tmp";
|
||||
my $tmpdir = "$tmp/$cpname";
|
||||
unless (-e $tmpdir) {
|
||||
mkdir $tmpdir or die "mkdir $tmpdir: $!";
|
||||
print "created $tmpdir\n";
|
||||
}
|
||||
|
||||
opendir DH, "/proc" or die;
|
||||
chdir "/proc";
|
||||
|
||||
while (my $pid = readdir DH) {
|
||||
next unless $pid =~ /^\d+$/;
|
||||
for my $name (@proc_files) {
|
||||
unless (-e "$tmpdir/$pid") {
|
||||
mkdir "$tmpdir/$pid";
|
||||
}
|
||||
local *SRC, *TARG;
|
||||
my $file = "$pid/$name";
|
||||
open SRC, $file or next;
|
||||
open TARG, ">$tmpdir/$file" or die "open $tmpdir/$file: $!";
|
||||
print TARG <SRC>;
|
||||
close TARG;
|
||||
close SRC;
|
||||
}
|
||||
}
|
||||
|
||||
chdir $tmp or die "chdir $tmp: $!";
|
||||
system "tar -cf $cpname.tar $cpname";
|
||||
system "gzip -f $cpname.tar";
|
||||
|
||||
print "files saved to $tmp/$cpname.tar.gz\n";
|
||||
print "to cleanup, run: rm -rf $tmp/$cpname\n";
|
||||
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
struct utsname name;
|
||||
uname(&name);
|
||||
|
||||
printf("sysname....%s\n", name.sysname);
|
||||
printf("nodename...%s\n", name.nodename);
|
||||
printf("release....%s\n", name.release);
|
||||
printf("version....%s\n", name.version);
|
||||
printf("machine....%s\n", name.machine);
|
||||
|
||||
return 0;
|
||||
}
|
219
src/sigar_main.c
219
src/sigar_main.c
|
@ -1,219 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
|
||||
* This file is part of SIGAR.
|
||||
*
|
||||
* SIGAR is free software; you can redistribute it and/or modify
|
||||
* it under the terms version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation. This program is distributed
|
||||
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
||||
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*/
|
||||
|
||||
#define WIN32
|
||||
#if defined(WIN32)
|
||||
#define WINDOWS_LEAN_AND_MEAN
|
||||
#define FILESEP '\\'
|
||||
#define LIBPRE ""
|
||||
#include "windows.h"
|
||||
#else
|
||||
#define FILESEP '/'
|
||||
#define LIBPRE "lib"
|
||||
#include <dlfcn.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include "sigar.h"
|
||||
#include "sigar_fileinfo.h"
|
||||
|
||||
#if defined(WIN32)
|
||||
# define LIBEXT "dll"
|
||||
#elif defined(DARWIN)
|
||||
# define LIBEXT "dylib"
|
||||
#else
|
||||
# define LIBEXT "so"
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
void *func;
|
||||
} sigar_callback_t;
|
||||
|
||||
struct {
|
||||
struct {
|
||||
const char *name;
|
||||
sigar_version_t * (*func)(void);
|
||||
} version;
|
||||
|
||||
struct {
|
||||
const char *name;
|
||||
int (*func)(sigar_t **);
|
||||
} open;
|
||||
|
||||
struct {
|
||||
const char *name;
|
||||
int (*func)(sigar_t *);
|
||||
} close;
|
||||
|
||||
struct {
|
||||
const char *name;
|
||||
int (*func)(sigar_t *, sigar_pid_t, sigar_proc_exe_t *);
|
||||
} proc_exe;
|
||||
struct {
|
||||
const char *name;
|
||||
int (*func)(sigar_t *, sigar_pid_t, sigar_proc_args_t *);
|
||||
} proc_args;
|
||||
struct {
|
||||
const char *name;
|
||||
int (*func)(sigar_t *, sigar_pid_t, sigar_proc_env_t *);
|
||||
} proc_env;
|
||||
struct {
|
||||
const char *name;
|
||||
int (*func)(sigar_t *, sigar_pid_t, sigar_proc_modules_t *);
|
||||
} proc_modules;
|
||||
struct {
|
||||
const char *name;
|
||||
int (*func)(sigar_t *, sigar_pid_t, sigar_proc_fd_t *);
|
||||
} proc_fd;
|
||||
struct {
|
||||
const char *name;
|
||||
int (*func)(sigar_t *, int, unsigned long, sigar_pid_t *);
|
||||
} proc_port;
|
||||
|
||||
struct {
|
||||
const char *name;
|
||||
int (*func)(sigar_t *, const char *dir, sigar_dir_stat_t *);
|
||||
} dir_stat;
|
||||
struct {
|
||||
const char *name;
|
||||
int (*func)(sigar_t *, const char *dir, sigar_dir_usage_t *);
|
||||
} dir_usage;
|
||||
sigar_callback_t end;
|
||||
} sigar_callbacks = {
|
||||
{ "sigar_version_get", NULL },
|
||||
{ "sigar_open", NULL },
|
||||
{ "sigar_close", NULL },
|
||||
{ "sigar_proc_exe_get", NULL },
|
||||
{ "sigar_proc_args_get", NULL },
|
||||
{ "sigar_proc_env_get", NULL },
|
||||
{ "sigar_proc_modules_get", NULL },
|
||||
{ "sigar_proc_fd_get", NULL },
|
||||
{ "sigar_proc_port_get", NULL },
|
||||
{ "sigar_dir_stat_get", NULL },
|
||||
{ "sigar_dir_usage_get", NULL },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static int sigar_main(char *argv0)
|
||||
{
|
||||
int status;
|
||||
sigar_t *sigar;
|
||||
char *errmsg;
|
||||
char *ptr;
|
||||
char sigarlib[8096], archlib[512];
|
||||
void *handle;
|
||||
sigar_callback_t *callbacks =
|
||||
(sigar_callback_t *)&sigar_callbacks;
|
||||
|
||||
strcpy(sigarlib, argv0);
|
||||
#ifdef WIN32
|
||||
if ((ptr = strstr(sigarlib, ".exe"))) {
|
||||
*ptr = '\0';
|
||||
}
|
||||
#endif
|
||||
ptr = strrchr(sigarlib, FILESEP);
|
||||
if (ptr) {
|
||||
++ptr;
|
||||
}
|
||||
else {
|
||||
ptr = sigarlib;
|
||||
}
|
||||
|
||||
sprintf(archlib, LIBPRE "%s." LIBEXT, ptr);
|
||||
strcpy(ptr, archlib);
|
||||
|
||||
#if defined(__sun)
|
||||
dlopen("/usr/lib/libnsl.so", RTLD_NOW|RTLD_GLOBAL);
|
||||
#endif
|
||||
|
||||
#if defined(WIN32)
|
||||
if (!(handle = LoadLibrary(sigarlib))) {
|
||||
errmsg = "XXX FormatMessage";
|
||||
}
|
||||
#else
|
||||
if (!(handle = dlopen(sigarlib, RTLD_LAZY))) {
|
||||
errmsg = dlerror();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!handle) {
|
||||
fprintf(stderr, "Error opening '%s': %s\n",
|
||||
sigarlib, errmsg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (callbacks->name) {
|
||||
#if defined(WIN32)
|
||||
callbacks->func = GetProcAddress(handle, callbacks->name);
|
||||
#else
|
||||
callbacks->func = dlsym(handle, callbacks->name);
|
||||
#endif
|
||||
callbacks++;
|
||||
}
|
||||
|
||||
if (isatty(fileno(stdin))) {
|
||||
sigar_version_t *version;
|
||||
|
||||
if (!sigar_callbacks.version.func) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
version = sigar_callbacks.version.func();
|
||||
|
||||
printf("version=%s, build date=%s\n",
|
||||
version->version, version->build_date);
|
||||
#if defined(WIN32)
|
||||
FreeLibrary(handle);
|
||||
#else
|
||||
dlclose(handle);
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
|
||||
status = sigar_callbacks.open.func(&sigar);
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
perror("sigar_open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* XXX pipe loop */
|
||||
|
||||
sigar_callbacks.close.func(sigar);
|
||||
#if defined(WIN32)
|
||||
FreeLibrary(handle);
|
||||
#else
|
||||
dlclose(handle);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 1) {
|
||||
return sigar_main(argv[0]);
|
||||
}
|
||||
else {
|
||||
return 1; /*XXX*/
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue