bool AdminRequestHandler::handleHeapProfilerRequest(const std::string &cmd,
                                                    Transport *transport) {
  string root = RuntimeOption::ProfilerOutputDir + "/" +
    Process::HostName;
  string file = root + "/hphp.prof";

  if (cmd == "prof-heap-on") {
    if (IsHeapProfilerRunning()) {
      transport->sendString("HeapProfiler is already running.\n");
    } else {
      if (Util::mkdir(file)) {
        // clean up leftovers
        string cmd = "/bin/rm -f ";
        cmd += file + ".*.heap";
        Util::ssystem(cmd.c_str());

        HeapProfilerStart(file.c_str());
        HeapProfilerDump("start");
        transport->sendString("OK\n");
      } else {
        transport->sendString("Unable to mkdir for profile data.\n");
      }
    }
    return true;
  }
  if (cmd == "prof-heap-dump") {
    if (!IsHeapProfilerRunning()) {
      transport->sendString("HeapProfiler is not running.\n");
    } else {
      HeapProfilerDump("end");
      transport->sendString("OK\n");
    }
    return true;
  }
  if (cmd == "prof-heap-off") {
    if (!IsHeapProfilerRunning()) {
      transport->sendString("HeapProfiler is not running.\n");
    } else {
      HeapProfilerDump("end");
      HeapProfilerStop();
      transport->sendString("OK\n");

      const char *argv[] = {"", root.c_str(), "-name", "*.heap", NULL};
      string files;
      Process::Exec("find", argv, NULL, files);
      vector<string> out;
      Util::split('\n', files.c_str(), out, true);
      if (out.size() > 1) {
        string base = "--base=";
        base += out[0];
        pprof(out[out.size() - 1], base.c_str());
      } else {
        Logger::Error("Unable to find heap profiler output");
      }
    }
    return true;
  }
  return false;
}
示例#2
0
static void stop_cb (flux_t *h, flux_msg_handler_t *mh,
                     const flux_msg_t *msg, void *arg)
{
    if (flux_request_decode (msg, NULL, NULL) < 0)
        goto error;
#if WITH_TCMALLOC
    if (!IsHeapProfilerRunning ()) {
        errno = EINVAL;
        goto error;
    }
    HeapProfilerStop();
#else
    errno = ENOSYS;
    goto error;
#endif /* WITH_TCMALLOC */
    if (flux_respond (h, msg, 0, NULL) < 0)
        FLUX_LOG_ERROR (h);
    return;
error:
    if (flux_respond (h, msg, errno, NULL) < 0)
        FLUX_LOG_ERROR (h);
}
示例#3
0
static void dump_cb (flux_t *h, flux_msg_handler_t *mh,
                     const flux_msg_t *msg, void *arg)
{
    const char *reason;

    if (flux_request_unpack (msg, NULL, "{s:s}", "reason", &reason) < 0)
        goto error;
#if WITH_TCMALLOC
    if (!IsHeapProfilerRunning ()) {
        errno = EINVAL;
        goto error;
    }
    HeapProfilerDump (reason);
#else
    errno = ENOSYS;
    goto error;
#endif
    if (flux_respond (h, msg, 0, NULL) < 0)
        FLUX_LOG_ERROR (h);
    return;
error:
    if (flux_respond (h, msg, errno, NULL) < 0)
        FLUX_LOG_ERROR (h);
}
示例#4
0
static void start_cb (flux_t *h, flux_msg_handler_t *mh,
                      const flux_msg_t *msg, void *arg)
{
    const char *filename;

    if (flux_request_unpack (msg, NULL, "{s:s}", "filename", &filename) < 0)
        goto error;
#if WITH_TCMALLOC
    if (IsHeapProfilerRunning ()) {
        errno = EINVAL;
        goto error;
    }
    HeapProfilerStart (filename);
#else
    errno = ENOSYS;
    goto error;
#endif
    if (flux_respond (h, msg, 0, NULL) < 0)
        FLUX_LOG_ERROR (h);
    return;
error:
    if (flux_respond (h, msg, errno, NULL) < 0)
        FLUX_LOG_ERROR (h);
}
示例#5
0
void read_mRNAs(FILE* f, GList<GSeqData>& seqdata, GList<GSeqData>* ref_data,
	         int check_for_dups, int qfidx, const char* fname, bool only_multiexon) {
	//>>>>> read all transcripts/features from a GTF/GFF3 file
	//int imrna_counter=0;
#ifdef HEAPROFILE
    if (IsHeapProfilerRunning())
      HeapProfilerDump("00");
#endif
	int loci_counter=0;
	if (ref_data==NULL) ref_data=&seqdata;
	bool isRefData=(&seqdata==ref_data);
	                          //(f, transcripts_only)
	GffReader* gffr=new GffReader(f, true); //load only transcript annotations
	gffr->showWarnings(gtf_tracking_verbose);
	//            keepAttrs   mergeCloseExons   noExonAttrs
	gffr->readAll(!isRefData,          true,        isRefData || gtf_tracking_largeScale);
	//so it will read exon attributes only for low number of Cufflinks files
#ifdef HEAPROFILE
    if (IsHeapProfilerRunning())
      HeapProfilerDump("post_readAll");
#endif

	int d=parse_mRNAs(gffr->gflst, seqdata, isRefData, check_for_dups, qfidx,only_multiexon);
#ifdef HEAPROFILE
    if (IsHeapProfilerRunning())
      HeapProfilerDump("post_parse_mRNAs");
#endif
	if (gtf_tracking_verbose && d>0) {
	  if (isRefData) GMessage(" %d duplicate reference transcripts discarded.\n",d);
	            else GMessage(" %d redundant query transfrags discarded.\n",d);
	  }
	//imrna_counter=gffr->mrnas.Count();
	delete gffr; //free the extra memory and unused GffObjs
#ifdef HEAPROFILE
    if (IsHeapProfilerRunning())
      HeapProfilerDump("post_del_gffr");
#endif
	
	//for each genomic sequence, cluster transcripts
	int oriented_by_overlap=0;
	int initial_unoriented=0;
	int final_unoriented=0;
	GStr bname(fname);
	GStr s;
	if (!bname.is_empty()) {
		int di=bname.rindex('.');
		if (di>0) bname.cut(di);
		int p=bname.rindex('/');
		if (p<0) p=bname.rindex('\\');
		if (p>=0) bname.remove(0,p);
	}
	FILE* fdis=NULL;
	FILE* frloci=NULL;

	for (int g=0;g<seqdata.Count();g++) {
		//find the corresponding refseqdata with the same gseq_id
		int gseq_id=seqdata[g]->get_gseqid();
		if (!isRefData) { //query data, find corresponding ref data
			GSeqData* rdata=getRefData(gseq_id, *ref_data);
			initial_unoriented+=seqdata[g]->umrnas.Count();
			if (seqdata[g]->umrnas.Count()>0) {
			    oriented_by_overlap+=fix_umrnas(*seqdata[g], rdata, fdis);
			    final_unoriented+=seqdata[g]->umrnas.Count();
			    }
			}
		//>>>>> group mRNAs into locus-clusters (based on exon overlap)
		cluster_mRNAs(seqdata[g]->mrnas_f, seqdata[g]->loci_f, qfidx);
		cluster_mRNAs(seqdata[g]->mrnas_r, seqdata[g]->loci_r, qfidx);
		if (!isRefData) {
			cluster_mRNAs(seqdata[g]->umrnas, seqdata[g]->nloci_u, qfidx);
			}
		loci_counter+=seqdata[g]->loci_f.Count();
		loci_counter+=seqdata[g]->loci_r.Count();
//		if (refData) {
//			if (frloci==NULL) {
//				s=bname;
//				s.append(".loci.lst");
//				frloci=fopen(s.chars(), "w");
//			}
//			writeLoci(frloci, seqdata[g]->loci_f);
//			writeLoci(frloci, seqdata[g]->loci_r);
//		}//write ref loci
	}//for each genomic sequence
	if (fdis!=NULL) fclose(fdis);
	if (frloci!=NULL) fclose(frloci);
	if (initial_unoriented || final_unoriented) {
	  if (gtf_tracking_verbose) GMessage(" Found %d transfrags with undetermined strand (%d out of initial %d were fixed by overlaps)\n",
			    final_unoriented, oriented_by_overlap, initial_unoriented);
	}
	//if (fdis!=NULL) remove(s.chars()); remove 0-length file
#ifdef HEAPROFILE
    if (IsHeapProfilerRunning())
      HeapProfilerDump("post_cluster");
#endif
}
示例#6
0
// static
bool LLAllocator::isProfiling()
{
    return IsHeapProfilerRunning();
}