示例#1
0
void ShmSystemV::Close()
{
    ProfilerStart("close");
    int result = shmdt(m_Buffer);
    ProfilerStop("close");
    if (result < 1)
    {
        throw std::ios_base::failure(
            "ERROR: failed to detach shared memory segment of size " +
            std::to_string(m_Size) + " and name " + m_Name +
            ", in call to SystemV shmdt Close\n");
    }

    if (m_RemoveAtClose)
    {
        ProfilerStart("close");
        int remove = shmctl(m_ShmID, IPC_RMID, NULL);
        ProfilerStop("close");
        if (result < 1)
        {
            throw std::ios_base::failure(
                "ERROR: failed to remove shared memory segment of size " +
                std::to_string(m_Size) + " and name " + m_Name +
                ", in call to SystemV shmctl Close\n");
        }
    }

    m_IsOpen = false;
}
示例#2
0
void ShmSystemV::Read(char *buffer, size_t size, size_t start)
{
    CheckSizes(size, start, "in call to Read");
    ProfilerStart("read");
    std::memcpy(buffer, &m_Buffer[start], size);
    ProfilerStop("read");
}
示例#3
0
void ShmSystemV::Write(const char *buffer, size_t size, size_t start)
{
    CheckSizes(size, start, "in call to Write");
    ProfilerStart("write");
    std::memcpy(&m_Buffer[start], buffer, size);
    ProfilerStop("write");
}
示例#4
0
文件: main.c 项目: samphippen/lsquare
int main(int argc, const char* argv[]) {
    char* alphabet;

    bool verbose = false;
    if (argc == 2 && strcmp(argv[1], "-v") != 0) {
        alphabet = (char*) argv[1];
    } else if (argc == 3) {
        alphabet = (char*) argv[2];
        verbose = true;
    } else {
        alphabet = (char*) "abcdefghijklmnopqrstuvwxyz";
    }

//    char* alphabet = "abcdefghijklmnopqrstuvwxyz@";
//    bool verbose = false;


    latin_square* my_square = malloc(sizeof(latin_square));
    init_latin_square(alphabet, my_square);
    clock_t start = clock();
    #ifdef profile
    ProfilerStart("/tmp/bees.prof");
    #endif
    solve_latin_square(my_square, verbose);
    #ifdef profile
    ProfilerStop();
    #endif
    if (!verbose) print_latin_square(my_square);
    clock_t end = clock();
    return 0;
}
示例#5
0
static VALUE
cpuprofiler_start(VALUE self, VALUE filename)
{
  StringValue(filename);

  if (bProfilerRunning)
    rb_raise(eError, "profiler is already running");

  if (getenv("CPUPROFILE_OBJECTS"))
    objprofiler_setup();
  else if (getenv("CPUPROFILE_METHODS"))
    methprofiler_setup();

  if (ProfilerStart(RSTRING_PTR(filename))) {
    bProfilerRunning = Qtrue;
  } else {
    rb_raise(eError, "profiler could not be started");
  }

  if (rb_block_given_p()) {
    rb_yield(Qnil);
    cpuprofiler_stop(self);
  }

  return Qtrue;
}
示例#6
0
inline void start()
{
    #ifdef MGBASE_PROFILER_USE_GPERFTOOLS
        // TODO: file name management
        ProfilerStart("gperf.prof");
    #endif
}
void StartProfiling::executePlanOperation() {
  output = input;
#ifdef HYRISE_USE_GOOGLE_PROFILER
  ProfilerStart((Settings::getInstance()->getProfilePath() + "/profile_" + std::to_string(get_epoch_nanoseconds()) +
                 ".gprof").c_str());
#endif
}
示例#8
0
文件: mutool.c 项目: ccxvii/mupdf
int main(int argc, char **argv)
{
	int ret;
	ProfilerStart("mutool.prof");
	ret = profiled_main(argc, argv);
	ProfilerStop();
	return ret;
}
示例#9
0
int main(int argc, char** argv)
{
    ProfilerStart(argv[0]);
    testing::InitGoogleTest(&argc, argv);
    int n = RUN_ALL_TESTS();
    ProfilerStop();
    return n;
}
示例#10
0
void sig_profiler_start_handler(int sig)
{
  char * profile_output = getenv("PROFILEOUTPUT");
  if (NULL != profile_output)
  {
    ProfilerStart(profile_output);
    ProfilerRegisterThread();
  }
}
示例#11
0
void ShmSystemV::Open(const std::string &name, const Mode openMode)
{
    m_Name = name;
    CheckName();
    m_OpenMode = openMode;

    // not using const
    key_t key = ftok(m_Name.c_str(), static_cast<int>(m_ProjectID));

    switch (m_OpenMode)
    {
    case (Mode::Write):
        ProfilerStart("open");
        m_ShmID = shmget(key, m_Size, IPC_CREAT | 0666);
        ProfilerStop("open");
        break;

    case (Mode::Append):
        ProfilerStart("open");
        m_ShmID = shmget(key, m_Size, 0);
        ProfilerStop("open");
        break;

    case (Mode::Read):
        ProfilerStart("open");
        m_ShmID = shmget(key, m_Size, 0);
        ProfilerStop("open");
        break;

    default:
        throw std::invalid_argument(
            "ERROR: unknown open mode for shared memory segment " + m_Name +
            ", in call to SystemV Open");
    }

    CheckShmID("in call to ShmSystemV shmget at Open");

    m_Buffer = static_cast<char *>(shmat(m_ShmID, nullptr, 0));
    CheckBuffer("in call to SystemV shmat at Open");
    m_IsOpen = false;
}
示例#12
0
文件: amedit.c 项目: naihe2010/amblog
int
main (int argc, char *argv[])
{
  gchar *prgdir, *localedir;
  GtkWidget *window, *vbox, *editor; 

  prgdir = am_install_path ();
  if (prgdir)
    {
      localedir = g_build_filename (prgdir, AM_SYS_LOCALE_DIR, NULL);
      g_free (prgdir);
    }
  else
    {
      localedir = g_strdup (AM_SYS_LOCALE_DIR);
    }

  if (localedir)
    {
      setlocale (LC_ALL, "");
      bindtextdomain (PACKAGE, localedir);
      bind_textdomain_codeset (PACKAGE, "UTF-8");
      textdomain (PACKAGE);
      g_free (localedir);
    }

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "amedit 0.0.1");
  gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);

  vbox = gtk_vbox_new (FALSE, FALSE);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  editor = wiki_editor_new (NULL);
  gtk_box_pack_start (GTK_BOX (vbox), editor, TRUE, TRUE, 2);

  g_signal_connect (G_OBJECT (window), "destroy-event", G_CALLBACK (amedit_quit_ask), editor);
  g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (amedit_quit_ask), editor);

  gtk_widget_show_all (window);

