本文整理汇总了Python中statprof.stop函数的典型用法代码示例。如果您正苦于以下问题:Python stop函数的具体用法?Python stop怎么用?Python stop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrapped
def wrapped(*args, **kwargs):
statprof.start()
try:
return main(*args, **kwargs)
finally:
statprof.stop()
statprof.display(OUT=file(output_file, 'wb'))
示例2: __exit__
def __exit__(self, type, value, callback):
import statprof
statprof.stop()
for call in statprof.CallData.all_calls.itervalues():
trace = _Trace(call)
for attr in ('percent', 'cumulative', 'self'):
self.update("{0}.{1}".format(trace.name, attr), getattr(trace, attr))
示例3: process_response
def process_response(self, request, response):
statprof.stop()
client = get_client()
total_samples = statprof.state.sample_count
if total_samples == 0:
return response
secs_per_sample = statprof.state.accumulated_time / total_samples
def get_struct(c):
return ({
'file': c.key.filename,
'lineno': c.key.lineno,
'function': c.key.name,
'type': 'python'
}, {
'self_nsamples': c.self_sample_count,
'cum_nsamples': c.cum_sample_count,
'tot_nsamples': total_samples,
'cum_time': c.cum_sample_count * secs_per_sample,
'self_time': c.self_sample_count * secs_per_sample
})
client.insert_all([get_struct(c)
for c in statprof.CallData.all_calls.itervalues()])
return response
示例4: process_response
def process_response(self, request, response):
statprof.stop()
client = get_client()
total_samples = statprof.state.sample_count
if total_samples == 0:
return response
secs_per_sample = statprof.state.accumulated_time / total_samples
client.insert_all(
[
(
{"file": c.key.filename, "lineno": c.key.lineno, "function": c.key.name, "type": "python"},
{
"self_nsamples": c.self_sample_count,
"cum_nsamples": c.cum_sample_count,
"tot_nsamples": total_samples,
"cum_time": c.cum_sample_count * secs_per_sample,
"self_time": c.self_sample_count * secs_per_sample,
},
)
for c in statprof.CallData.all_calls.itervalues()
]
)
return response
示例5: stat
def stat():
if options.profile:
statprof.stop()
output = StringIO.StringIO()
output.write("-" * 80)
output.write("\nWorker with PID %s processed %d requests\n" % (workerPid, site.cnt))
if options.profile:
output.write("\n")
#format = statprof.DisplayFormats.ByLine
#format = statprof.DisplayFormats.ByMethod
#statprof.display(output, format = format)
statprof.display(output)
output.write("-" * 80)
output.write("\n")
output.write("\n")
sys.stdout.write(output.getvalue())
if options.profile:
statprof.reset()
statprof.start()
reactor.callLater(options.interval, stat)
示例6: inner
def inner(*args, **kwargs):
statprof.reset(frequency=1000)
statprof.start()
try:
return fn(*args, **kwargs)
finally:
statprof.stop()
statprof.display()
示例7: catching
def catching(proc, *args, **kwargs):
import statprof
statprof.start()
try:
return proc(*args, **kwargs)
finally:
statprof.stop()
statprof.display()
示例8: pilot_detail
def pilot_detail(request, pilot_id):
return pilot_detail_view.pilot_detail(request, pilot_id)
statprof.start()
try:
return pilot_detail_view.pilot_detail(request, pilot_id)
finally:
statprof.stop()
statprof.display()
return pilot_detail_view.pilot_detail(request, pilot_id)
return render(request, "analizer/index.html", {"error_message": "Unsupported: "})
示例9: inner
def inner(*args, **kwargs):
if deco_kwargs.get('traceback'):
traceback.print_stack()
print('starting %s' % fn.__name__)
start = time.time()
stat_profile = deco_kwargs.get('stat_profile')
if stat_profile:
import statprof
statprof.reset(frequency=10000)
statprof.start()
fn(*args, **kwargs)
fn_time = time.time() - start
print('finished %s in %s s' % (fn.__name__, fn_time))
if stat_profile:
statprof.stop()
statprof.display()
return fn_time
示例10: statprofile
def statprofile(ui, func, fp):
try:
import statprof
except ImportError:
raise util.Abort(_('statprof not available - install using "easy_install statprof"'))
freq = ui.configint("profiling", "freq", default=1000)
if freq > 0:
statprof.reset(freq)
else:
ui.warn(_("invalid sampling frequency '%s' - ignoring\n") % freq)
statprof.start()
try:
return func()
finally:
statprof.stop()
statprof.display(fp)
示例11: run
def run(main, profile=None):
if not profile:
main()
return
if profile == 'hotshot':
import hotshot, hotshot.stats
p = hotshot.Profile("/tmp/pro")
p.runcall(main)
p.close()
hotshot.stats.load("/tmp/pro").sort_stats('cumulative').print_stats()
elif profile == 'stat':
import statprof
statprof.start()
try:
main()
finally:
statprof.stop()
statprof.display()
示例12: statprofile
def statprofile(ui, fp):
try:
import statprof
except ImportError:
raise error.Abort(_(
'statprof not available - install using "easy_install statprof"'))
freq = ui.configint('profiling', 'freq', default=1000)
if freq > 0:
# Cannot reset when profiler is already active. So silently no-op.
if statprof.state.profile_level == 0:
statprof.reset(freq)
else:
ui.warn(_("invalid sampling frequency '%s' - ignoring\n") % freq)
statprof.start()
try:
yield
finally:
statprof.stop()
statprof.display(fp)
示例13: test_profiling_output_contains_file_names_formatted_appropriately
def test_profiling_output_contains_file_names_formatted_appropriately():
start()
def fun():
for i in range(2 ** 20):
pass
def fun2():
for i in range(50):
fun()
fun2()
stop()
for format in (DisplayFormat.BY_LINE, DisplayFormat.BY_METHOD):
full_path = abspath(__file__)
base = basename(__file__)
content = get_output(format=format, path_format=PathFormat.FULL_PATH)
assert full_path in content
content = get_output(format=format, path_format=PathFormat.FILENAME_ONLY)
assert base in content
assert full_path not in content
示例14: stat
def stat():
if options.profile:
statprof.stop()
output = StringIO.StringIO()
output.write("-" * 80 + "\n")
output.write("Worker Statistics (PID %s)\n\n%s" % (workerPid, factory.stats.stats()))
if options.profile:
output.write("\n")
#format = statprof.DisplayFormats.ByLine
#format = statprof.DisplayFormats.ByMethod
#statprof.display(output, format = format)
statprof.display(output)
output.write("-" * 80 + "\n\n")
sys.stdout.write(output.getvalue())
if options.profile:
statprof.reset(PROFILER_FREQ)
statprof.start()
reactor.callLater(options.interval, stat)
示例15: generateOrders
def generateOrders(): # pylint: disable=invalid-name
"""Called once per turn to tell the Python AI to generate and issue orders to control its empire.
at end of this function, fo.doneTurn() should be called to indicate to the client that orders are finished
and can be sent to the server for processing."""
empire = fo.getEmpire()
if empire.eliminated:
print "This empire has been eliminated. Aborting order generation"
try:
# early abort if already eliminated. no need to do meter calculations
# on last-seen gamestate if nothing can be ordered anyway...
fo.doneTurn()
except Exception as e:
print_error(e)
return
# This code block is required for correct AI work.
print "Meter / Resource Pool updating..."
fo.initMeterEstimatesDiscrepancies()
fo.updateMeterEstimates(0)
fo.updateResourcePools()
turn = fo.currentTurn()
turn_uid = foAIstate.set_turn_uid()
print "Start turn %s (%s) of game: %s" % (turn, turn_uid, foAIstate.uid)
turn_timer.start("AI planning")
# set the random seed (based on galaxy seed, empire name and current turn)
# for game-reload consistency.
random_seed = str(fo.getGalaxySetupData().seed) + "%05d%s" % (turn, fo.getEmpire().name)
random.seed(random_seed)
aggression_name = fo.aggression.values[foAIstate.aggression].name
if turn == 1:
declare_war_on_all()
human_player = fo.empirePlayerID(1)
fo.sendChatMessage(human_player, '%s Empire (%s):\n"Ave, Human, morituri te salutant!"' % (empire.name, aggression_name))
# turn cleanup !!! this was formerly done at start of every turn -- not sure why
foAIstate.split_new_fleets()
foAIstate.refresh() # checks exploration border & clears roles/missions of missing fleets & updates fleet locs & threats
foAIstate.report_system_threats()
print("Calling AI Modules")
# call AI modules
action_list = [ColonisationAI.survey_universe,
ProductionAI.find_best_designs_this_turn,
PriorityAI.calculate_priorities,
ExplorationAI.assign_scouts_to_explore_systems,
ColonisationAI.assign_colony_fleets_to_colonise,
InvasionAI.assign_invasion_fleets_to_invade,
MilitaryAI.assign_military_fleets_to_systems,
FleetUtilsAI.generate_fleet_orders_for_fleet_missions,
FleetUtilsAI.issue_fleet_orders_for_fleet_missions,
ResearchAI.generate_research_orders,
ProductionAI.generateProductionOrders,
ResourcesAI.generate_resources_orders,
foAIstate.after_turn_cleanup,
]
for action in action_list:
try:
main_timer.start(action.__name__)
action()
main_timer.stop()
except Exception as e:
print_error(e, location=action.__name__)
main_timer.end()
turn_timer.end()
turn_timer.start("Server_Processing")
try:
fo.doneTurn()
except Exception as e:
print_error(e) # TODO move it to cycle above
if using_statprof:
try:
statprof.stop()
statprof.display()
statprof.start()
except:
pass