Exemplo n.º 1
0
def run():
    Processor.init()
    try:
        while True:
            pc = Processor.read_pc()
            content = Memory.read(pc)
            assert content[
                'type'] == 2, 'Following content %s is unexpected.' % str(
                    content)
            inst = content['inst']

            Profiler.count(pc)

            if JIT.is_acceleratable(pc):
                JIT.accelerate(pc)
            else:
                """
                print 'Current PC is 0x%08X.' % Processor.read_pc()
                print inst
                """
                Processor.execute(inst)
                JIT.snapshot(pc)
    except KeyboardInterrupt:
        pass
    except:
        print traceback.print_exc()
        print 'Current PC is 0x%08X.' % Processor.read_pc()
        print 'Current instruction is %s.' % str(inst)
Exemplo n.º 2
0
def load_text(text):
    addr = 0
    for line in text:
        if line.startswith(';'):
            continue
        if line.find(':') == -1:
            inst = Parser.inst(line)
            Memory.write(addr, {'type': 2, 'inst': inst})
            Profiler.record(addr, inst)
            addr += 4
        else:
            Labels.add(line.strip().split(':')[0], addr)
Exemplo n.º 3
0
 def restart(self):
     # The normal restart technique is to exit the application
     # with a special exit code and let an exta-process script
     # start the app server up again. That works poorly for a
     # debugging environment which is attached to a particular process.
     Profiler.reset()
     self.initiateShutdown()
     self._closeThread.join()
     sys.stdout.flush()
     sys.stderr.flush()
     self._imp.delModules(includePythonModules=False,
         excludePrefixes=self._excludePrefixes)
     raise ThreadedAppServer.RestartAppServerError
Exemplo n.º 4
0
 def restart(self):
     # The normal restart technique is to exit the application
     # with a special exit code and let an exta-process script
     # start the app server up again. That works poorly for a
     # debugging environment which is attached to a particular process.
     Profiler.reset()
     self.initiateShutdown()
     self._closeThread.join()
     sys.stdout.flush()
     sys.stderr.flush()
     self._imp.delModules(includePythonModules=False,
                          excludePrefixes=self._excludePrefixes)
     raise ThreadedAppServer.RestartAppServerError
Exemplo n.º 5
0
    def applicationShouldTerminate_(self, sender):
        if self.terminating:
            return True

        self.terminating = True
        BlinkLogger().log_info('Application will be terminated')
        NSThread.detachNewThreadSelector_toTarget_withObject_("killSelfAfterTimeout:", self, None)
        NotificationCenter().post_notification("BlinkShouldTerminate", None)
        NotificationCenter().add_observer(self, name="SIPApplicationDidEnd")
        app = SIPApplication()
        app.stop()

        import Profiler
        Profiler.stop(os.path.join(ApplicationData.directory, 'logs', 'profiler.stats'))
        return False
 def calculate(self):
     if (Vars.isDebug()):
         profiler = Profiler.Profiler('self.calculate_()', globals(), locals())
         profiler.profile()
         profiler.printStats()
     else:
         self.calculate_()
Exemplo n.º 7
0
def runOnePuzzle():
    for puzzle in PUZZLES:
        p = SudokuPuzzle(puzzle.getPuzzle())
        Debug.debug(puzzle.getName(),1)
        Debug.debugPrintPuzzle(p, 1)
        orderingStrategy = GuessOrdering.SimpleGuessOrderingByTuple((4,3,2,5,6,7,8,9))
        s = Solver.Solver(p, orderingStrategy)
        time_start = time.time()
        s.solve()
        time_end = time.time()
        elapsed_time = time_end - time_start
        Profiler.printAll(elapsed_time)
        print 'solved puzzle'
        print 'name:', puzzle.getName()
        p.printPuzzle()
        pass
    pass
Exemplo n.º 8
0
def main_web_mapper():
    global profiler
    try:
        profiler = Profiler.Profiler()
        webMapper = WebMapper()
        webMapper.start_mapping()
    except KeyboardInterrupt:
        debug.logger('got KeyboardInterrupt!')
    except:
        raise
    finally:
        debug.close_debugger()
        profiler.print_stats()