#ifdef AMBLOG_ENABLE_PROFILER
  ProfilerStart ("amblog.prof");
#endif
  gtk_main ();
#ifdef AMBLOG_ENABLE_PROFILER
  ProfilerStop ();
#endif

  return 0;
}
示例#13
0
void mypaint_benchmark_start(const char *name)
{
    if (profiling_enabled()) {
#ifdef HAVE_GPERFTOOLS
        ProfilerStart(name);
#else
        fprintf(stderr, "Warning: Not built with gperftools support.\n");
#endif
    }

    g_start_time = get_time();
}
示例#14
0
int main(int argc, char* argv[]) {
	google::ParseCommandLineFlags(&argc, &argv, true);
	google::InitGoogleLogging(argv[0]);
	LOG(INFO) << "Running...";
	nicopp::DataSet dset(std::move(nicopp::DataSet::Load("compiled/tagf","compiled/vf","compiled/linkf")));
#ifdef DEBUG
	ProfilerStart ("prof.out");
#endif
	/*{
		long t = std::clock();
		bool run = true;
		Graph g;
		g.total_weight = totalLink;
		int degreeTotal = 0;
		for(unsigned int i=0;i<nodes.size();i++){
			nicopp::Node& node = nodes[i];
			degreeTotal += node.neighbors().size();
			g.degrees.emplace_back(degreeTotal);
			for(auto& kv : node.neighbors()){
				g.links.emplace_back(kv.first);
				g.weights.emplace_back(kv.second);
			}
		}
		g.nb_links = g.links.size();
		g.nb_nodes = nodes.size();
		for(;run;){
			int from = g.degrees.size();
			Community c(g, 10, 0);
			LOG(INFO) << g.degrees.size() << " / " << g.links.size() << " / " << g.weights.size() << " <> " << c.size;
			run = c.one_level();
			g = c.partition2graph_binary();
			LOG(INFO) << from << " -> " << g.degrees.size() << " Nodes";
		}
		LOG(INFO) << "Lap: " << (std::clock() - t);
	}*/
	{
		long t = std::clock();
		nicopp::TagGraph graph = dset.searchTag(0, 99999999999, 150000);
		for(int i=0;i<5;i++){
			LOG(INFO) << graph.nodes().size() << " nodes / " << graph.edges() << " edges";
			graph = std::move(graph.nextLevel(4, .0));
		}
		LOG(INFO) << "Lap: " << (std::clock() - t);
		for (auto const& node : graph.nodes()){
			LOG(INFO) << "  Node: " << dset.tag(node.payload().tagId) << " / "<< node.selfLoops() << "/"<<node.degree();
		}
	}
#ifdef DEBUG
	ProfilerStop ();
#endif
	return 0;
}
示例#15
0
int main(int argc, char** argv) {
#ifdef PROFILER
    ProfilerStart("uwsgi_server.prof");
#endif
    stats s;
    tasks::net::acceptor<uwsgi_handler> srv(12345);
    auto tasks = std::vector<tasks::task*>{&srv, &s};
    tasks::dispatcher::instance()->run(tasks);
#ifdef PROFILER
    ProfilerStop();
#endif
    return 0;
}
示例#16
0
文件: t.cpp 项目: despair1/czk
int main2() {
	ProfilerStart("test2.txt");
	std::ifstream myfile;
	myfile.open("test.txt");
	//myfile<<"wtf?";
	//get_pilot_json("90376921","201407120000",myfile);
	//fclose(fp);
	get_json(myfile);
	std::cout << "!!!Hello World!!!" << std::endl; // prints !!!Hello World!!!
	myfile.close();
	ProfilerStop();
	return 0;
}
// main entrance.
int main(int argc, char** argv) 
{
    int ret = ERROR_SUCCESS;
    
    // TODO: support both little and big endian.
    srs_assert(srs_is_little_endian());

#ifdef SRS_AUTO_GPERF_MP
    HeapProfilerStart("gperf.srs.gmp");
#endif
#ifdef SRS_AUTO_GPERF_CP
    ProfilerStart("gperf.srs.gcp");
#endif

#ifdef SRS_AUTO_GPERF_MC
    #ifdef SRS_AUTO_GPERF_MP
    srs_error("option --with-gmc confict with --with-gmp, "
        "@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n"
        "Note that since the heap-checker uses the heap-profiling framework internally, "
        "it is not possible to run both the heap-checker and heap profiler at the same time");
    return -1;
    #endif
#endif
    
    // never use srs log(srs_trace, srs_error, etc) before config parse the option,
    // which will load the log config and apply it.
    if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) {
        return ret;
    }
    
    // config parsed, initialize log.
    if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) {
        return ret;
    }
    
    srs_trace("srs(simple-rtmp-server) "RTMP_SIG_SRS_VERSION);
    srs_trace("license: "RTMP_SIG_SRS_LICENSE);
    srs_trace("uname: "SRS_AUTO_UNAME);
    srs_trace("build: %s, %s", SRS_AUTO_BUILD_DATE, srs_is_little_endian()? "little-endian":"big-endian");
    srs_trace("configure: "SRS_AUTO_USER_CONFIGURE);
    srs_trace("features: "SRS_AUTO_CONFIGURE);
