예제 #1
0
파일: larson.c 프로젝트: d-b/CSC469
void runloops(long sleep_cnt, int num_chunks )
{
  int     cblks ;
  int     victim ;
  int     blk_size ;
  long ticks_per_sec ;
  long start_cnt, end_cnt ;
  _int64        ticks ;
  double        duration ;
  double        reqd_space ;
  ptrdiff_t     used_space ;
  int           sum_allocs=0 ;

  QueryPerformanceFrequency( &ticks_per_sec ) ;
  QueryPerformanceCounter( &start_cnt) ;

  for( cblks=0; cblks<num_chunks; cblks++){
    if (max_size == min_size) {
      blk_size = min_size;
    } else {
      blk_size = min_size+lran2(&rgen)%(max_size - min_size) ;
    }
    blkp[cblks] = (char *) mm_malloc(blk_size) ;
    blksize[cblks] = blk_size ;
    assert(blkp[cblks] != NULL) ;
  }

  while(TRUE){
    for( cblks=0; cblks<num_chunks; cblks++){
      victim = lran2(&rgen)%num_chunks ;
      mm_free(blkp[victim]) ;

      if (max_size == min_size) {
	blk_size = min_size;
      } else {
	blk_size = min_size+lran2(&rgen)%(max_size - min_size) ;
      }
      blkp[victim] = (char *) mm_malloc(blk_size) ;
      blksize[victim] = blk_size ;
      assert(blkp[victim] != NULL) ;
    }
    sum_allocs += num_chunks ;

    QueryPerformanceCounter( &end_cnt) ;
    ticks = end_cnt - start_cnt ;
    duration = (double)ticks/ticks_per_sec ;

    if( duration >= sleep_cnt) break ;
  }
  reqd_space = (0.5*(min_size+max_size)*num_chunks) ;
  used_space = mem_usage();

  printf("%6.3f", duration  ) ;
  printf("%8.0f", sum_allocs/duration ) ;
  printf(" %6.3f %.3f", (double)used_space/(1024*1024), used_space/reqd_space) ;
  printf("\n") ;

}
예제 #2
0
//allocate buffer for storing
//allocation depends on image w and h, selected fps, selected amount of seconds to store, image format
JNIEXPORT jint JNICALL Java_com_zihuatanejo_finalcamera_plugins_capture_preshot_PreShot_AllocateBuffer
(
	JNIEnv* env,
	jobject pObj,
	jint jimgw,
	jint jimgh,
	jint jfps,
	jint secondsToAllocate,
	jint isJPG
)
{
	int i=0;

	int desiredBufSize = 0;
	int maxBufSize = 0;

	image_w = jimgw;
	image_h = jimgh;
	FPS = jfps;

	//zero buf head&tail
	idxIN=0;
	idxOUT=0;

	if (isJPG==1)
		elemSize = jimgw*jimgh/2;
	else
		elemSize = jimgw*jimgh*3/2;
	//long mem_free;
	mem_usage(&mem_free);

	desiredBufSize = secondsToAllocate*FPS+1;
//	if (!isReservedAllocated)
//		maxBufSize = mem_free/2/elemSize;
//	else
		maxBufSize = mem_free*0.8/elemSize;

	//count buf_size
	buf_size = (desiredBufSize<maxBufSize)?desiredBufSize:maxBufSize;

	frame_buffer = (unsigned char *)malloc(sizeof(unsigned char)*buf_size*elemSize);
	if (!frame_buffer)
		return 0;

	orient_buffer = (unsigned char *)malloc(sizeof(unsigned char)*buf_size);
	if (!orient_buffer)
		return 0;

	len_buffer = (unsigned int *)malloc(sizeof(unsigned int)*buf_size);
	if (!len_buffer)
		return 0;

	__android_log_print(ANDROID_LOG_ERROR, "Allocation", "Allocated %d bufers of %d size", buf_size, elemSize);

	return buf_size/FPS;
}
예제 #3
0
파일: main.cpp 프로젝트: bhanderson/cpts464
int main(int argc, const char *argv[])
{
	std::cout << "user "  + get_user() << std::endl;
	std::cout << "hostname " + get_hostname() << std::endl;
	std::cout << "time " + get_time() << std::endl;
	std::cout << "procs " + get_procs() << std::endl;
	std::cout << "cpu " + cpu_usage() << std::endl;
	std::cout << "mem " + (float)mem_usage() << std::endl;
	return 0;
}
예제 #4
0
int main (int argc, char * argv[])
{
  int nthreads;
  int iterations;
  int objSize;
  int repetitions;

  if (argc > 4) {
    nthreads = atoi(argv[1]);
    iterations = atoi(argv[2]);
    objSize = atoi(argv[3]);
    repetitions = atoi(argv[4]);
  } else {
    fprintf (stderr, "Usage: %s nthreads iterations objSize repetitions\n", argv[0]);
    exit(1);
  }

  pthread_t threads[nthreads];
  int numCPU = getNumProcessors();
  pthread_setconcurrency(numCPU);

  int i;

  /* Call allocator-specific initialization function */
  mm_init();

  pthread_attr_t attr;
  initialize_pthread_attr(PTHREAD_CREATE_JOINABLE, SCHED_RR, -10, PTHREAD_EXPLICIT_SCHED, 
			  PTHREAD_SCOPE_SYSTEM, &attr);

  timer_start();

  for (i = 0; i < nthreads; i++) {
    struct workerArg * w = (struct workerArg *)mm_malloc(sizeof(struct workerArg));
    w->_objSize = objSize;
    w->_repetitions = repetitions / nthreads;
    w->_iterations = iterations;
    w->_cpu = (i+1)%numCPU;
    pthread_create(&threads[i], &attr, &worker, (void *)w);
  }

  for (i = 0; i < nthreads; i++) {
    pthread_join(threads[i], NULL);
  }

  double t = timer_stop();

  printf ("Time elapsed = %f seconds\n", t);
  printf ("Memory used = %d bytes\n",mem_usage());
  return 0;
}
예제 #5
0
static void join_demo_header(int threads, work_t* works) {
    char buf[64];
    int usrcpu = usrcpu_usage(threads, works);
    int syscpu = syscpu_usage(threads, works);
    mem2str(buf, mem_usage(threads, works) + sizeof(pthread_t) * threads);
    TRACE("*** PTHREAD JOIN DEMO ***\n"
            "CPU usage\n"
            "\tuser:   drops from %3d%% to 0%%\n"
            "\tsystem: drops from %3d%% to 0%%\n"
            "Memory usage\n"
            "\tdrops from %s to 0\n"
            "Thread usage\n"
            "\ttotal:  drops from %d to 0\n"
            "\tlocked: none\n",
            100 * usrcpu / MAX(usrcpu + syscpu, cpucount()),
            100 * syscpu / MAX(usrcpu + syscpu, cpucount()),
            buf, threads + 1);
}
예제 #6
0
static void rwlock_demo_header(int readers, int writers, work_t* works) {
    char buf[64];
    int usrcpu = usrcpu_usage(readers, works);
    int syscpu = syscpu_usage(readers, works);
    int total = usrcpu + syscpu;
    usrcpu = 100 * usrcpu / MAX(total, cpucount());
    syscpu = 100 * syscpu / MAX(total, cpucount());
    mem2str(buf, (readers + writers) * sizeof (pthread_t) + mem_usage(readers, works));
    TRACE("*** PTHREAD RWLOCK DEMO ***\n"
            "CPU usage\n"
            "\tuser:   about %3d%%\n"
            "\tsystem: about %3d%%\n"
            "Memory usage\n"
            "\t%s\n"
            "Thread usage\n"
            "\ttotal:  %d\n"
            "\tlocked: %d\n",
            usrcpu, syscpu,
            buf, readers + writers + 1, writers);
}
예제 #7
0
void sequential_demo(int work_count, work_t* works, int seconds_per_work) {
    PRINT("*** SEQUENTIAL DEMO ***\n\n");
    EXPLAIN("  I'm going to run %d works sequentially, one after another.\n", work_count);
    EXPLAIN("  Each work will run for %d seconds.\n\n", seconds_per_work);
    int i;
    for (i = 0; i < work_count; ++i) {
        work_explain(&works[i]);
        PAUSE("Press [Enter] to start this work...\n");
        REF("Estimated resource usage for the following %d seconds\n", seconds_per_work);
        REF("CPU usage:\n");
        REF("\tuser:   about %d%%\n", 100 * usrcpu_usage(1, &works[i]) / cpucount());
        REF("\tsystem: about %d%%\n", 100 * syscpu_usage(1, &works[i]) / cpucount());
        REF("Memory usage:\n");
        REF("\t%ld bytes\n", mem_usage(1, &works[i]));
        REF("Thread usage:\n");
        REF("\ttotal:  1\n");
        REF("\tlocked: 0\n\n");
        work_run(&works[i], seconds_per_work * MICROS_PER_SECOND);
        PRINT("\n");
    }
}
예제 #8
0
extern "C" JNIEXPORT jstring JNICALL Java_com_almalence_plugins_processing_simple_AlmaShotDRO_Initialize
(
	JNIEnv* env,
	jobject thiz
)
{
	char status[1024];
	int err=0;
	long mem_used, mem_free;

	if (almashot_inited == 0)
	{
		err = AlmaShot_Initialize(0);

		if (err == 0)
			almashot_inited = 1;
	}

	mem_usage(&mem_used, &mem_free);

	sprintf (status, " memory: %ld(%ld) init status: %d\n", mem_free, mem_used, err);
	return env->NewStringUTF(status);
}
예제 #9
0
  using std::experimental::meta::void_t;