Exemplo n.º 9
0
    def shutDown(self):
        """
		Subclasses may override and normally follow this sequence:
			1. set self._shuttingDown to 1
			2. class specific statements for shutting down
			3. Invoke super's shutDown() e.g., AppServer.shutDown(self)
		"""
        print "Shutting down the AppServer"
        self._shuttingDown = 1
        self.running = 0
        self._app.shutDown()
        del self._plugIns
        del self._app
        if Profiler.profiler:
            print 'Writing profile stats to %s...' % Profiler.statsFilename
            Profiler.dumpStats(
            )  # you might also considering having a page/servlet that lets you dump the stats on demand
            print
            print 'WARNING: Applications run much slower when profiled, so turn off profiling in Launch.py when you are finished.'
            print
            print 'AppServer ran for %0.2f seconds.' % (time.time() -
                                                        Profiler.startTime)
        print "AppServer has been shutdown"
Exemplo n.º 10
0
 def process(self, queueItem):
     Profiler.startStopWatch('constraints > ProcessOfElimination')
     # deduction within my row, column, box
     for f in (rowSquares9, columnSquares9, boxSquares9):
         bitmaps = []
         squares = f(self.puzzle, queueItem)
         for square in squares:
             bitmaps.append(square.getBitmap())
         # e.g. in 4-sudoku, you have (23) (24) (1234) (34), you would select 1
         # given a number of bitmaps, how to count if certain position has
         # exactly 1 member set? Using bit operations
         # translate above to (0110) (0101) (1111) (0011)
         setEver = 0
         setOdd = 0
         setTwoPlusTimes = 0
         for bitmap in bitmaps:
             setEver = setEver | bitmap
             setOdd = setOdd ^ bitmap
             # first occurrence of 2 is setEver = 1, setOdd = 0
             setTwoPlusTimes = setTwoPlusTimes | (setEver & (~setOdd & 511))
         if setEver != 511:
             Profiler.stopStopWatch('constraints > ProcessOfElimination')
             raise SudokuConstraintViolationError('contradiction')
         # to get "Sudoku not", do bitwise not, then and with 511
         setExactlyOnce = setOdd & (511 & ~setTwoPlusTimes)
         # setExactlyOnce is values with exactly one square of legality
         for possibleValue in range(1,10):
             if Squares.BITMAP_VALUES[possibleValue] & setExactlyOnce != 0:
                 # find the square with possibleValue legal
                 found = False
                 for square in squares:
                     if square.isPossible(possibleValue):
                         found = True
                         square.select(possibleValue)
                         break
                 if not found:
                     Profiler.stopStopWatch('constraints > ProcessOfElimination')
                     # may not be found in case where a square was
                     # selected in above for loop, thereby eliminating
                     # some other potential value
                     # (resulting in a contradiction)
                     raise SudokuConstraintViolationError('should be found')
     Profiler.stopStopWatch('constraints > ProcessOfElimination')
Exemplo n.º 11
0
import IDCache
import Profiler

mgiconfigPath = '/usr/local/mgi/live/mgiconfig'
if 'MGICONFIG' in os.environ:
        mgiconfigPath = os.environ['MGICONFIG']
sys.path.insert(0, mgiconfigPath)

try:
        import masterConfig
        hasMasterConfig = True
except:
        hasMasterConfig = False

###--- Globals ---###

profiler = Profiler.Profiler()

if hasMasterConfig:
        pg_db.set_sqlServer(masterConfig.MGD_DBSERVER)
        pg_db.set_sqlDatabase(masterConfig.MGD_DBNAME)
        pg_db.set_sqlUser(masterConfig.MGD_DBUSER)
        pg_db.set_sqlPasswordFromFile(masterConfig.MGD_DBPASSWORDFILE)
else:
        pg_db.set_sqlLogin('mgd_public', 'mgdpub', 'mgi-adhoc', 'mgd')

builder = IDCache.CacheBuilder(pg_db.sql, profiler.stamp)
builder.cacheIDs()
profiler.stamp('finished')
profiler.write()
        pathGirona: parent + '/osmFiles/girona/girona_buildings.csv',
        pathBarcelona: parent + '/../BigOsmFiles/Barcelona/Tiendas.csv'
    }
    pathBuildingsDescriptorPredator = {
        pathVenice: parent + '/osmFiles/venice/venice_buildings_predator.csv',
        pathGirona: parent + '/osmFiles/girona/girona_buildings_predator.csv',
        pathBarcelona: parent + '/../BigOsmFiles/Barcelona/Mercados.csv'
    }
    pathCityBackground = {
        pathBarcelona: parent + '/../BigOsmFiles/Barcelona/background.gif'
    }
    commercialGenerator = CommercialGenerator.CommercialGenerator(
        ['Huff', 'UrbanDistance'],
        [pathBarcelona],
        pathPrecomputedCities,
        pathCityBackground,
        pathDensityDescriptor,
        pathBuildingsDescriptor,
        pathBuildingsDescriptorPredator,
        5000,  # number of agents
        1,  # number of buildins
        1)  # number of predator buildings

    if (Vars.isDebug()):
        profiler = Profiler.Profiler(
            'commercialGenerator.processSimulationTemplate()', globals(),
            locals())
        profiler.profile()
        profiler.printStats()
    else:
        commercialGenerator.processSimulationTemplate()