#ifdef SRS_AUTO_ARM_UBUNTU12
    srs_trace("arm tool chain: "SRS_AUTO_EMBEDED_TOOL_CHAIN);
#endif
    
    if ((ret = _srs_server->initialize()) != ERROR_SUCCESS) {
        return ret;
    }
    
    return run();
}
示例#18
0
文件: Util.cpp 项目: absorbguo/Paddle
static void profilerSwitch(int signalNumber) {
  bool static started = false;

  if (!started) {
    if (ProfilerStart(FLAGS_profile_data_file.c_str())) {
      LOG(INFO) << "Profiler started";
    } else {
      LOG(WARNING) << "Can't turn on cpu profiling for "
                   << FLAGS_profile_data_file;
    }
  } else {
    ProfilerStop();
    LOG(INFO) << "Profiler stopped";
  }
  started = !started;
}
示例#19
0
文件: address.c 项目: 38/glimpse
int main()
{
#ifdef GPROF
	ProfilerStart("/tmp/scanner.prof");
#endif
	glimpse_init();
	Glimpse_TypeAPI_init();
	glimpse_pluginloader_path[0] = ".";
	glimpse_pluginloader_path[1] = "..";
	glimpse_pluginloader_path[2] = NULL;
	glimpse_pluginloader_load_plugin("integer");
	case0();
	glimpse_cleanup();
#ifdef GPROF
	ProfilerStop();
#endif
}
示例#20
0
void ExternalProfiler::start() {
	if (not this->can_profile) {
		log::log(MSG(err) << "Can not profile: gperftools is missing");
		return;
	}

	if (this->currently_profiling) {
		log::log(MSG(info) << "Profiler is already running");
		return;
	}

	log::log(MSG(info) << "Starting profiler; writing data to " << this->profiling_filename);

	this->currently_profiling = true;
	#if WITH_GPERFTOOLS_PROFILER
	ProfilerStart(this->profiling_filename);
	#endif
}
示例#21
0
int main( int ac, char** av )
{
    try
    {
        #ifdef WIN32
        _setmode( _fileno( stdout ), _O_BINARY );
        #endif
        comma::command_line_options options( ac, av );
        if( options.exists( "--help,-h" ) ) { usage(); }
        csv = comma::csv::options( options, "r,b,e" );
        foreground_threshold = options.value( "--foreground-threshold", 1.0 );
        min_points_per_partition = options.value( "--min-points-per-partition", 1u );
        verbose = options.exists( "--verbose,-v" );
        discard = options.exists( "--discard,-d" );
        output_all = options.exists( "--output-all" );
        ::tbb::filter_t< block_t*, block_t* > partition_filter( ::tbb::filter::serial_in_order, &partition_ );
        ::tbb::filter_t< block_t*, void > write_filter( ::tbb::filter::serial_in_order, &write_block_ );
        #ifdef PROFILE
        ProfilerStart( "points-foreground-partitions.prof" ); {
        #endif
        if( discard )
        {
            bursty_reader.reset( new snark::tbb::bursty_reader< block_t* >( &read_block_bursty_ ) );
            ::tbb::filter_t< void, void > filters = bursty_reader->filter() & partition_filter & write_filter;
            ::tbb::parallel_pipeline( 3, filters ); // while( bursty_reader->wait() ) { ::tbb::parallel_pipeline( 3, filters ); }
            bursty_reader->join();
        }
        else
        {
            ::tbb::filter_t< void, block_t* > read_filter( ::tbb::filter::serial_in_order, &read_block_ );
            ::tbb::filter_t< void, void > filters = read_filter & partition_filter & write_filter;
            ::tbb::parallel_pipeline( 3, filters );
        }
        #ifdef PROFILE
        ProfilerStop(); }
        #endif
        if( is_shutdown ) { std::cerr << "points-foreground-partitions: caught signal" << std::endl; }
        else { std::cerr << "points-foreground-partitions: end of stream" << std::endl; }
        return 0;
    }
    catch( std::exception& ex ) { std::cerr << "points-foreground-partitions: " << ex.what() << std::endl; }
    catch( ... ) { std::cerr << "points-foreground-partitions: unknown exception" << std::endl; }
    return 1;
}
示例#22
0
文件: Main.cpp 项目: poseidn/KungFoo
int main(int argc, const char* argv[]) {
	SDLInterfaceInitData sdlInitData;

	std::vector < std::string > opts;

	for (int i = 0; i < argc; i++) {
		opts.push_back(std::string(argv[i]));
	}

	// running fullscreen is default
	sdlInitData.Fullscreen = false;
	bool runDemoMode = false;
	bool muted = false;
	bool forwardScroll = false;
	bool withIntro = false;
/*
	if (commandline::handleCommandLine(sdlInitData, opts, runDemoMode, muted, forwardScroll, withIntro)
			== false)
		return 0;*/

	DescentFramework f(false, runDemoMode, muted, forwardScroll, withIntro, true);

	f.initRenderEngine(sdlInitData);

	// todo: make this a lot nicer, by templating the FW class
#ifdef USE_PROFILER
	ProfilerStart("GameLoop.perf");
#endif

	f.execute();

#ifdef USE_PROFILER
	ProfilerStop();
#endif

	// done globally here for all used SDL systems;
	SDL_Quit();

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

  if (cmd == "prof-cpu-on") {
    if (Util::mkdir(file)) {
      ProfilerStart(file.c_str());
      transport->sendString("OK\n");
    } else {
      transport->sendString("Unable to mkdir for profile data.\n");
    }
    return true;
  }
  if (cmd == "prof-cpu-off") {
    ProfilerStop();
    ProfilerFlush();
    transport->sendString("OK\n");
    return true;
  }
  return false;
}
示例#24
0
  // Starts the profiler. There are no request parameters.
  Future<http::Response> start(const http::Request& request)
  {
#ifdef HAS_GPERFTOOLS
    if (os::getenv("LIBPROCESS_ENABLE_PROFILER", false) != "1") {
      return http::BadRequest(
          "The profiler is not enabled. To enable the profiler, libprocess "
          "must be started with LIBPROCESS_ENABLE_PROFILER=1 in the "
          "environment.\n");
    }

    if (started) {
      return http::BadRequest("Profiler already started.\n");
    }

    LOG(INFO) << "Starting Profiler";

    // WARNING: If using libunwind < 1.0.1, profiling should not be used, as
    // there are reports of crashes.
    // WARNING: If using libunwind 1.0.1, profiling should not be turned on
    // when it's possible for new threads to be created.
    // This may cause a deadlock. The workaround used in libprocess is described
    // here:
    // https://groups.google.com/d/topic/google-perftools/Df10Uy4Djrg/discussion
    // NOTE: We have not tested this with libunwind > 1.0.1.
    if (!ProfilerStart(PROFILE_FILE.c_str())) {
      std::string error =
        strings::format("Failed to start profiler: %s", strerror(errno)).get();
      LOG(ERROR) << error;
      return http::InternalServerError(error);
    }

    started = true;
    return http::OK("Profiler started.\n");
#else
    return http::BadRequest(
        "Perftools is disabled. To enable perftools, "
        "configure libprocess with --enable-perftools.\n");
#endif
  }
