Exemplo n.º 1
0
LL evaluate_jobs(const JobList& jobs) {
  int num_jobs = jobs.size();
  LL sum_lengths = 0;
  LL weighted_sum = 0;
  for (int idx = 0; idx < num_jobs; ++idx) {
    sum_lengths += jobs[idx].second;
    weighted_sum += jobs[idx].first * sum_lengths;
  }
  return weighted_sum;
}
Exemplo n.º 2
0
int main( int argc, char * argv[] )
{
	int result=0;

#ifdef Q_OS_WIN
	hMutex = CreateMutex( NULL, true, L"FreezerSingleProcessMutex");
	if (hMutex == NULL) {
		LOG_5( "Error: Couldn't create mutex, exiting" );
		return false;
	}
	if( GetLastError() == ERROR_ALREADY_EXISTS ) {
		LOG_5( "Error: Another process owns the mutex, exiting" );
		QList<int> pids;
		if( pidsByName( "freezer.exe", &pids ) ) {
			int otherProcessId = pids[0];
			if( otherProcessId == processID() ) {
				if( pids.size() < 2 )
					return false;
				otherProcessId = pids[1];
			}
			LOG_5( "Trying to find window with process pid of " + QString::number( otherProcessId ) );
			EnumWindows( AFEnumWindowsProc, LPARAM(otherProcessId) );
		}
		return false;
	}

	QLibrary excdll( "exchndl.dll" );
	if( !excdll.load() ) {
		qWarning( excdll.errorString().toLatin1().constData() );
	}
	disableWindowsErrorReporting( "assburner.exe" );

#endif

    signal(SIGSEGV, oops_handler);
    signal(SIGABRT, oops_handler);
	QApplication a(argc, argv);

    if( !initConfig( "freezer.ini" ) ) {
#ifndef Q_OS_WIN
        // Fallback if the config file does not exist in the current folder
        if( !initConfig( "/etc/ab/freezer.ini" ) )
#endif
        return -1;
    }

#ifdef Q_OS_WIN
	QString cp = "h:/public/" + getUserName() + "/Blur";
	if( !QDir( cp ).exists() )
		cp = "C:/Documents and Settings/" + getUserName();
	initUserConfig( cp + "/freezer.ini" );
#else
	initUserConfig( QDir::homePath() + "/.freezer" );
#endif

    initStone( argc, argv );
    classes_loader();
    initStoneGui();
	{
		JobList showJobs;
		bool showTime = false;
        QString currentView;
        QStringList loadViewFiles;

		for( int i = 1; i<argc; i++ ){
			QString arg( argv[i] );
			if( arg == "-h" || arg == "--help" )
			{
				LOG_1( QString("Freezer v") + VERSION );
				LOG_1( "Options:" );
				LOG_1( "-current-render" );
				LOG_1( "\tShow the current job that is rendering on this machine\n" );
				LOG_1( "-show-time" );
				LOG_1( "\tOutputs summary of time executed for all sql statement at program close\n" );
				LOG_1( "-user USER" );
				LOG_1( "\tSet the logged in user to USER: Requires Admin Privs" );
				LOG_1( "-current-view VIEWNAME" );
				LOG_1( "\tMake VIEWNAME the active view, once they are all loaded" );
				LOG_1( "-load-view FILE" );
				LOG_1( "\tRead a saved view config from FILE" );
				LOG_1( stoneOptionsHelp() );
				return 0;
			}
			else if( arg.endsWith("-show-time") )
				showTime = true;
			else if( arg.endsWith( "-current-render" ) ) {
				showJobs = Host::currentHost().activeAssignments().jobs();
			}
			else if( arg.endsWith("-user") && (i+1 < argc) ) {
				QString impersonate( argv[++i] );
				if( User::hasPerms( "User", true ) ) // If you can edit users, you can login as anyone
					User::setCurrentUser( impersonate );
			}
            else if( arg.endsWith("-current-view") && (i+1 < argc) ) {
				currentView = QString( argv[++i] );
            }
            else if( arg.endsWith("-load-view") && (i+1 < argc) ) {
                loadViewFiles << QString(argv[++i]);
            }
		}

		// Share the database across threads, each with their own connection
		FreezerCore::setDatabaseForThread( classesDb(), Connection::createFromIni( config(), "Database" ) );
		
		{
            loadPythonPlugins();
			MainWindow m;
			IniConfig & cfg = userConfig();
			cfg.pushSection( "MainWindow" );
			QStringList fg = cfg.readString( "FrameGeometry", "" ).split(',');
			cfg.popSection();
			if( fg.size()==4 ) {
				m.resize( QSize( fg[2].toInt(), fg[3].toInt() ) );
				m.move( QPoint( fg[0].toInt(), fg[1].toInt() ) );
			}
			if( showJobs.size() )
				m.jobPage()->setJobList( showJobs );
            foreach( QString viewFile, loadViewFiles )
                m.loadViewFromFile( viewFile );
            if( !currentView.isEmpty() )
                m.setCurrentView( currentView );
			m.show();
			result = a.exec();
			if( showTime ){
				Database * tm = Database::current();
				LOG_5( 			"                  Sql Time Elapsed" );
				LOG_5(			"|   Select  |   Update  |  Insert  |  Delete  |  Total  |" );
				LOG_5( 			"-----------------------------------------------" );
				LOG_5( QString(	"|     %1    |     %2    |    %3    |    %4    |    %5   |\n")
					.arg( tm->elapsedSqlTime( Table::SqlSelect ) )
					.arg( tm->elapsedSqlTime( Table::SqlUpdate ) )
					.arg( tm->elapsedSqlTime( Table::SqlInsert ) )
					.arg( tm->elapsedSqlTime( Table::SqlDelete ) )
					.arg( tm->elapsedSqlTime() )
				);
				LOG_5( 			"                  Index Time Elapsed" );
				LOG_5(			"|   Added  |   Updated  |  Incoming  |  Deleted  |  Search  |  Total  |" );
				LOG_5( 			"-----------------------------------------------" );
				LOG_5( QString(	"|     %1     |     %2    |    %3    |    %4   |    %5    |   %6    |\n")
					.arg( tm->elapsedIndexTime( Table::IndexAdded ) )
					.arg( tm->elapsedIndexTime( Table::IndexUpdated ) )
					.arg( tm->elapsedIndexTime( Table::IndexIncoming ) )
					.arg( tm->elapsedIndexTime( Table::IndexRemoved ) )
					.arg( tm->elapsedIndexTime( Table::IndexSearch ) )
					.arg( tm->elapsedIndexTime() )
				);
				tm->printStats();
			}
		}
	}
	shutdown();
#ifdef Q_OS_WIN
	CloseHandle( hMutex );
#endif
	return result;
}