Exemplo n.º 13
0
embedding_dims = 50
maxlen = 50

#train_on_tweets = True

#split_tokenizer_cats = True
#split_classifier_cats = True

kfold = 5

will_shuffle = True
shuffle_seed = 1234

n_est = 1000

prf = Profiler.Milestones()

print("Creating ensemble")
ensemble = ISee.Ensemble()
prf.add_milestone("Created ensemble object")

print("Adding models")
##ensemble.add('Random', NullHypothesis.RandomClassifier())
ensemble.add(
    'XGB',
    XGBClassifier(n_estimators=n_est,
                  learning_rate=0.01,
                  max_depth=6,
                  subsample=0.65,
                  colsample_bytree=0.25,
                  gamma=5))
Exemplo n.º 14
0
def profileStrategy():
    Debug.DEBUG = 0

    strategies = (
        GuessOrdering.SimpleGuessOrderingByTuple2(range(2,10)),
        #GuessOrdering.SimpleGuessOrderingByTuple2((6,5,4,3,2,7,8,9)),
        #GuessOrdering.SimplePlusPairPriority2(),
        #GuessOrdering.DegreeRowColBoxDegree2(),
        #GuessOrdering.DegreeRowColBoxDegree(True),
        #GuessOrdering.DegreeRowColBoxDegree(),
        #GuessOrdering.SimplePlusPairPriority(),
        #GuessOrdering.SimpleGuessOrderingByTuple(range(2,10)),
        #GuessOrdering.SimpleGuessOrderingByTuple((3,2,4,5,6,7,8,9)),
        #GuessOrdering.SimpleGuessOrderingByTuple((4,3,2,5,6,7,8,9)),
        #GuessOrdering.SimpleGuessOrderingByTuple((9,8,7,6,5,4,3,2)),
        #GuessOrdering.SimpleGuessOrderingByTuple((5,4,3,2,6,7,8,9)),
        #GuessOrdering.SimpleGuessOrderingByTuple((6,5,4,3,2,7,8,9)),
        #GuessOrdering.SimpleGuessOrderingByTuple((7,6,5,4,3,2,8,9)),
        #GuessOrdering.SimpleGuessOrderingByTuple((5,4,2,3,6,7,8,9)),
        #GuessOrdering.SimpleGuessOrderingByTuple((5,2,3,4,6,7,8,9)),
    )

    uberresults = []
    number_of_trials = 10

    for i in range(0, len(strategies)):
        strategy = strategies[i]
        trial_results = []
        sum = [0, 0]

        for trial in range(0, number_of_trials):
            Profiler.STOPWATCHES = {}
            Solver.TOTAL_GUESSES_MADE = 0
            p = SudokuPuzzle(SamplePuzzles.getById('worldshardest').getPuzzle())
            s = Solver.Solver(p, strategy)
            Profiler.startStopWatch('cjvk')
            s.solve()
            sys.stdout.write('.')
            sys.stdout.flush()
            Profiler.stopStopWatch('cjvk')
            total_elapsed_time = Profiler.STOPWATCHES['cjvk'].totalElapsed
            trial_results.append((Solver.TOTAL_GUESSES_MADE, total_elapsed_time))
            sum[0] += Solver.TOTAL_GUESSES_MADE
            sum[1] += total_elapsed_time

        name = strategy.name()
        nps = sum[0]/sum[1]
        avg_time = sum[1]/number_of_trials
        avg_guesses = sum[0]/number_of_trials
        ubertuple = (name, nps, avg_time, avg_guesses)

        uberresults.append(ubertuple)
        whichone = str(i+1) + '/' + str(len(strategies))
        #sys.stdout.write(str(len(strategies)-i) + '\n')
        sys.stdout.write(' ' + whichone + '     ' + str(ubertuple) + '\n')
        sys.stdout.flush()
    
    print 'name, number_of_trials, nps, avg_time, avg_guesses'
    for uberresult in uberresults:
        name = str(uberresult[0])
        nps = uberresult[1]
        avg_time = uberresult[2]
        avg_guesses = uberresult[3]
        print 'name=', name
        print 'number_of_trials=', number_of_trials
        print 'nps=', nps
        print 'avg_time=', avg_time
        print 'avg_guesses=', avg_guesses
        print name, number_of_trials, nps, avg_time, avg_guesses