示例#25
0
void DSPLLE::DSP_WriteMailBoxHigh(bool _CPUMailbox, u16 _uHighMail)
{
	if (_CPUMailbox)
	{
		if (gdsp_mbox_peek(GDSP_MBOX_CPU) & 0x80000000)
		{
			ERROR_LOG(DSPLLE, "Mailbox isnt empty ... strange");
		}

#if PROFILE
		if ((_uHighMail) == 0xBABE)
		{
			ProfilerStart();
		}
#endif

		gdsp_mbox_write_h(GDSP_MBOX_CPU, _uHighMail);
	}
	else
	{
		ERROR_LOG(DSPLLE, "CPU can't write to DSP mailbox");
	}
}
int main( int argc, char ** argv )
{
#ifdef GOOGLEPROF
	ProfilerStart("test.prof");
#endif

	// parse command line
	if ( argc > 1 ){
		time_to_run_s = atoi(argv[1]);
	}
	if ( argc > 2 ){
		thread_count = atoi(argv[2]);
	}

	printf("SIOX threaded performance test, please run it with and without SIOX instrumentation !\n");
	printf("Parameters: %d threads, %d seconds\n", thread_count, time_to_run_s);

	pthread_barrier_init( & barrier, NULL, thread_count );

	pthread_t thread[thread_count];
	for(int i=0; i < thread_count; i++){
		pthread_create(& thread[i], NULL, threadFunc, (void * restrict) i);
	}

	for(int i=0; i < thread_count; i++){
		void * data;
		pthread_join(thread[i], & data);
	}

	pthread_barrier_destroy( & barrier );

#ifdef GOOGLEPROF
        ProfilerStop("test.prof");
#endif
	return 0;
}
示例#27
0
int main(int argc, const char *argv[])
{
	fake * fk = newfake();

	// 解析参数
	int parseret = parsearg(fk, argc, argv);
	if (parseret != 0)
	{
		return parseret;
	}

	if (g_iscompiled)
	{
		fksetargv(fk, argc - 1, argv + 1);
	}
	else
	{
		fksetargv(fk, argc - 2, argv + 2);
	}
	fkopenalllib(fk);
	fkseterrorfunc(fk, error_log);

	// for test
	fkreg(fk, "test_cfunc1", test_cfunc1);
	fkreg(fk, "new_test_class1", new_test_class1);
	fkreg(fk, "new_test_class2", new_test_class2);
	fkreg(fk, "delete_test_class1", delete_test_class1);
	fkreg(fk, "delete_test_class2", delete_test_class2);
	fkreg(fk, "test_memfunc1", &test_class1::test_memfunc1); 
	fkreg(fk, "test_memfunc1", &test_class2::test_memfunc1); 
	fkreg(fk, "test_memfunc2", &test_class2::test_memfunc2); 

	// 编译后文件
	if (g_iscompiled)
	{
		// 打开自己
		char * selftmpbuf = 0;
		int selfsize = 0;
		if (!readfile(g_selfname, 0, selftmpbuf, selfsize))
		{
			return -1;
		}

		int startpos = 0;
		int size = 0;
		memcpy(&startpos, g_replacebuff, sizeof(startpos));
		memcpy(&size, g_replacebuff + 4, sizeof(size));

		if (fkloadfunc(fk, selftmpbuf + startpos, size) == -1)
		{
			printf("load func fail\n");
			return -1;
		}

		free(selftmpbuf);
	}
	// 解析文件
	else if (!g_isload)
	{
		fkparse(fk, argv[1]);
		if (fkerror(fk))
		{
			return -1;
		}
	}
	// 读文件
	else
	{
		// 读文件
		char * tmpbuf = 0;
		int size = 0;
		if (!readfile(argv[1], 0, tmpbuf, size))
		{
			return -1;
		}

		if (fkloadfunc(fk, tmpbuf, size) == -1)
		{
			printf("load func fail\n");
			return -1;
		}

		free(tmpbuf);
		printf("load from %s ok, size %d\n", argv[1], size);
	}

	// 存文件
	if (g_issave)
	{
		int tmpsize = 1024 * 1024;
		char * tmpbuf = (char *)malloc(tmpsize);
		int size = fksavefunc(fk, tmpbuf, tmpsize);
		if (size == -1)
		{
			printf("save func fail\n");
			return -1;
		}

		const char * filename = "fake.bin";
		if (!writefile(filename, tmpbuf, size))
		{
			return -1;
		}
		free(tmpbuf);
		
		printf("save to %s ok, size %d\n", filename, size);
		
		return 0;
	}

	// 编译到一起
	if (g_iscompile)
	{
		int tmpsize = 1024 * 1024;
		char * tmpbuf = (char *)malloc(tmpsize);
		int size = fksavefunc(fk, tmpbuf, tmpsize);
		if (size == -1)
		{
			printf("compile func fail\n");
			return -1;
		}

		// 打开自己
		char * selftmpbuf = 0;
		int selfsize = 0;
		if (!readfile(g_selfname, size, selftmpbuf, selfsize))
		{
			return -1;
		}

		// 替换内存中的字符串
		bool isfind = false;
		for (int i = 0; i < selfsize; i++)
		{
			if (memcmp(selftmpbuf + i, g_replacebuff, strlen(g_replacebuff)) == 0)
			{
				memcpy(selftmpbuf + i, &selfsize, sizeof(selfsize));
				memcpy(selftmpbuf + i + 4, &size, sizeof(size));
				isfind = true;
				break;
			}
		}
		if (!isfind)
		{
			printf("replace %s pos fail\n", argv[0]);
			return -1;
		}

		// 复制后面的
		memcpy(selftmpbuf + selfsize, tmpbuf, size);
		free(tmpbuf);

		// 输出
		const char * filename = "out.exe";
		if (!writefile(filename, selftmpbuf, selfsize + size))
		{
			return -1;
		}
		free(selftmpbuf);

		printf("compile to %s ok, size %d\n", filename, selfsize + size);

		return 0;
	}

#ifndef WIN32
	if (g_isopengoogleprofile)
	{
		ProfilerStart("fake.prof");
	}
#endif

	uint32_t begintime = time(0);
	int fkret = 0;

	// run
	for (int i = 0; i < g_testnum; i++)
	{
		if (!g_isopenjit)
		{
			if (g_isstep)
			{
				fkret = fkdebugrun<int>(fk, "main");
			}
			else
			{
				fkret = fkrun<int>(fk, "main");
			}
		}
		else
		{
			fkret = fkrunjit<int>(fk, "main");
		}
	}
	
	uint32_t endtime = time(0);

#ifndef WIN32
	if (g_isopengoogleprofile)
	{
		ProfilerStop();
	}
#endif

	if (fkerror(fk))
	{
		return -1;
	}

	if (g_isopenprofile)
	{
		printf("\n%s", fkdumpprofile(fk));
	}

	if (g_isprintoutput)
	{
		printf("main return : %d, use time %d\n", fkret, endtime - begintime);
	}

	delfake(fk);

	return 0;
}
示例#28
0
int
main(int argc, char *argv[]) {
	isc_result_t result;
#ifdef HAVE_LIBSCF
	char *instance = NULL;
#endif

#ifdef HAVE_GPERFTOOLS_PROFILER
	(void) ProfilerStart(NULL);
#endif

	/*
	 * Record version in core image.
	 * strings named.core | grep "named version:"
	 */
	strlcat(version,
#if defined(NO_VERSION_DATE) || !defined(__DATE__)
		"named version: BIND " VERSION " <" SRCID ">",
#else
		"named version: BIND " VERSION " <" SRCID "> (" __DATE__ ")",
#endif
		sizeof(version));
	result = isc_file_progname(*argv, program_name, sizeof(program_name));
	if (result != ISC_R_SUCCESS)
		ns_main_earlyfatal("program name too long");

	if (strcmp(program_name, "lwresd") == 0)
		ns_g_lwresdonly = ISC_TRUE;

	if (result != ISC_R_SUCCESS)
		ns_main_earlyfatal("failed to build internal symbol table");

	isc_assertion_setcallback(assertion_failed);
	isc_error_setfatal(library_fatal_error);
	isc_error_setunexpected(library_unexpected_error);

	ns_os_init(program_name);

	dns_result_register();
	dst_result_register();
	isccc_result_register();
#ifdef PKCS11CRYPTO
	pk11_result_register();
#endif

	parse_command_line(argc, argv);

	pfilter_open();

	/*
	 * Warn about common configuration error.
	 */
	if (ns_g_chrootdir != NULL) {
		int len = strlen(ns_g_chrootdir);
		if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&
		    (ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))
			ns_main_earlywarning("config filename (-c %s) contains "
					     "chroot path (-t %s)",
					     ns_g_conffile, ns_g_chrootdir);
	}

	result = isc_mem_create(0, 0, &ns_g_mctx);
	if (result != ISC_R_SUCCESS)
		ns_main_earlyfatal("isc_mem_create() failed: %s",
				   isc_result_totext(result));
	isc_mem_setname(ns_g_mctx, "main", NULL);

	setup();

	/*
	 * Start things running and then wait for a shutdown request
	 * or reload.
	 */
	do {
		result = isc_app_run();

		if (result == ISC_R_RELOAD) {
			ns_server_reloadwanted(ns_g_server);
		} else if (result != ISC_R_SUCCESS) {
			UNEXPECTED_ERROR(__FILE__, __LINE__,
					 "isc_app_run(): %s",
					 isc_result_totext(result));
			/*
			 * Force exit.
			 */
			result = ISC_R_SUCCESS;
		}
	} while (result != ISC_R_SUCCESS);