namespace adl_mem_usage {

  template< class C >
    constexpr auto mem_usage( C& c ) -> decltype(c.mem_usage()) { return c.mem_usage(); }
  template <typename T>
  std::enable_if_t<std::is_trivial<T>::value, size_t>
     mem_usage(const T& v) { return sizeof v; }

  template <typename T>
#if 1
    size_t mem_usage(const std::vector<T>& v);
#else
  // unable to forward declare SFINAE interface
    auto mem_usage(const std::vector<T>& v) -> decltype(mem_usage(v[0]));
#endif

  // overload for std::optional
  template <typename T>
  auto mem_usage(const std::experimental::optional<T>& v) -> decltype(mem_usage(*v))
  {
      size_t ans = sizeof(v);
      if (v) ans += mem_usage(*v) - sizeof(*v);
      return ans;
  }

  // overload for std::pair
  template <typename T, typename U>
  auto mem_usage(const std::pair<T,U>& v) -> decltype(mem_usage(v.first)
      + mem_usage(v.second))
예제 #10
0
파일: int.c 프로젝트: ebcode/weaverd
void input_directory(const char* dir_name, int recurse) {
  time_t now;
  int elapsed;
  DIR *dirp;
  struct dirent *dp;
  char file_name[MAX_FILE_NAME];
  struct stat stat_buf;
  char *all_files, *files;
  char *all_dirs, *dirs;
  size_t dir_size;
  int total_files = 0, i = 0;
  char **file_array;

  printf("%s\n", dir_name); 

  if ((dirp = opendir(dir_name)) == NULL)
    return;

  if (fstat(dirfd(dirp), &stat_buf) == -1) {
    closedir(dirp);
    return;
  }
  
  // The total size of the file names shouldn't exceed the size
  // of the directory file.  So we just use that as the size.  It's
  // wasteful, but meh.
  dir_size = stat_buf.st_size + 1024;
  files = all_files = malloc(dir_size);
  bzero(all_files, dir_size);
  
  // Go through all the files in the directory and put files
  // in one array and directories in another.
  while ((dp = readdir(dirp)) != NULL) {
    if (strcmp(dp->d_name, ".") &&
        strcmp(dp->d_name, "..")) {
      total_files++;
      strcpy(files, dp->d_name);
      files += strlen(dp->d_name) + 1;
    }
  }
  closedir(dirp);

  // Sort the files by name.
  files = all_files;
  file_array = calloc(sizeof(char*), total_files);
  while (*files) {
    file_array[i++] = files;
    files += strlen(files) + 1;
  }
  qsort(file_array, total_files, sizeof(char*), compare);
  
  dirs = all_dirs = malloc(dir_size);
  bzero(all_dirs, dir_size);

  // Go through all the files, stat them/thread them, and separate
  // out the directories.
  for (i = 0; i < total_files; i++) {
    snprintf(file_name, sizeof(file_name), "%s/%s", dir_name, file_array[i]);
    if (lstat(file_name, &stat_buf) != -1) {
      if (S_ISDIR(stat_buf.st_mode)) {
	strcpy(dirs, file_array[i]);
	dirs += strlen(file_array[i]) + 1;
      } else if (S_ISREG(stat_buf.st_mode)) {
	if (is_number(file_array[i])) {
	  thread_file(file_name);
	  if (! (commands++ % 10000)) {
	    time(&now);
	    elapsed = now - start_time;
	    printf("    %d files (%d/s, last %d seconds)\n",
		   commands - 1, 
		   (elapsed?
		    (int)(10000 / elapsed):
		    0), 
		   elapsed);
	    start_time = now;
	    printf("    %lu bytes string storage per file\n",
		   next_string / commands);
	    mem_usage();
	  }
	}
      }
    }
  }
  free(file_array);
  
  if (recurse) {
    dirs = all_dirs;
    while (*dirs) {
      snprintf(file_name, sizeof(file_name), "%s/%s", dir_name, dirs);
      input_directory(file_name, recurse);
      dirs += strlen(dirs) + 1;
    }
  }

  free(all_files);
  free(all_dirs);
}
예제 #11
0
파일: larson.c 프로젝트: d-b/CSC469
void runthreads(long sleep_cnt, int min_threads, int max_threads, int chperthread, int num_rounds)
{
  thread_data  de_area[MAX_THREADS] ;
  int           nperthread ;
  int           sum_threads ;
  int           sum_allocs ;
  int           sum_frees ;
  double        duration ;
  long ticks_per_sec ;
  long start_cnt, end_cnt ;
  _int64        ticks ;
  double        rate_1=0, rate_n ;
  double        reqd_space ;
  ptrdiff_t     used_space ;
  int           prevthreads ;
  int           i ;

  QueryPerformanceFrequency( &ticks_per_sec ) ;

  memset(&de_area[0], 0, sizeof(thread_data)) ;

  prevthreads = 0 ;
  for(num_threads=min_threads; num_threads <= max_threads; num_threads++ )
    {

      warmup(&blkp[prevthreads*chperthread], (num_threads-prevthreads)*chperthread );

      nperthread = chperthread ;
      stopflag   = FALSE ;
		
      for(i=0; i< num_threads; i++){
	de_area[i].threadno    = i+1 ;
	de_area[i].NumBlocks   = num_rounds*nperthread;
	de_area[i].array       = &blkp[i*nperthread] ;
	de_area[i].blksize     = &blksize[i*nperthread] ;
	de_area[i].asize       = nperthread ;
	de_area[i].min_size    = min_size ;
	de_area[i].max_size    = max_size ;
	de_area[i].seed        = lran2(&rgen) ; ;
	de_area[i].finished    = 0 ;
	de_area[i].cAllocs     = 0 ;
	de_area[i].cFrees      = 0 ;
	de_area[i].cThreads    = 0 ;
	de_area[i].finished    = FALSE ;
	lran2_init(&de_area[i].rgen, de_area[i].seed) ;

	_beginthread(exercise_heap, 0, &de_area[i]) ;  

      }

      QueryPerformanceCounter( &start_cnt) ;

      //printf ("Sleeping for %ld seconds.\n", sleep_cnt);
      Sleep(sleep_cnt * 1000L) ;
      stopflag = TRUE ;

      for(i=0; i<num_threads; i++){
	while( !de_area[i].finished ){
		sched_yield();
	}
      }


      QueryPerformanceCounter( &end_cnt) ;

      sum_frees = sum_allocs =0  ;
      sum_threads = 0 ;
      for(i=0;i< num_threads; i++){
	sum_allocs    += de_area[i].cAllocs ;
	sum_frees     += de_area[i].cFrees ;
	sum_threads   += de_area[i].cThreads ;
	printf("area %d: %d allocs, %d threads\n",i,de_area[i].cAllocs,de_area[i].cThreads);
	de_area[i].cAllocs = de_area[i].cFrees = 0;
      }

 
      ticks = end_cnt - start_cnt ;
     duration = (double)ticks/ticks_per_sec ;

      for( i=0; i<num_threads; i++){
	if( !de_area[i].finished )
	  printf("Thread at %d not finished\n", i) ;
      }


      rate_n = sum_allocs/duration ;
      if( rate_1 == 0){
	rate_1 = rate_n ;
      }
		
      reqd_space = (0.5*(min_size+max_size)*num_threads*chperthread) ;
      used_space = mem_usage();
      
      printf ("Throughput = %8.0f operations per second.\n", sum_allocs / duration);
      printf ("Memory used = %ld bytes, required %.0lf, ratio %lf\n",used_space,reqd_space,used_space/reqd_space);

#if 0
      printf("%2d ", num_threads ) ;
      printf("%6.3f", duration  ) ;
      printf("%6.3f", rate_n/rate_1 ) ;
      printf("%8.0f", sum_allocs/duration ) ;
      printf(" %6.3f %.3f", (double)used_space/(1024*1024), used_space/reqd_space) ;
      printf("\n") ;
#endif

      Sleep(5000L) ; // wait 5 sec for old threads to die

      prevthreads = num_threads ;

      printf ("Done sleeping...\n");

    }
}