void MmapDecoder::read_map_line(const char* line)
{
	uint32_t fd;
	uint32_t start, end, offset;
	int rc = sscanf(line, "%x %x %x %x",
		&fd, &start, &end, &offset);
	lite_assert(rc==4);
	lite_assert(fd<MAX_FD_TABLE);
	lite_assert(fd_table[fd]!=NULL);

	uint32_t size = end-start;

	// round fast_mmap size to page boundary, since client fast_mmap will
	// need to do the same thing to exploit this fast region.
	size = ((size-1)&(~0xfff))+0x1000;
	// TODO this is a source of waste; account for it.

/*
	if (strcmp(fd_table[fd], "/usr/lib/mozilla/plugins/librhythmbox-itms-detection-plugin.so")==0)
	{
		fprintf(stderr, "break here\n");
		fprintf(stderr, "yeah\n");
	}
*/

	MmapBehavior* behavior = query_file(fd_table[fd], true);
	if (offset==0)
	{
		if (behavior->aligned_mapping_copies==0)
		{
			behavior->aligned_mapping_size = size;
		}

		if (behavior->aligned_mapping_size != size)
		{
			// already have seen one 0-offset mapping, but it doesn't match
			// I've seen this happen when the second instance is actually
			// the data segment, but the text segment was so small that
			// the data segment fit inside the first page of the file.
			// (e.g. librhythmbox-itms-detection-plugin.so).
			// In this case, the second instance should be a 'precious'
			// range anyway; it can't get mmap_fast'd due to how the
			// client will request it.
			lite_assert(size <= 8192);	// just be sure we're not getting carried away and falling for this trick too often.
			MDRange this_range(offset, offset+size);
			behavior->insert_range(&this_range);
		}
		else
		{
			behavior->aligned_mapping_copies += 1;
		}
	}
	else
	{
		MDRange this_range(offset, offset+size);
		behavior->insert_range(&this_range);
	}
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
    if (argc < 3 || argc > 5)
    {
        std::cerr << "Usage: ./create_benchmark data_file benchmark_file [Q = 200] [K = 50]" << std::endl;
        return -1;
    }
    unsigned K = 50, Q = 200, seed = 2;
    if (argc > 3)
    {
        Q = atoi(argv[3]);
    }
    if (argc > 4)
    {
        K = atoi(argv[4]);
    }
    lshbox::timer timer;
    std::cout << "CREATE BENCHMARK FOR DATA ..." << std::endl;
    timer.restart();
    std::string file(argv[1]);
    std::string query_file(argv[2]);
    lshbox::Matrix<float> data(file);
    lshbox::Benchmark bench;
    bench.init(Q, K, data.getSize(), seed);
    lshbox::Metric<float> metric(data.getDim(), L2_DIST);
    lshbox::progress_display pd(Q);
    for (unsigned i = 0; i != Q; ++i)
    {
        unsigned q = bench.getQuery(i);
        lshbox::Topk &topk = bench.getAnswer(i);
        for (unsigned j = 0; j != data.getSize(); ++j)
        {
            topk.push(j, metric.dist(data[q], data[j]));
        }
        topk.genTopk();
        ++pd;
    }
    bench.save(query_file);
    std::cout << "MEAN QUERY TIME: " << timer.elapsed() / Q << "s." << std::endl;
}
Ejemplo n.º 3
0
int
main (int argc, char **argv)
{
  int status = 0;
  int i;
  char *filename = NULL;

  progname = argv[0];

  bufsiz = resolv_number (BGPDUMP_BUFSIZ_DEFAULT, NULL);
  nroutes = resolv_number (ROUTE_LIMIT_DEFAULT, NULL);

  status = bgpdump_getopt (argc, argv);

  argc -= optind;
  argv += optind;

  if (status)
    return status;

  if (argc == 0)
    {
      printf ("specify rib files.\n");
      usage ();
      exit (-1);
    }

  if (verbose)
    {
      printf ("bufsiz = %llu\n", bufsiz);
      printf ("nroutes = %llu\n", nroutes);
    }

  /* default cmd */
  if (! brief && ! show && ! route_count && ! plen_dist && ! udiff &&
      ! lookup && ! peer_table_only && ! stat && ! compat_mode &&
      ! autsiz && ! heatmap)
    show++;

  if (stat)
    peer_stat_init ();

  char *buf;
  buf = malloc (bufsiz);
  if (! buf)
    {
      printf ("can't malloc %lluB-size buf: %s\n",
              bufsiz, strerror (errno));
      exit (-1);
    }

  peer_table_init ();

  if (peer_spec_size)
    {
      for (i = 0; i < peer_spec_size; i++)
        {
          peer_route_table[i] = route_table_create ();
          peer_route_size[i] = 0;
          peer_ptree[i] = ptree_create ();
        }
    }

  if (lookup)
    {
      route_init ();
      ptree[AF_INET] = ptree_create ();
      ptree[AF_INET6] = ptree_create ();
    }

  if (udiff)
    {
      diff_table[0] = malloc (nroutes * sizeof (struct bgp_route));
      diff_table[1] = malloc (nroutes * sizeof (struct bgp_route));
      assert (diff_table[0] && diff_table[1]);
      memset (diff_table[0], 0, nroutes * sizeof (struct bgp_route));
      memset (diff_table[1], 0, nroutes * sizeof (struct bgp_route));

      if (udiff_lookup)
        {
          diff_ptree[0] = ptree_create ();
          diff_ptree[1] = ptree_create ();
        }
    }

  /* for each rib files. */
  for (i = 0; i < argc; i++)
    {
      filename = argv[i];

      file_format_t format;
      struct access_method *method;
      void *file;
      size_t ret;

      format = get_file_format (filename);
      method = get_access_method (format);
      file = method->fopen (filename, "r");
      if (! file)
        {
          fprintf (stderr, "# could not open file: %s\n", filename);
          continue;
        }

      size_t datalen = 0;

      while (1)
        {
          ret = method->fread (buf + datalen, bufsiz - datalen, 1, file);
          if (debug)
            printf ("read: %lu bytes to buf[%lu]. total %lu bytes\n",
                    ret, datalen, ret + datalen);
          datalen += ret;

          /* end of file. */
          if (ret == 0 && method->feof (file))
            {
              if (debug)
                printf ("read: end-of-file.\n");
              break;
            }

          bgpdump_process (buf, &datalen);

          if (debug)
            printf ("process rest: %lu bytes\n", datalen);
        }

      if (datalen)
        {
          printf ("warning: %lu bytes unprocessed data remains: %s\n",
                  datalen, filename);
        }
      method->fclose (file);

      /* For each end of the processing of files. */
      if (route_count)
        {
          peer_route_count_show ();
          peer_route_count_clear ();
        }

      if (plen_dist)
        {
          peer_route_count_by_plen_show ();
          peer_route_count_by_plen_clear ();
        }
    }

  /* query_table construction. */
  if (lookup)
    {
      query_limit = 0;

      if (lookup_file)
        query_limit = query_file_count (lookup_file);

      if (lookup_addr)
        query_limit++;

      query_init ();

      if (lookup_addr)
        query_addr (lookup_addr);

      if (lookup_file)
        query_file (lookup_file);

      if (debug)
        query_list ();
    }

  /* query to route_table (ptree). */
  if (lookup)
    {
      if (benchmark)
        benchmark_start ();

      if (peer_spec_size)
        {
          for (i = 0; i < peer_spec_size; i++)
            {
              printf ("peer %d:\n", peer_spec_index[i]);
              if (verbose)
                ptree_list (peer_ptree[i]);
              ptree_query (peer_ptree[i], query_table, query_size);
            }
        }
      else
        {
          if (verbose)
            ptree_list (ptree[qaf]);
          ptree_query (ptree[qaf], query_table, query_size);
        }

      if (benchmark)
        {
          benchmark_stop ();
          benchmark_print (query_size);
        }
    }

  if (heatmap)
    {
      for (i = 0; i < peer_spec_size; i++)
        {
          heatmap_image_hilbert_gplot (i);
          heatmap_image_hilbert_data (i);
          //heatmap_image_hilbert_data_aspath_max_distance (i);
        }
    }

  if (lookup)
    {
      free (query_table);
      ptree_delete (ptree[AF_INET]);
      ptree_delete (ptree[AF_INET6]);
      route_finish ();
    }

  if (udiff)
    {
      free (diff_table[0]);
      free (diff_table[1]);

      if (lookup)
        {
          ptree_delete (diff_ptree[0]);
          ptree_delete (diff_ptree[1]);
        }
    }

  if (stat)
    {
      peer_stat_show ();
      //peer_stat_finish ();
    }

  free (buf);

  return status;
}
Ejemplo n.º 4
0
int main(int argc,char **argv){

	if(argc<2){
		fprintf(stderr,"tag: mising operand\n");
		fprintf(stderr,"Try `tag --help' for more information.\n");
		return 0;
	}
	
	if(!strcmp(argv[1],"--help")){
		printf(helptext);
		return 0;
	}
	
	if(!strcmp(argv[1],"--version")){
		printf(versiontext,VERSION_MAJOR,VERSION_MINOR,VERSION_BUILD);
		return 0;
	}

	if(argc<3){
		fprintf(stderr,"tag: mising operand\n");
		fprintf(stderr,"Try `tag --help' for more information.\n");
		return 0;
	}

	if(!strcmp(argv[1],"-t")){//tag a file
			tag_tagfile(argv[argc-1],(const char **)argv+2,argc-3);

	}else if(!strcmp(argv[1],"-f")){//find file(s)
		//printf("find mode\n");
		struct stat s;
		if(lstat(argv[argc-1],&s)){
			fprintf(stderr,"tag: `%s\': No such directory\n",argv[argc-1]);
			return 0;
		}

		if(!S_ISDIR(s.st_mode)){
			fprintf(stderr,"tag: `%s\': Not a directory\n",argv[argc-1]);
			return 0;
		}

			int len=strlen(argv[argc-1]);
			char *path=malloc((len+4)*sizeof(*path));
			strcpy(path,argv[argc-1]);
			if(path[len-1]!='/'){
				strcat(path,"/");
			}
			search(path,(const char **)argv+2,argc-3);
			free(path);path=NULL;

	}else if(!strcmp(argv[1],"-d")){//dump file tags
		//dump_tagfile(argv[argc-1]);
		

	}else if(!strcmp(argv[1],"-q")){//query file tags
		query_file(argv[argc-1]);

	}else{
		fprintf(stderr,"tag: invalid operand\n");
		fprintf(stderr,"Try `tag --help' for more information.\n");
	}


	return 0;
}