#ifdef HAVE_LIBSCF
	if (ns_smf_want_disable == 1) {
		result = ns_smf_get_instance(&instance, 1, ns_g_mctx);
		if (result == ISC_R_SUCCESS && instance != NULL) {
			if (smf_disable_instance(instance, 0) != 0)
				UNEXPECTED_ERROR(__FILE__, __LINE__,
						 "smf_disable_instance() "
						 "failed for %s : %s",
						 instance,
						 scf_strerror(scf_error()));
		}
		if (instance != NULL)
			isc_mem_free(ns_g_mctx, instance);
	}
#endif /* HAVE_LIBSCF */

	cleanup();

	if (want_stats) {
		isc_mem_stats(ns_g_mctx, stdout);
		isc_mutex_stats(stdout);
	}

	if (ns_g_memstatistics && memstats != NULL) {
		FILE *fp = NULL;
		result = isc_stdio_open(memstats, "w", &fp);
		if (result == ISC_R_SUCCESS) {
			isc_mem_stats(ns_g_mctx, fp);
			isc_mutex_stats(fp);
			isc_stdio_close(fp);
		}
	}
	isc_mem_destroy(&ns_g_mctx);
	isc_mem_checkdestroyed(stderr);

	ns_main_setmemstats(NULL);

	isc_app_finish();

	ns_os_closedevnull();

	ns_os_shutdown();

