def __init__(self): self.initTime = 0 self.endTime = 0 self.obj_tr = tracker.SummaryTracker() self.cls_tr = classtracker.ClassTracker() self.output_snap = len( [name for name in os.listdir('.') if os.path.isfile(name)])
def __init__(self, get_response): """Construct and configure the middleware, one time.""" if PYMPLER_ENABLED and not settings.DEBUG: self.memory_tracker = tracker.SummaryTracker() self.class_tracker = classtracker.ClassTracker() self.class_tracker.track_class(Template) self.object_count = len(muppy.get_objects()) self.get_response = get_response else: raise MiddlewareNotUsed('PymplerMiddleware will not be used.')
def profile_memory(args, reference_dict, db_genes_metrics, transcripts_metrics, separated_reports, comparison_report, logger): try: from pympler import classtracker from pympler import asizeof logger.print_timestamp() logger.info('Memory profile:') tracker = classtracker.ClassTracker() if args.reference is not None: logger.info('reference_dict [bit]\t' + str(asizeof.asizeof(reference_dict))) if args.gtf is not None or args.gene_db: tracker.track_object(db_genes_metrics) for i_transcripts in range(len(transcripts_metrics)): if args.transcripts is not None: tracker.track_object( transcripts_metrics[i_transcripts].basic_metrics) if args.alignment is not None and args.reference is not None and args.transcripts is not None: tracker.track_object( transcripts_metrics[i_transcripts].simple_metrics) if (args.gtf is not None or args.gene_db is not None) \ and args.alignment is not None and args.reference is not None and args.transcripts is not None: tracker.track_object(transcripts_metrics[i_transcripts]. assembly_correctness_metrics) tracker.track_object( transcripts_metrics[i_transcripts]. assembly_completeness_metrics.exons_coverage) tracker.track_object( transcripts_metrics[i_transcripts]. assembly_completeness_metrics.isoforms_coverage) tracker.track_object(transcripts_metrics[i_transcripts]. assembly_completeness_metrics) tracker.track_object(separated_reports[i_transcripts]) if comparison_report is not None: tracker.track_object(comparison_report) tracker.create_snapshot() tracker.stats.print_summary() except Exception: logger.warning('Can\'t profile memory: please install Pympler.')
def class_tracker(self): """Get class tracker object. Example: >>> tr = j.tools.memprof.class_tracker() >>> tr.track_class(Document) >>> tr.create_snapshot() >>> create_documents() >>> tr.create_snapshot() >>> tr.stats.print_summary() active 1.42 MB average pct Document 1000 195.38 KB 200 B 13% """ return classtracker.ClassTracker()
def start_memory_profiling(): ''' Sets-up some tracking statements from pympler IN: NONE OUT: tr - SummaryTracker - SummaryTracker object for the whole run tr_sm - ClassTrackers - ClassTracker object of SeriesModel ''' tr = tracker.SummaryTracker() tr_sm = classtracker.ClassTracker() tr_sm.track_class(SeriesModel) tr_sm.create_snapshot() return tr, tr_sm
def main(): cltr = classtracker.ClassTracker() cltr.track_class(GroupLst) cltr.create_snapshot() # Needed for the specified command line arguments parser = argparse.ArgumentParser() parser.add_argument('-i', type=str, default="bench_2.net", help='What is the input filename?') args = parser.parse_args() # Load the input data and generate the graph graph, num_cells, num_nets = data_load(args.i) # Instantiate GroupLst Sol, nSol = GroupLst(graph, num_cells), GroupLst(graph, num_cells) print("Graph Created") # Report the memory size cltr.create_snapshot() cltr.stats.print_summary()
def start(self): self._tracker = tracker.SummaryTracker() self._aliceTracker = classtracker.ClassTracker() self._aliceTracker.track_class(ProjectAliceObject)
# Tracking object lifetime from pympler import classtracker class Document: title = 1 tr = classtracker.ClassTracker() tr.track_class(Document) tr.create_snapshot() d1 = Document() tr.create_snapshot() d2 = Document() tr.create_snapshot() tr.stats.print_summary()
def simulatedAnnealing(graph, num_cells, params, fn): cltr = classtracker.ClassTracker() cltr.track_class( GroupLst) # Follow the memory size of the graph data struct. # Instantiate GroupLst objects curSol, nextSol = GroupLst(graph, num_cells), GroupLst(graph, num_cells) bestSol, bestCost = list(curSol.V), curSol.cost T = params["T0"] # Initial Temp # Initialize graphing variables last_time, total_time = time.time(), time.time() iter_cntr, tmp_cntr = 0, 0 iter_arr, temp_arr = [], [] best_cutset_arr, cutset_arr, t2_arr, boltz_arr, nam_arr = [], [], [], [], [] print_skip = 10 while T > params["Tfreeze"]: #While the temperature is above Tfreeze, num_accepted_moves = 0 # reset accepted moves counter for i in range(params["num_moves_per_T"]): # For the number of moves per T, # copy over the curSol into the nextSol. nextSol.V, nextSol.cost = list(curSol.V), curSol.cost nextSol.perturb() # Swap two random cells and update the cost. delCost = nextSol.cost - curSol.cost boltz, accept = acceptMove(delCost, T, num_cells) if accept: #If the move is accepted, copy nextSol back into curSol curSol.V, curSol.cost = list(nextSol.V), nextSol.cost num_accepted_moves += 1 if curSol.cost < bestCost: # If curSol is the best solution seen so far, upate bestSol. bestSol, bestCost = list(curSol.V), curSol.cost iter_cntr += 1 # Update graph data. Only once per temp to save space iter_arr.append(iter_cntr) t2_arr.append(T) temp_arr.append(T) cutset_arr.append(curSol.cost) best_cutset_arr.append(bestCost) nam_arr.append(num_accepted_moves) boltz_arr.append(boltz) tmp_cntr += 1 if tmp_cntr % print_skip == 0: # Give output every print_skip temp updates print("{} T: {} curCost: {}, num_accepted_moves: {}".format( tmp_cntr, T, curSol.cost, num_accepted_moves)) print('T step took {:0.3f} seconds'.format( (time.time() - last_time) / print_skip)) last_time = time.time() T = coolDown(T, params) # Plot the requisite graphs fig, ax = plt.subplots() ax.plot(temp_arr, cutset_arr, label="Cutset Size") ax.plot(temp_arr, best_cutset_arr, label="Best Cutset Size") ax.set_xlabel("Temperature") ax.set_ylabel("Cutset Size") ax.set_title("Cutset Size vs. Temperature") ax.legend() fig.set_size_inches(6, 4) fig.savefig("Images/{}_CS_v_T.png".format(fn), dpi=200) fig, ax = plt.subplots() ax.plot(iter_arr, t2_arr) ax.set_xlabel("Iteration") ax.set_ylabel("Temperature") ax.set_title("Temperature vs. Iteration") fig.set_size_inches(6, 4) fig.savefig("Images/{}_T_v_I.png".format(fn), dpi=200) fig, ax = plt.subplots() ax.plot(iter_arr, boltz_arr) ax.set_xlabel("Iteration") ax.set_ylabel("Boltz") ax.set_title("Boltz vs. Iteration") fig.set_size_inches(6, 4) fig.savefig("Images/{}_B_v_I.png".format(fn), dpi=200) fig, ax = plt.subplots() ax.plot(temp_arr, nam_arr) ax.set_xlabel("Temperature") ax.set_ylabel("Number of Accepted Moves") ax.set_title("Number of Accepted Moves vs. Temperature") fig.set_size_inches(6, 4) fig.savefig("Images/{}_NAM_v_T.png".format(fn), dpi=200) print("\n\nBest Cost: {}, temp iteration {}".format(bestCost, tmp_cntr)) print("Total Time {:0.3f} seconds".format(time.time() - total_time)) cltr.create_snapshot() cltr.stats.print_summary( ) #display the size of the instatiated GroupLst data structs return bestSol, bestCost