コード例 #1
0
int CDECL main( int argc, char *argv[] )
{
	Manager	manager;
	char	iometer[MAX_NETWORK_NAME];
	struct dynamo_param param;

#if defined(IOMTR_OS_LINUX)
	struct aioinit aioDefaults;

	memset(&aioDefaults, 0, sizeof(aioDefaults));
	aioDefaults.aio_threads = 2;
	aioDefaults.aio_threads = 2;
	aio_init(&aioDefaults);
	kstatfd = InitIoctlInterface();
	procstatstyle = DetectProcStatStyle();
	if (kstatfd < 0 && procstatstyle == -1) {
		cerr << "IoMeter can not get correct status information" << endl;
		exit(1);
	}
#if defined(IOMTR_CPU_XSCALE)
	if ((ccntfd = InitCCNTInterface()) < 0) {
		exit(1);
	}
#endif
#endif

	iometer[0]                 = 0;
	manager.manager_name[0]    = 0;
	manager.exclude_filesys[0] = 0;

	//provide a temporary global ptr to the version string for Syntax() to use
	g_pVersionStringWithDebug = manager.GetVersionString(TRUE);
	
	param.iometer 		    = iometer;
	param.manager_name 	    = manager.manager_name;
	param.manager_computer_name = manager.prt->network_name;
	param.manager_exclude_fs    = manager.exclude_filesys;
	param.blkdevlist 	    = &manager.blkdevlist;
	
	ParseParam(argc, argv, &param);

	g_pVersionStringWithDebug = NULL;	//should use manager object after this...

	iomtr_set_cpu_affinity(param.cpu_affinity);

	// If there were command line parameters, indicate that they were recognized.
	if ( iometer[0] || manager.manager_name[0] )
	{
		cout << "\nCommand line parameter(s):" << endl;

		if ( iometer[0] ) {
			cout << "   Looking for Iometer on \"" << iometer << "\"" << endl;
		}
		if ( manager.manager_name[0] ) {
			cout << "   New manager name is \"" << manager.manager_name << "\"" << endl;
		}
	}
	if ( manager.exclude_filesys[0] )
        {
      		cout << "\nExcluding the following filesystem types:" << endl;
        	cout << "   \"" << manager.exclude_filesys << "\"" << endl;
        }
        else
        {
        	strcpy(manager.exclude_filesys, DEFAULT_EXCLUDE_FILESYS);
        }
	cout << endl;

#if defined(IOMTR_OSFAMILY_UNIX)
 #if defined(IOMTR_OS_LINUX)
	signal(SIGALRM, SIG_IGN);
 #elif defined(IOMTR_OS_SOLARIS)
	sigignore(SIGALRM);
 #else
  #warning ===> WARNING: You have to do some coding here to get the port done!
 #endif 

	// Initialize the lock on UNIX platforms.
	if (pthread_mutex_init(&lock_mt, NULL))
	{
		cout <<"unable to init the lock" << endl;
		exit(1);
	}

	// Block SIGPIPE signal. Needed to ensure that Network worker
	// threads don't exit due to a broken pipe signal.
	sigset_t sigset;
	sigemptyset(&sigset);
	sigaddset(&sigset, SIGPIPE);
	if (sigprocmask(SIG_BLOCK, &sigset, NULL) < 0)
	{
		cout << "sigprocmask() call failed." << endl;
		cout << "dynamo could be unstable" << endl;
	}

	//
	// the number of file descriptors a process may create can be a small value like 64.
	//
	struct rlimit rlimitp;
	if (getrlimit(RLIMIT_NOFILE, &rlimitp) < 0)
	{
		cout << "error " << errno << " trying to get rlimit (# file descriptors)" << endl;
	}
	else
	{
		// it succeeded. We leave out atleast 25 file descriptors for non-targets
		// and compare with the hard limit.
		unsigned int targets = MAX_TARGETS + 25;
		if ( rlimitp.rlim_max < targets )
		{
			cout << "Only " << rlimitp.rlim_max << " file descriptors available" << endl;
			rlimitp.rlim_cur = rlimitp.rlim_max;
		}
		else
		{
			// set the soft limit to the required value.
			rlimitp.rlim_cur = targets;
		}
		if (setrlimit(RLIMIT_NOFILE, &rlimitp) < 0)
		{
			cout << "error " << errno << " trying to set rlimit (# file descriptors)" << endl;
		}
	}

	// Check for super-user permissions. If not super-user, we
	// cannot get many of the info from the kernel.
	if (getuid() || geteuid())
	{
		cout << "Dynamo not running as super-user." << endl;
		cout << "       All available disks might not be reported " << endl;
		cout << "       Cannot get TCP statistics from the kernel " << endl;
	}

#ifdef IOMTR_SETTING_OVERRIDE_FS
	// No command line args specifies destructive testing. Check to see if there
	// are any environment variables specifying the same. We need to warn the user.
	if (getenv("IOMTR_SETTING_OVERRIDE_FS") != NULL)
	{
		cout << "       ************ WARNING **************" << endl;
		cout << "       dynamo running in Destructive mode." << endl;
		cout << "         (overriding the not mounted fs)"   << endl;		
		cout << "       ************ WARNING **************" << endl;
	}
#endif // IOMTR_SETTING_OVERRIDE_FS
#endif // IOMTR_OSFAMILY_UNIX
#if defined(IOMTR_OSFAMILY_NETWARE)
	// Initialize the lock on NetWare platforms.
	if (pthread_mutex_init(&lock_mt, NULL))
	{
		cout <<"unable to init the lock" << endl;
		exit(1);
	}
#endif

	// Ensure, that the endian type of the CPU is detectable
	if ( (IsBigEndian() != 0) && (IsBigEndian() != 1) )
	{
		cout << "===> ERROR: Endian type of the CPU couldn't be detected." << endl;
		cout << "     [main() in " << __FILE__ << " line " << __LINE__ << "]" << endl;
		exit(1);
	}

	// Entering infinite loop to allow Dynamo to run multiple tests.  Outer while loop allows
	// Dynamo to be reset from Iometer.  If everything works smoothly, resets should be rare.
	while (TRUE)
	{
		// Initializing worker and logging into Iometer director.
		if ( !manager.Login( iometer ) )
			break;

		// Manager will continue to run until an error, or stopped by Iometer.
		if ( !manager.Run() )
			break;		// Stop running when the manager is done.
	}
	cout << "Ending execution." << endl;
	Sleep( 1000 );

#if defined(IOMTR_OS_LINUX)
	CleanupIoctlInterface(kstatfd);
#if defined(IOMTR_CPU_XSCALE)
	CleanupCCNTInterface(ccntfd);
#endif
#endif
	return(0);
}
コード例 #2
0
ファイル: test.c プロジェクト: blusjune/.bsrc
int main(void)
{
	int fd, res, t, nr_cpu;
	unsigned long m;
	struct cpu_data_type raw_cpu;
	struct ni_data_type raw_net;
	struct tcp_data_type raw_tcp;
	long long sz;
	unsigned long long jf;

	printf("clock_tick = %ld\n", sysconf(_SC_CLK_TCK));
	
	gettcpcounter();
	
	DetectProcStatStyle();
		
	DetectLinuxVersion();

	if ((fd = InitIoctlInterface()) < 0) {
		printf("device file open fail!\n");
		exit(1);
	}
	
	if ((res = ioctl(fd, IM_IOC_GETCPUNUM, &nr_cpu)) >= 0 ) {
		printf("# CPU: %d\n", nr_cpu);
	}
	if ((res = ioctl(fd, IM_IOC_GETCPUKHZ, &m)) >= 0 ) {
		printf("CPU KHZ: %lu\n", m);
	}
	if ((res = ioctl(fd, IM_IOC_GETCURJIFFIES, &jf)) >= 0 ) {
		printf("JIFFIE: %llu\n", jf);
	}
	if ((res = ioctl(fd, IM_IOC_GETCPUDATA, &raw_cpu)) >= 0 ) {
		for (t = 0; t < nr_cpu; t++) {
			printf("cpu %d: system time %llu, user time %llu\n", t, raw_cpu.system_time[t], raw_cpu.user_time[t]);
		}
		printf("# intr %llu\n", raw_cpu.intr);
	}
	if ((res = ioctl(fd, IM_IOC_GETNIDATA, &raw_net)) >= 0 ) {
		for (t = 0; t < MAX_NUM_INTERFACES; t++) {
			if (raw_net.nr_pkt[t])
				printf("net %d: nr_pkt %llu, in_err %llu, out_err %llu\n", t, raw_net.nr_pkt[t], 
					raw_net.in_err[t], raw_net.out_err[t]);
		}
	}
	if ((res = ioctl(fd, IM_IOC_GETTCPDATA, &raw_tcp)) >= 0 ) {
		printf("tcp:%lld, %lld, %lld\n", raw_tcp.insegs, raw_tcp.outsegs, raw_tcp.retranssegs);
	}
	else {
		printf("fail\n");
	}

	CleanupIoctlInterface(fd);
	fd = open("/dev/hda", O_RDONLY);
	if (fd < 0)
		printf("fail to open\n");
	else {
		// get a sector size
		res = ioctl(fd, BLKSSZGET, &t);
		printf("sz:%d\n", t);
		// get a total size
		res = ioctl(fd, BLKGETSIZE64, &sz);
		printf("sz:%llu\n", sz);
	}
	
	return 0;
}