#ifdef HAVE_GPERFTOOLS_PROFILER
	ProfilerStop();
#endif

	return (0);
}
/**
* main entrance.
*/
int main(int argc, char** argv) 
{
    int ret = ERROR_SUCCESS;

    // TODO: support both little and big endian.
    srs_assert(srs_is_little_endian());

#ifdef SRS_AUTO_GPERF_MP
    HeapProfilerStart("gperf.srs.gmp");
#endif
#ifdef SRS_AUTO_GPERF_CP
    ProfilerStart("gperf.srs.gcp");
#endif

#if defined(SRS_AUTO_GPERF_MC) && defined(SRS_AUTO_GPERF_MP)
    srs_error("option --with-gmc confict with --with-gmp, "
        "@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n"
        "Note that since the heap-checker uses the heap-profiling framework internally, "
        "it is not possible to run both the heap-checker and heap profiler at the same time");
    return -1;
#endif
    
    // never use srs log(srs_trace, srs_error, etc) before config parse the option,
    // which will load the log config and apply it.
    if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) {
        return ret;
    }
    
    // config parsed, initialize log.
    if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) {
        return ret;
    }

    // we check the config when the log initialized.
    if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) {
        return ret;
    }
    
    srs_trace("srs(simple-rtmp-server) "RTMP_SIG_SRS_VERSION);
    srs_trace("license: "RTMP_SIG_SRS_LICENSE);
    srs_trace("authors: "RTMP_SIG_SRS_PRIMARY_AUTHROS);
    srs_trace("contributors: "SRS_AUTO_CONSTRIBUTORS);
    srs_trace("uname: "SRS_AUTO_UNAME);
    srs_trace("build: %s, %s", SRS_AUTO_BUILD_DATE, srs_is_little_endian()? "little-endian":"big-endian");
    srs_trace("configure: "SRS_AUTO_USER_CONFIGURE);
    srs_trace("features: "SRS_AUTO_CONFIGURE);
