def output(bpf, fmt="plain"): if fmt == "plain": print() print("mmap:") for (k, v) in bpf.get_table('mmap_size').items(): size = utils.size(v.value) name = k.name.decode("ascii") if not name.startswith("postgres"): return print("[{}]: {}".format(k.pid, size)) print("anon shm:") for (k, v) in bpf.get_table('anon_shm_size').items(): size = utils.size(v.value) name = k.name.decode("ascii") if not name.startswith("postgres"): return print("[{}]: {}".format(k.pid, size)) print("shm:") for (k, v) in bpf.get_table('shm_size').items(): size = utils.size(v.value) name = k.name.decode("ascii") if not name.startswith("postgres"): return print("[{}]: {}".format(k.file.decode("ascii"), size)) bpf.get_table('mmap_size').clear() bpf.get_table('shm_size').clear() bpf.get_table('anon_shm_size').clear()
def wait_for_nzf(folder, sab_nzo_id, nzf): log("wait_for_nzf: folder: %s sab_nzo_id: %s nzf.filename: %s" % (folder, sab_nzo_id, nzf.filename)) iscanceled = False is_rar_found = False # If rar exist we skip dialogs some_rar = os.path.join(folder, nzf.filename) if utils.exists(some_rar): is_rar_found = True if not is_rar_found: progressDialog = xbmcgui.DialogProgress() progressDialog.create('Pneumatic', 'Request to SABnzbd succeeded, waiting for ', utils.short_string(nzf.filename)) time_now = time.time() while not is_rar_found: time.sleep(1) if utils.exists(some_rar): # TODO Look for optimization # Wait until the file is written to disk before proceeding size_now = float(nzf.bytes) size_later = 0 while (size_now != size_later) or (size_now == 0) or (size_later == 0): size_now = utils.size(some_rar) if size_now != size_later: time.sleep(0.5) size_later = utils.size(some_rar) is_rar_found = True break nzo = Nzo(sab_nzo_id) m_nzf = nzo.get_nzf_id(nzf.nzf_id) percent, label = utils.wait_for_rar_label(nzo, m_nzf, time_now) progressDialog.update(percent, 'Request to SABnzbd succeeded, waiting for', utils.short_string(nzf.filename), label) if progressDialog.iscanceled(): progressDialog.close() dialog = xbmcgui.Dialog() ret = dialog.select('What do you want to do?', ['Delete job', 'Just download']) # Fix for hang when playing .strm xbmc.Player().stop() xbmc.executebuiltin('Dialog.Close(all, true)') if ret == 0: sabnzbd.nzo_pause(sab_nzo_id) time.sleep(3) delete_ = sabnzbd.nzo_delete_files(sab_nzo_id) if not "ok" in delete_: xbmc.log(delete_) utils.notification("Deleting failed") else: utils.notification("Deleting succeeded") elif ret == 1: # allow the previous select dialog to close time.sleep(1) just_download({'nzoid': sab_nzo_id}) return True progressDialog.close() return iscanceled
def wait_for_nzf(folder, sab_nzo_id, nzf): log("wait_for_nzf: folder: %s sab_nzo_id: %s nzf.filename: %s" % (folder, sab_nzo_id, nzf.filename)) iscanceled = False is_rar_found = False # If rar exist we skip dialogs some_rar = os.path.join(folder, nzf.filename) if utils.exists(some_rar): is_rar_found = True if not is_rar_found: progressDialog = xbmcgui.DialogProgress() progressDialog.create('Pneumatic', 'Request to SABnzbd succeeded, waiting for ', utils.short_string(nzf.filename)) time_now = time.time() while not is_rar_found: time.sleep(1) if utils.exists(some_rar): # TODO Look for optimization # Wait until the file is written to disk before proceeding size_now = int(nzf.bytes) size_later = 0 while (size_now != size_later) or (size_now == 0) or (size_later == 0): size_now = utils.size(some_rar) if size_now != size_later: time.sleep(0.5) size_later = utils.size(some_rar) is_rar_found = True break nzo = sabnzbd.Nzo(SABNZBD, sab_nzo_id) m_nzf = nzo.get_nzf_id(nzf.nzf_id) percent, label = utils.wait_for_rar_label(nzo, m_nzf, time_now) progressDialog.update(percent, 'Request to SABnzbd succeeded, waiting for', utils.short_string(nzf.filename), label) if progressDialog.iscanceled(): progressDialog.close() dialog = xbmcgui.Dialog() ret = dialog.select('What do you want to do?', ['Delete job', 'Just download']) # Fix for hang when playing .strm xbmc.Player().stop() xbmc.executebuiltin('Dialog.Close(all, true)') if ret == 0: pause = SABNZBD.pause_queue(id=sab_nzo_id) time.sleep(3) delete_ = SABNZBD.delete_queue('',sab_nzo_id) if not "ok" in delete_: xbmc.log(delete_) utils.notification("Deleting failed") else: utils.notification("Deleting succeeded") elif ret == 1: # allow the previous select dialog to close time.sleep(1) just_download({'nzoid': sab_nzo_id}) return True progressDialog.close() return iscanceled
def run(args): print("Attaching...") debug = 4 if args.debug else 0 bpf = BPF(text=text, debug=debug) attach(bpf, args) exiting = False def print_event(cpu, data, size): event = ct.cast(data, ct.POINTER(Data)).contents name = event.name.decode("ascii", "ignore") if not name.startswith("postgres"): return print("Event: pid {} category {} size {}".format( event.pid, event_category(bpf, event.user_stack_id, event.pid), event.size)) print_stack(bpf, event.user_stack_id, event.pid) print("Listening...") while True: try: sleep(1) except KeyboardInterrupt: exiting = True # as cleanup can take many seconds, trap Ctrl-C: signal.signal(signal.SIGINT, signal_ignore) if exiting: print() print("Detaching...") print() break data = {} for (k, v) in bpf.get_table('write_size').items(): if not k.name.decode("ascii", "ignore").startswith("postgres"): continue action, process = event_category(bpf, k.user_stack_id, k.tgid) category = "{},{}".format(process, action) data[category] = data.get(category, 0) + v.value if args.debug: print("[{}:{}:{}] {}: {}".format( k.name, k.pid, k.user_stack_id, event_category(bpf, k.user_stack_id, k.tgid), utils.size(v.value))) print_stack(bpf, k.user_stack_id, k.tgid) for category, written in data.items(): print("{}: {}".format(category, utils.size(written)))
def printJets(self, eventVars=None, params=None, coords=None, jets=None, nMax=None, highlight=False): self.prepareText(params, coords) self.printText(jets) headers = "bbt pT eta phi Mass" self.printText(headers) self.printText("-" * len(headers)) nJets = utils.size(eventVars, jets) for iJet in range(nJets): if nMax <= iJet: self.printText("[%d more not listed]" % (nJets - nMax)) break jet = eventVars[jets].At(iJet) out = "" out += "2" if jet.BTag & 0x2 else " " out += "1" if jet.BTag & 0x1 else " " out += "t" if jet.TauTag else " " out += " %5.0f %4.1f %4.1f %5.0f" % (jet.PT, jet.Eta, jet.Phi, jet.Mass) color = r.kBlack if highlight: for jetsHighlight, indicesHighlight, colorHighlight, _, _ in self.jetIndices: if jetsHighlight != jets: continue if (indicesHighlight in eventVars) and (iJet in eventVars[indicesHighlight]): color = colorHighlight self.printText(out, color)
def printTracks(self, eventVars=None, params=None, coords=None, nMax=None, tracks=None, color=r.kBlack): self.prepareText(params, coords) self.printText(tracks) headers = " name pdgId pT eta phi" self.printText(headers) self.printText("-" * len(headers)) nTracks = utils.size(eventVars, tracks) for iTrack in range(nTracks): if nMax <= iTrack: self.printText("[%d more not listed]" % (nTracks - nMax)) break track = eventVars[tracks][iTrack] name = pdgLookup.pdgid_to_name(track.PID) if pdgLookupExists else "" self.printText("%6s %6d%5.0f %s %4.1f" % (name[-6:], track.PID, track.PT, utils.eta(track), track.Phi, ), color=color) return
def output(bpf, fmt="plain"): if fmt == "plain": print() for (k, v) in bpf.get_table('wal_records').items(): query = k.query.decode("ascii", "ignore") print("[{}:{}] {}: {}".format(k.pid, k.namespace, query, utils.size(v.value)))
def printLeptons(self, eventVars=None, params=None, coords=None, nMax=None, leptons=None, color=r.kBlack, ptMin=None): self.prepareText(params, coords) self.printText(leptons) headers = " pT eta phi iso" self.printText(headers) self.printText("-" * len(headers)) nLeptons = utils.size(eventVars, leptons) for iLepton in range(nLeptons): if nMax <= iLepton: self.printText("[%d more not listed]" % (nLeptons - nMax)) break lepton = eventVars[leptons][iLepton] iso = "%4.1f" % lepton.IsolationVar if hasattr( lepton, "IsolationVar") else " " self.printText("%5.0f %s %4.1f %s" % ( lepton.PT, utils.eta(lepton), lepton.Phi, iso, ), color=color) return
def printTowers(self, eventVars=None, params=None, coords=None, nMax=None, towers=None, color=r.kBlack): self.prepareText(params, coords) self.printText(towers) headers = " ET eta phi" self.printText(headers) self.printText("-" * len(headers)) nTowers = utils.size(eventVars, towers) for iTower in range(nTowers): if nMax <= iTower: self.printText("[%d more not listed]" % (nTowers - nMax)) break tower = eventVars[towers][iTower] self.printText("%5.0f %s %4.1f" % ( tower.ET, utils.eta(tower), tower.Phi, ), color=color) return
def printTracks(self, eventVars=None, params=None, coords=None, nMax=None, tracks=None, color=r.kBlack): self.prepareText(params, coords) self.printText(tracks) headers = " name pdgId pT eta phi" self.printText(headers) self.printText("-" * len(headers)) nTracks = utils.size(eventVars, tracks) for iTrack in range(nTracks): if nMax <= iTrack: self.printText("[%d more not listed]" % (nTracks - nMax)) break track = eventVars[tracks][iTrack] name = pdgLookup.pdgid_to_name( track.PID) if pdgLookupExists else "" self.printText("%6s %6d%5.0f %s %4.1f" % ( name[-6:], track.PID, track.PT, utils.eta(track), track.Phi, ), color=color) return
def printGenParticles(self, eventVars=None, params=None, coords=None, nMax=None, particles=None, color=r.kBlack): self.prepareText(params, coords) self.printText(particles) headers = " name pdgId pT eta phi st PU" self.printText(headers) self.printText("-" * len(headers)) nParticles = utils.size(eventVars, particles) for iParticle in range(nParticles): if nMax <= iParticle: self.printText("[%d more not listed]" % (nParticles - nMax)) break particle = eventVars[particles].At(iParticle) name = pdgLookup.pdgid_to_name( particle.PID) if pdgLookupExists else "" self.printText("%6s %6d%5.0f %s %4.1f %1d %1d" % ( name[-6:], particle.PID, particle.PT, utils.eta(particle), particle.Phi, particle.Status, particle.IsPU, ), color=color) return
def run(args): print("Attaching...") debug = 4 if args.debug else 0 bpf = BPF(text=bpf_text, debug=debug) attach(bpf) exiting = False if args.debug: bpf["events"].open_perf_buffer(print_event) print("Listening...") while True: try: sleep(1) if args.debug: bpf.perf_buffer_poll() except KeyboardInterrupt: exiting = True # as cleanup can take many seconds, trap Ctrl-C: signal.signal(signal.SIGINT, signal_ignore) if exiting: print() print("Detaching...") print() break print("Total") for (k, v) in bpf.get_table("net_data_hash").items(): print('{}: {}'.format(k.device.decode("ascii"), utils.size(v.value)))
def printGenParticles(self, eventVars=None, params=None, coords=None, nMax=None, particles=None, color=r.kBlack): self.prepareText(params, coords) self.printText(particles) headers = " name pdgId pT eta phi st PU" self.printText(headers) self.printText("-" * len(headers)) nParticles = utils.size(eventVars, particles) for iParticle in range(nParticles): if nMax <= iParticle: self.printText("[%d more not listed]" % (nParticles - nMax)) break particle = eventVars[particles].At(iParticle) name = pdgLookup.pdgid_to_name(particle.PID) if pdgLookupExists else "" self.printText("%6s %6d%5.0f %s %4.1f %1d %1d" % (name[-6:], particle.PID, particle.PT, utils.eta(particle), particle.Phi, particle.Status, particle.IsPU, ), color=color) return
def print_result(name, table): print(name) for (k, v) in table.items(): if k.name == b"postgres": backend = k.query.decode("ascii") or get_pid_cmdline(k.pid) print("[{}:{}] {}: {}".format( k.pid, k.namespace, backend, utils.size(v.value))) print()
def output(bpf, fmt="plain"): if fmt == "plain": print() for (k, v) in bpf.get_table('query_stacks').items(): if stack_from_wal(bpf, k.user_stack_id, k.pid): print("[{}:{}], {}, len: {}".format(k.pid, k.namespace, k.name, utils.size(v.value))) print_stack(bpf, k.user_stack_id, k.pid)
def output(bpf, fmt="plain"): if fmt == "plain": print() for (k, v) in bpf.get_table('reclaim').items(): name = k.name.decode("ascii") if not name.startswith("postgres"): return size = utils.size(v.value * PAGE_SIZE) print("[{}] {}: {}".format(k.pid, k.name, size)) bpf.get_table('reclaim').clear()
def uponAcceptance(self, eventVars): for iObject in range(utils.size(eventVars, self.var)): object = eventVars[self.var][iObject] if (self.maxIndex is not None) and self.maxIndex < i: continue key = self.attr yTitle = self.var if self.labelIndex: key += " (%s %d)" % (self.var, iObject) yTitle = "Events" value = getattr(object, self.attr) if self.func: value = value() self.book.fill(value, key, *self.bins, title=";%s;%s / bin" % (key, yTitle))
def update(self, _): self.value = [] particles = self.source[self.key] for iParticle in range(utils.size(self.source, self.key)): particle = particles[iParticle] if self.pids and (particle.PID not in self.pids): continue if self.status and (particle.Status not in self.status): continue if self.ptMin and (getattr(particle, self.pt) < self.ptMin): continue if self.absEtaMax and (self.absEtaMax < abs(particle.Eta)): continue self.value.append(iParticle if self.indices else particle) if self.ptSort: self.value.sort(key=lambda x:getattr(x, self.pt), reverse=True)
def update(self, _): self.value = [] particles = self.source[self.key] for iParticle in range(utils.size(self.source, self.key)): particle = particles[iParticle] if self.pids and (particle.PID not in self.pids): continue if self.status and (particle.Status not in self.status): continue if self.ptMin and (getattr(particle, self.pt) < self.ptMin): continue if self.absEtaMax and (self.absEtaMax < abs(particle.Eta)): continue self.value.append(iParticle if self.indices else particle) if self.ptSort: self.value.sort(key=lambda x: getattr(x, self.pt), reverse=True)
def requiredMaterials(typeID, componentsOnly=False, manufSize=None): """return the component materials needed for manufSize number of items""" bpItems = utils.getBlueprintsItems(typeID) if not manufSize: manufSize = utils.size(typeID)[1] #modify runs if they are negative (i.e, if a bpo is available) for bp in bpItems: ME = bp[0] runs = bp[1] if runs == -1: #bpos have -1 runs bpItems = [[ME, 10000000]] break #logic that decides which bpc to use given the amount of things to produce sortedBPCs = sorted(bpItems, key=lambda x: x[0], reverse=True) totalMaterialCost = {} for BP in sortedBPCs: ME = BP[0] runs = BP[1] if manufSize - runs > 0: modMaterialCost = modifiedMaterials(typeID, runs, ME) for matID in modMaterialCost: if componentsOnly and not utils.buildable(matID): continue totalMaterialCost = utils.integrate(totalMaterialCost, matID, modMaterialCost[matID]) manufSize = manufSize - runs elif manufSize - runs <= 0: modMaterialCost = modifiedMaterials(typeID, manufSize, ME) for matID in modMaterialCost: if componentsOnly and not utils.buildable(matID): continue totalMaterialCost = utils.integrate(totalMaterialCost, matID, modMaterialCost[matID]) break return totalMaterialCost
def printTowers(self, eventVars=None, params=None, coords=None, nMax=None, towers=None, color=r.kBlack): self.prepareText(params, coords) self.printText(towers) headers = " ET eta phi" self.printText(headers) self.printText("-" * len(headers)) nTowers = utils.size(eventVars, towers) for iTower in range(nTowers): if nMax <= iTower: self.printText("[%d more not listed]" % (nTowers - nMax)) break tower = eventVars[towers][iTower] self.printText("%5.0f %s %4.1f" % (tower.ET, utils.eta(tower), tower.Phi, ), color=color) return
def printLeptons(self, eventVars=None, params=None, coords=None, nMax=None, leptons=None, color=r.kBlack, ptMin=None): self.prepareText(params, coords) self.printText(leptons) headers = " pT eta phi iso" self.printText(headers) self.printText("-" * len(headers)) nLeptons = utils.size(eventVars, leptons) for iLepton in range(nLeptons): if nMax <= iLepton: self.printText("[%d more not listed]" % (nLeptons - nMax)) break lepton = eventVars[leptons][iLepton] iso = "%4.1f" % lepton.IsolationVar if hasattr(lepton, "IsolationVar") else " " self.printText("%5.0f %s %4.1f %s" % (lepton.PT, utils.eta(lepton), lepton.Phi, iso, ), color=color) return
def size(self): return utils.size(self.path)
def generate_html_file(term, results): html = """ <html> <head> <title>MyBay - Search results for "{0}"</title> <style> h1 {{ font-family: Georgia, serif; }} table.table2{{ font-family: Georgia, serif; font-size: 18px; font-style: normal; font-weight: normal; line-height: 1.2em; border-collapse:collapse; text-align:center; width: 100%; }} .table2 thead th, .table2 tfoot td{{ padding:20px 10px 40px 10px; color:#fff; font-size: 26px; background-color:#222; font-weight:normal; border-right:1px dotted #666; border-top:3px solid #666; -moz-box-shadow:0px -1px 4px #000; -webkit-box-shadow:0px -1px 4px #000; box-shadow:0px -1px 4px #000; text-shadow:0px 0px 1px #fff; text-shadow:1px 1px 1px #000; }} .table2 tfoot th{{ padding:10px; font-size:18px; text-transform:uppercase; color:#888; }} .table2 tfoot td{{ font-size:36px; color:#EF870E; border-top:none; border-bottom:3px solid #666; -moz-box-shadow:0px 1px 4px #000; -webkit-box-shadow:0px 1px 4px #000; box-shadow:0px 1px 4px #000; }} .table2 thead th:empty{{ background:transparent; -moz-box-shadow:none; -webkit-box-shadow:none; box-shadow:none; }} .table2 thead :nth-last-child(1){{ border-right:none; }} .table2 thead :first-child, .table2 tbody :nth-last-child(1){{ border:none; }} .table2 tbody th{{ text-align:left; padding:10px; color:#333; text-shadow:1px 1px 1px #ccc; background-color:#f9f9f9; }} .table2 tbody td{{ padding:10px; background-color:#f0f0f0; border-right:1px dotted #999; text-shadow:-1px 1px 1px #fff; color:#333; }} </style> </head> <body> <h1>MyBay - Search results for "{0}"</h1> <table class="table2"> <tr> <th>Name</th> <th>Size</th> <th>SE</th> <th>LE</th> </tr> """.format(term) for result in results: html += """ <tr> <td> <a href="magnet:?xt=urn:btih:{1}"> {0} </a> </td> <td>{2}</td> <td>{3}</td> <td>{4}</td> </tr> """.format(result[0], result[1], size(result[2]), str(result[4]), str(result[5])) html += """ </table> </body> </html> """ # Create temp HTML file f = tempfile.NamedTemporaryFile(delete=False, suffix='.html') f.write(html) name = f.name f.close() return name
help = 'File to append the numerical data to (after converting to a string).', ) return p.parse_args() if __name__ == "__main__": o = parse_args() data = None if not o.quiet or o.verbose: data = bc.load_json(filepath=o.path,verbose=-2) print o.graph sites, values, datetimes = bc.parse_query(o.graph) print 'sites',sites print 'values',values rows = bc.retrieve_data(sites,values,datetimes) NM = size(rows) assert NM[1]>=NM[0], size(rows) #cols = bc.transpose_lists(rows) bc.display_correlation(rows=rows, labels=o.graph, leads=o.lead) #bc.plot_data(columns=cols,normalize=True) if not o.nomine: # mine hard-coded urls d = dict() if type(o.urls)==dict: # TODO: this check and "iterification" of mine_data() should happen inside the function # check to see if all the dictionary keys look like urls if bc.are_all_urls(o.urls): for u,r in o.urls.items():