#ifdef SRS_AUTO_ARM_UBUNTU12
    srs_trace("arm tool chain: "SRS_AUTO_EMBEDED_TOOL_CHAIN);
#endif
    srs_trace("conf: %s, limit: %d", _srs_config->config().c_str(), _srs_config->get_max_connections());
    
    // features
    show_macro_features();
    check_macro_features();
    
    /**
    * we do nothing in the constructor of server,
    * and use initialize to create members, set hooks for instance the reload handler,
    * all initialize will done in this stage.
    */
    if ((ret = _srs_server->initialize()) != ERROR_SUCCESS) {
        return ret;
    }
    
    return run();
}
示例#30
0
void bigDictTest() {
    SmartKey::SmartKeyDictionary dictionary(g_settings);

#ifdef HEAP
    HeapProfilerStart("smartkey");
    HeapProfilerDump("period");
#endif

    dictionary.loadSkippedCharsFromFile("/var/tmp/key_skipped");

#ifdef HEAP
    HeapProfilerDump("period");
#endif

    dictionary.loadTermsFromFile("/var/tmp/key_dict_us");
    //dictionary.loadCompiledDictionary("/var/tmp/compiled_key_dict_us");

    //HeapProfilerDump("period");

    dictionary.loadEquivalencesFromFile("/var/tmp/key_equiv");

    //testExactMatchesInFile(dictionary, "/var/tmp/key_dict_us");


     // old test
    /*
    int numInserts = 0;
    dictionary.insert("dork", 69); numInserts++;
    dictionary.insert("door", 67); numInserts++;
    dictionary.insert("doored", 39); numInserts++;
    dictionary.insert("flake", 70); numInserts++;
    dictionary.insert("the", 90); numInserts++;
    dictionary.insert("that", 90); numInserts++;
    dictionary.insert("they", 80); numInserts++;
    dictionary.insert("there", 82); numInserts++;
    dictionary.insert("There's", 81); numInserts++;
    dictionary.insert("at", 90); numInserts++;
    dictionary.insert("it", 91); numInserts++;
    dictionary.insert("for", 69); numInserts++;
    dictionary.insert("attempt", 30); numInserts++;
    dictionary.insert("substantial", 43); numInserts++;
    dictionary.insert("subs", 2); numInserts++;
    dictionary.insert("nonsense", 4); numInserts++;

    dictionary.print();
*/




    allWordsTest(dictionary);

    // small tree insertion test


/*
    std::string there = "there";

    std::string theres = "theres";
    
    std::string therr = "therr";
    
    std::string rhsy = "rhsy";
    
    std::string that = "that";
    std::string that_rgsr = "rgsy";

    dictionary.find(there);
    dictionary.find(therr);
    
    dictionary.find(that);
    dictionary.find(that_rgsr);

    dictionary.find(theres);

    dictionary.find(std::string("fot"));
    dictionary.find(std::string("ot"));
    dictionary.find(std::string("dindrsmrusl"));
  */




/*
    //tiny test
    printf("---- inserting ------\n");
    dictionary.insert("that", 80);
    dictionary.print();
    printf("---- inserting ------\n");
    dictionary.insert("there", 90);
    dictionary.print();
    printf("---- inserting ------\n");
    dictionary.insert("they", 70);
    dictionary.print();
    printf("---- inserting ------\n");
    dictionary.insert("that's", 70);
    dictionary.print();
*/
    /* weird ordering issue
    dictionary.insert("theater", 2);
    dictionary.insert("theaters", 3);
    dictionary.insert("there", 2);
    dictionary.insert("the", 1);
    dictionary.insert("Theme", 4);
    dictionary.insert("Thematic", 1);
    dictionary.insert("Th", 10);
    dictionary.insert("those", 1);
     */

    //dictionary.print();
    //test(dictionary, "there", "there");
#ifdef HEAP
    ProfilerStart("smartkeyCpu");
#endif

    /*
    test(dictionary, "tha", "that");
    test(dictionary, "rgru", "they");
    test(dictionary, "subs", "sub's");
    test(dictionary, "substanti", "substantial");
    test(dictionary, "mimdrbdr", "nonsense");
*/
#ifdef HEAP
    ProfilerStop();
#endif

    //dictionary.insert("the", 100000);



    int size = 0;
    int numOfSize = -1;

    printf("%s: number of nodes: %d\n", __FUNCTION__, dictionary.getNodeCount());

    while (numOfSize != 0) {
        int capacity = 0;
        numOfSize = dictionary.singlesCounter(size, capacity);
        printf("%s: number of child maps with only %d child: %d\n", __FUNCTION__, size, numOfSize);
        size++;
    }

    printf("%s: num removable nodes: %d\n", __FUNCTION__, dictionary.numRemovableNodes());



    printf("%s: node size: %d\n", __FUNCTION__,
            sizeof(SmartKeyNode));
}