Beispiel #1
0
void
depprint(double *hm, double *hd, double *hs, double *hk)
{
	int i, n;

	double hmean[256], hstd[256], hskew[256], hkurt[256];
	double mean, std, skew, kurt;

	n = 0;
	for (i = 0; i < 256; i++) {
		hmean[n] = esterror(hm, i);
		hstd[n] = esterror(hd, i);
		hskew[n] = esterror(hs, i);
		hkurt[n] = esterror(hk, i);
		if (hm[i] != 0 && hd[i] != 0)
			n++;
	}

	compute_stats(hmean, n, &mean, &std, &skew, &kurt);
	fprintf(stdout, "%f %f %f %f ", mean, std, skew, kurt);
	compute_stats(hstd, n, &mean, &std, &skew, &kurt);
	fprintf(stdout, "%f %f %f %f ", mean, std, skew, kurt);
	compute_stats(hskew, n, &mean, &std, &skew, &kurt);
	fprintf(stdout, "%f %f %f %f ", mean, std, skew, kurt);
	compute_stats(hkurt, n, &mean, &std, &skew, &kurt);
	fprintf(stdout, "%f %f %f %f ", mean, std, skew, kurt);
}
Beispiel #2
0
static void
devstats(void)
{
	int dn;
	long double transfers_per_second;
	long double busy_seconds;

	diff_cp_time.cp_user = cp_time.cp_user - old_cp_time.cp_user;
	diff_cp_time.cp_nice = cp_time.cp_nice - old_cp_time.cp_nice;
	diff_cp_time.cp_sys = cp_time.cp_sys - old_cp_time.cp_sys;
	diff_cp_time.cp_intr = cp_time.cp_intr - old_cp_time.cp_intr;
	diff_cp_time.cp_idle = cp_time.cp_idle - old_cp_time.cp_idle;
	old_cp_time = cp_time;

	busy_seconds = compute_etime(cur.busy_time, last.busy_time);

	for (dn = 0; dn < num_devices; dn++) {
		int di;

		if ((dev_select[dn].selected == 0)
		 || (dev_select[dn].selected > maxshowdevs))
			continue;

		di = dev_select[dn].position;

		if (compute_stats(&cur.dinfo->devices[di],
				  &last.dinfo->devices[di], busy_seconds,
				  NULL, NULL, NULL,
				  NULL, &transfers_per_second, NULL,
				  NULL, NULL) != 0)
			errx(1, "%s", devstat_errbuf);

		printf("%3.0Lf ", transfers_per_second);
	}
}
Beispiel #3
0
void CErrorAnal_dlg::OnChangeStatOptions()
{
  get_stat_options(); // xfer stat options ctls to stat options of active data set
  list_stats();
  compute_stats();
  update_stat_param_ctls();
}
Beispiel #4
0
void flac__analyze_finish(analysis_options aopts)
{
	if(aopts.do_residual_gnuplot) {
		compute_stats(&all_);
		(void)dump_stats(&all_, "all");
	}
}
Beispiel #5
0
// read method implementation
char fifo::read () {
  // local buffer for storing the read byte until return
  char c;

  // record time
  last_time = sc_time_stamp();

  // fetch the "oldest" byte in the buffer
  c = data[first];

  // compute the new stats based on new counters
  compute_stats();

  // if the buffer is already empty, we update the empty read counter
  if (num_elements == 0) {
    c = '0';
    ++ num_emptyread;
  }

  // otherwise we decrement the number of elements counter, and
  // increment the first pointer to point to the next oldest element
  else {
    -- num_elements;
    first = (first + 1) % size;
  }
  
#ifdef TRACE
  cout << "-" << c;
#endif

  // return the correct byte
  return c;
}
Beispiel #6
0
void CErrorAnal_dlg::OnFilter()
{
  FeatureFilter& filter=active_data()->filter;
  if (CFeatureFilter_dlg(filter,this).DoModal()!=IDOK) return;
  list_stats();
  compute_stats();
  update_stat_param_ctls(); // xfer stats of active data set to stat ctls
}
Beispiel #7
0
static void perform_ping_test(struct ping_test_recipe recipe,
                              memcached_st *mst,
                              struct moxi_stats *out, int *failures)
{
    double *timing_results = calloc(recipe.iterations, sizeof(double));
    assert(timing_results);

    struct timeval timing = { 0, 0 };

    char *key = calloc(recipe.keysize, sizeof(char));
    assert(key);
    char *value = calloc(recipe.valsize, sizeof(char));
    assert(value);

    /* Key is all 't's...just because */
    memset(key, 't', recipe.keysize);
    /* Value is a random bunch of stuff */
    for (int i = 0; i < recipe.valsize; i++) {
        value[i] = random() & 0xff;
    }

    if (memcached_set(mst,
                      key, recipe.keysize,
                      value, recipe.valsize,
                      0, 0) != MEMCACHED_SUCCESS) {
        /* XXX: Failure */
    }

    for (int i = 0 ; i < recipe.iterations; i++) {
        struct timeval tv_pre = { 0, 0 } , tv_post = { 0, 0 };
        size_t retrieved_len = 0;
        uint32_t flags = 0;
        memcached_return error;

        gettimeofday(&tv_pre, NULL);

        char *retrieved = memcached_get(mst,
                                        key, recipe.keysize,
                                        &retrieved_len, &flags,
                                        &error);

        gettimeofday(&tv_post, NULL);
        timeval_subtract(&timing, &tv_post, &tv_pre);
        timing_results[i] = timeval_to_double(timing);

        if (retrieved) {
            free(retrieved);
        } else {
            (*failures)++;
        }
    }

    compute_stats(out, timing_results, recipe.iterations);
    free(timing_results);
    free(key);
    free(value);
}
Beispiel #8
0
void CErrorAnal_dlg::compute_stats(AnalData *data)
{
  if (!data) {
    compute_stats(&m_peak_data);
    if (m_separam) {
      compute_stats(&m_sadl_data);
      m_mahal=m_peak_data.regress.mahal(m_sadl_data.regress);
    }
    return;
  }
  data->regress.summarize();
  m_more_params.EnableWindow(data->regress.n>data->regress.nparam);
  //if (data->gamma<0) {
    //AfxMessageBox("Unaccounted model error is negative!\n"
		  //"Is your calibration range too low?",MB_ICONWARNING);
  //}
  //if (data==active_data()) update_stat_option_ctls();
}
Beispiel #9
0
void Histogram::high_clip( float val ) {
  high_clip_ = val;
  recompute_ = true;
  if( val < low_clip_ ) 
    end_ = start_;
  else
    end_ = std::upper_bound( data_.begin(), data_.end(), high_clip_ );
  compute_stats();
  bins( bins_count_ );
}
Beispiel #10
0
void Histogram::low_clip( float val ) {
  low_clip_ = val;
  recompute_ = true;
  if( val > high_clip_ )
    start_ = end_;
  else
    start_ = std::lower_bound( data_.begin(), data_.end(), low_clip_ );
  compute_stats();
  bins( bins_count_ );
}
Beispiel #11
0
    void read(char &c){
      last_time = sc_time_stamp();
      if (num_elements == 0)
        wait(write_event);

      compute_stats();

      c = data[first];
      -- num_elements;
      first = (first + 1) % size;
      read_event.notify();
    }
Beispiel #12
0
void Histogram::clipping_values( std::pair<float,float> vals ) {
  recompute_ = true;

  if( vals.second < vals.first )
    vals.second = vals.first;

  low_clip_ = vals.first;
  high_clip_ = vals.second;
  start_ = std::lower_bound( data_.begin(), data_.end(), low_clip_ );
  end_ = std::upper_bound( data_.begin(), data_.end(), high_clip_ );
  compute_stats();
  bins( bins_count_ );
}
Beispiel #13
0
void CErrorAnal_dlg::set_tabs()
{
  m_featr_type_tab.DeleteAllItems();
  if (m_separam) {
    m_featr_type_tab.InsertItem(0,"Peak");
    m_featr_type_tab.InsertItem(1,"Saddle");
  }
  else m_featr_type_tab.InsertItem(0,"Peak && Saddle");
  list_stats();
  compute_stats(0);
  update_option_ctls();
  update_stat_param_ctls();
}
Beispiel #14
0
// [[Rcpp::export]]
DataFrame compute_stats(NumericVector observed, NumericVector predicted)
{
    vec obs = as<std::vector<double> >(observed);
    vec pred = as<std::vector<double> >(predicted);

    PredStats output = compute_stats(obs, pred);
    return DataFrame::create( Named("num_pred") = output.num_pred, 
                              Named("rho") = output.rho, 
                              Named("mae") = output.mae, 
                              Named("rmse") = output.rmse,
                              Named("perc") = output.perc, 
                              Named("p_val") = output.p_val);
}
Beispiel #15
0
void do_read_write(long *sizes, DATATYPE *x, double *times, double *bws, double *percents)
{
  long limit, j, i, tloops;
  double refcnt, overhead_per_ref = 0.0, tmicrosec;
  /* double nullcnt = 0.0, cmicrosec = 0.0; */

  if (my_isatty(1))
    {
      printf("\n\t\t%s%s%s RMW Cache Test\n\n",
	     ((type & HANDTUNED) ? "Tuned " : ""),
	     ((!(type & NOCALIBRATE)) ? "Calibrated " : ""), DATASTRING);

      printf("C Size\t\tNanosec\t\tMB/sec\t\t%% Chnge\n");
      printf("-------\t\t-------\t\t-------\t\t-------\n");
    }

  for (i = 0; i < timeslots; i++) 
    {
      limit = sizes[i] / (long)sizeof(DATATYPE);

      for (j = 0; j < repeat_count; j++)
	{
	  if (type & HANDTUNED)
	    refcnt = hand_benchmark_cache(x, limit, &tloops, &tmicrosec) * 2.0;
	  else
	    refcnt = benchmark_cache(x, limit, &tloops, &tmicrosec) * 2.0;
  
	  /* if (type & NOCALIBRATE)
	    {
	      nullcnt = 0.0;
	      overhead_per_ref = 0.0;
	      cmicrosec = 0.0;
	    }
	  else
	    {
	      nullcnt = calibrate_benchmark(x, tloops, limit, &cmicrosec);
	      nullcnt *= 2; 
	      overhead_per_ref = (cmicrosec*1000.0) / nullcnt;
	      DBG(fprintf(stderr,"C: %f ns per ref.\n",overhead_per_ref));
	    } */
	  
	  compute_stats(i,j,refcnt,overhead_per_ref,times,bws,percents,sizes,tmicrosec,sizeof(DATATYPE));
	}
    }
  
  /* if ((my_isatty(1))&&(type&GUESSCACHESIZE))
    compute_cache_sizes(times,bws,percents,sizes); */
}
Beispiel #16
0
double *
roughness_transform(short *dcts, int bits, int *pnpoints)
{
	double mean, std, skew, kurt;
	static double output[8];
	double *poutput, *points;
	int i, j, n, off, npoints;

	n = bits / DCTSIZE2;

	if ((points = malloc(n * sizeof(double))) == NULL)
		err(1, "malloc");

	/* Computes frequency averaged roughness */
	for (i = 0; i < n; i++) {
		double sum = 0, weight = 0, val;

		off = i * DCTSIZE2;
		for (j = 0; j < DCTSIZE2; j++) {
			int u, v;
			val = dcts[off + j];

			u = j / 8;
			v = j % 8;

			sum += (u*u + v*v) * val * val;
			weight += (u*u + v*v);
		}
		points[i] = sqrt(sum/weight);
	}

	compute_stats(points, n, &mean, &std, &skew, &kurt);

	npoints = 0;
	poutput = output;
	*poutput++ = mean;
	*poutput++ = std;
	*poutput++ = skew;
	*poutput++ = kurt;
	npoints += 4;

	*pnpoints = npoints;

	free(points);

	return (output);
}
Beispiel #17
0
void do_memory_copy(long *sizes, void *x, double *times, double *bws, double *percents)
{
  long limit, j, i, tloops;
  double refcnt, overhead_per_ref = 0.0, tmicrosec;
  /* double nullcnt = 0.0, cmicrosec = 0.0; */
  void *y;

  assert(y = (void *)malloc(memsize));
  memset(y,0x0f,memsize);

  if (my_isatty(1))
    {
      printf("\n\t\t%sMemory Copy Library Cache Test\n\n",
	     (!(type & NOCALIBRATE)) ? "Calibrated " : "");
      printf("C Size\t\tNanosec\t\tMB/sec\t\t%% Chnge\n");
      printf("-------\t\t-------\t\t-------\t\t-------\n");
    }

  for (i = 0; i < timeslots; i++) 
    {
      limit = sizes[i];
      for (j = 0; j < repeat_count; j++)
	{
	  refcnt = benchmark_cache_memory_copy(x, y, limit, &tloops, &tmicrosec) * 2.0;
	  
	  /* if (type & NOCALIBRATE)
	    {
	      nullcnt = 0.0;
	      overhead_per_ref = 0.0;
	      cmicrosec = 0.0;
	    }
	  else
	    {
	      nullcnt = calibrate_benchmark_cache_memory_copy(x, tloops, limit, &cmicrosec);
	      overhead_per_ref = (cmicrosec*1000.0) / nullcnt;
	      DBG(fprintf(stderr,"C: %f ns per ref.\n",overhead_per_ref));
	    } */

	  compute_stats(i,j,refcnt,overhead_per_ref,times,bws,percents,sizes,tmicrosec,1);
	}
    }
  
  /* if ((my_isatty(1))&&(type&GUESSCACHESIZE))
    compute_cache_sizes(times,bws,percents,sizes); */

  free(y);
}
Beispiel #18
0
END_TEST

START_TEST (test_compute_stats)
{
    double vals[] = { 2, 4, 4, 4, 5, 5, 7, 9 };
    struct moxi_stats stats;

    compute_stats(&stats, vals, sizeof(vals) / sizeof(double));

    fail_unless(almost_equal(stats.min, 2.0), "Min should be 2");
    fail_unless(almost_equal(stats.max, 9.0), "Max should be 9");
    fail_unless(almost_equal(stats.avg, 5.0), "Avg should be 5");
    fail_unless(almost_equal(stats.stddev, 2.0),
                "Standard devition should be 2.");
    fail_unless(almost_equal(stats.ninetyfifth, 9.0),
                "95th %%ile should be 9.");
}
Beispiel #19
0
void CErrorAnal_dlg::OnOptions()
{
  CStatOptions_dlg dlg;
  Stat_options& options=active_data()->options;
  dlg.m_symmetry=options.symmetry;
  dlg.m_min_nbr=options.mns;
  dlg.m_measr_error=options.measr_err;
  dlg.m_convolutn=options.nconv_inuse>0;
  if (dlg.DoModal()!=IDOK) return;
  options.symmetry=(Stat_options::Symmetry)dlg.m_symmetry;
  options.mns=(Stat_options::Min_nbr_set)dlg.m_min_nbr;
  options.measr_err=dlg.m_measr_error!=FALSE;
  options.nconv_inuse=dlg.m_convolutn?1:0;
  list_stats();
  compute_stats();
  update_stat_param_ctls();
}
Beispiel #20
0
double
distribution(int slot, short *data, int bits, double *p)
{
	double mean, std, skew, kurt;
	int i, j, n, nsimple;
	double *simple;
	double *herror;
	short *ndata;

	n = bits / DCTSIZE2;

	if ((ndata = malloc(n * sizeof(short))) == NULL)
		err(1, "malloc");

	for (j = 0; j < n; j++)
		ndata[j] = data[j*DCTSIZE2 + slot];

	histogram(ndata, n, &simple, &nsimple);

	free(ndata);

	if ((herror = calloc(nsimple, sizeof(double))) == NULL)
		err(1, "malloc");

	for (i = 2; i < nsimple - 2; i++) {
		if (simple[i] != 0)
			herror[i] = esterror2(simple, i, nsimple-1)/simple[i];
		else
			herror[i] = 0;
		/* fprintf(stderr, "%d %f\n", i, herror[i]); */
	}

	compute_stats(herror, nsimple, &mean, &std, &skew, &kurt);

	free(simple);
	free(herror);

	*p++ = mean;
	*p++ = std;
	*p++ = skew;
	*p++ = kurt;

	return (0);
}
Beispiel #21
0
static int
devstats(int row, int _col, int dn)
{
	long double transfers_per_second;
	long double kb_per_transfer, mb_per_second;
	long double busy_seconds;
	int di;
	
	di = dev_select[dn].position;

	busy_seconds = compute_etime(cur.busy_time, last.busy_time);

	if (compute_stats(&cur.dinfo->devices[di], &last.dinfo->devices[di],
			  busy_seconds, NULL, NULL, NULL,
			  &kb_per_transfer, &transfers_per_second,
			  &mb_per_second, NULL, NULL) != 0)
		errx(1, "%s", devstat_errbuf);

	if (numbers) {
		mvwprintw(wnd, row, _col, " %5.2Lf %3.0Lf %5.2Lf ",
			 kb_per_transfer, transfers_per_second,
			 mb_per_second);
		return(row);
	}
	wmove(wnd, row++, _col);
	histogram(mb_per_second, 50, .5);
	wmove(wnd, row++, _col);
	histogram(transfers_per_second, 50, .5);
	if (kbpt) {
		wmove(wnd, row++, _col);
		histogram(kb_per_transfer, 50, .5);
	}

	return(row);

}
Beispiel #22
0
PredStats ForecastMachine::make_const_stats()
{
    return compute_stats(targets, const_predicted);
}
Beispiel #23
0
void flac__analyze_frame(const FLAC__Frame *frame, unsigned frame_number, FLAC__uint64 frame_offset, unsigned frame_bytes, analysis_options aopts, FILE *fout)
{
	const unsigned channels = frame->header.channels;
	char outfilename[1024];
	subframe_stats_t stats;
	unsigned i, channel, partitions;

	/* do the human-readable part first */
#ifdef __MSVCRT__
	fprintf(fout, "frame=%u\toffset=%I64u\tbits=%u\tblocksize=%u\tsample_rate=%u\tchannels=%u\tchannel_assignment=%s\n", frame_number, frame_offset, frame_bytes*8, frame->header.blocksize, frame->header.sample_rate, channels, FLAC__ChannelAssignmentString[frame->header.channel_assignment]);
#else
	fprintf(fout, "frame=%u\toffset=%llu\tbits=%u\tblocksize=%u\tsample_rate=%u\tchannels=%u\tchannel_assignment=%s\n", frame_number, (unsigned long long)frame_offset, frame_bytes*8, frame->header.blocksize, frame->header.sample_rate, channels, FLAC__ChannelAssignmentString[frame->header.channel_assignment]);
#endif
	for(channel = 0; channel < channels; channel++) {
		const FLAC__Subframe *subframe = frame->subframes+channel;
		const FLAC__bool is_rice2 = subframe->data.fixed.entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
		const unsigned pesc = is_rice2? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
		fprintf(fout, "\tsubframe=%u\twasted_bits=%u\ttype=%s", channel, subframe->wasted_bits, FLAC__SubframeTypeString[subframe->type]);
		switch(subframe->type) {
			case FLAC__SUBFRAME_TYPE_CONSTANT:
				fprintf(fout, "\tvalue=%d\n", subframe->data.constant.value);
				break;
			case FLAC__SUBFRAME_TYPE_FIXED:
				FLAC__ASSERT(subframe->data.fixed.entropy_coding_method.type <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2);
				fprintf(fout, "\torder=%u\tresidual_type=%s\tpartition_order=%u\n", subframe->data.fixed.order, is_rice2? "RICE2":"RICE", subframe->data.fixed.entropy_coding_method.data.partitioned_rice.order);
				for(i = 0; i < subframe->data.fixed.order; i++)
					fprintf(fout, "\t\twarmup[%u]=%d\n", i, subframe->data.fixed.warmup[i]);
				partitions = (1u << subframe->data.fixed.entropy_coding_method.data.partitioned_rice.order);
				for(i = 0; i < partitions; i++) {
					unsigned parameter = subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents->parameters[i];
					if(parameter == pesc)
						fprintf(fout, "\t\tparameter[%u]=ESCAPE, raw_bits=%u\n", i, subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents->raw_bits[i]);
					else
						fprintf(fout, "\t\tparameter[%u]=%u\n", i, parameter);
				}
				if(aopts.do_residual_text) {
					for(i = 0; i < frame->header.blocksize-subframe->data.fixed.order; i++)
						fprintf(fout, "\t\tresidual[%u]=%d\n", i, subframe->data.fixed.residual[i]);
				}
				break;
			case FLAC__SUBFRAME_TYPE_LPC:
				FLAC__ASSERT(subframe->data.lpc.entropy_coding_method.type <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2);
				fprintf(fout, "\torder=%u\tqlp_coeff_precision=%u\tquantization_level=%d\tresidual_type=%s\tpartition_order=%u\n", subframe->data.lpc.order, subframe->data.lpc.qlp_coeff_precision, subframe->data.lpc.quantization_level, is_rice2? "RICE2":"RICE", subframe->data.lpc.entropy_coding_method.data.partitioned_rice.order);
				for(i = 0; i < subframe->data.lpc.order; i++)
					fprintf(fout, "\t\tqlp_coeff[%u]=%d\n", i, subframe->data.lpc.qlp_coeff[i]);
				for(i = 0; i < subframe->data.lpc.order; i++)
					fprintf(fout, "\t\twarmup[%u]=%d\n", i, subframe->data.lpc.warmup[i]);
				partitions = (1u << subframe->data.lpc.entropy_coding_method.data.partitioned_rice.order);
				for(i = 0; i < partitions; i++) {
					unsigned parameter = subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents->parameters[i];
					if(parameter == pesc)
						fprintf(fout, "\t\tparameter[%u]=ESCAPE, raw_bits=%u\n", i, subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents->raw_bits[i]);
					else
						fprintf(fout, "\t\tparameter[%u]=%u\n", i, parameter);
				}
				if(aopts.do_residual_text) {
					for(i = 0; i < frame->header.blocksize-subframe->data.lpc.order; i++)
						fprintf(fout, "\t\tresidual[%u]=%d\n", i, subframe->data.lpc.residual[i]);
				}
				break;
			case FLAC__SUBFRAME_TYPE_VERBATIM:
				fprintf(fout, "\n");
				break;
		}
	}

	/* now do the residual distributions if requested */
	if(aopts.do_residual_gnuplot) {
		for(channel = 0; channel < channels; channel++) {
			const FLAC__Subframe *subframe = frame->subframes+channel;
			unsigned residual_samples;

			init_stats(&stats);

			switch(subframe->type) {
				case FLAC__SUBFRAME_TYPE_FIXED:
					residual_samples = frame->header.blocksize - subframe->data.fixed.order;
					for(i = 0; i < residual_samples; i++)
						update_stats(&stats, subframe->data.fixed.residual[i], 1);
					break;
				case FLAC__SUBFRAME_TYPE_LPC:
					residual_samples = frame->header.blocksize - subframe->data.lpc.order;
					for(i = 0; i < residual_samples; i++)
						update_stats(&stats, subframe->data.lpc.residual[i], 1);
					break;
				default:
					break;
			}

			/* update all_ */
			for(i = 0; i < stats.nbuckets; i++) {
				update_stats(&all_, stats.buckets[i].residual, stats.buckets[i].count);
			}

			/* write the subframe */
			sprintf(outfilename, "f%06u.s%u.gp", frame_number, channel);
			compute_stats(&stats);

			(void)dump_stats(&stats, outfilename);
		}
	}
}
int main(int argc, char* argv[])
{
   std::deque<std::string> str_list;

   switch (argc)
   {
      case 1  : strtk::load_from_text_file(std::cin,str_list);
                break;

      case 2  : strtk::load_from_text_file(argv[1],str_list);
                break;

      default :
               {
                  std::cout << "usage: strtk_numstats <file name>" << std::endl;
                  std::cout << "usage: cat data.txt | strtk_numstats" << std::endl;
                  return 1;
               }
   }

   if (str_list.empty())
      return 0;

   std::size_t total_length = 0;
   for (std::size_t i = 0; i < str_list.size(); total_length += str_list[i++].size()) ;

   std::string buffer;
   buffer.reserve(total_length + str_list.size());
   strtk::join(buffer,"\n",str_list);

   std::vector<double> value_list;
   value_list.reserve(str_list.size());

   str_list.clear();

   strtk::token_grid::options options;
   options.set_column_delimiters(", ");

   strtk::token_grid grid(buffer.data(),
                          buffer.size(),
                          options);

   grid.remove_empty_tokens();

   for (std::size_t column = 0; column < grid.max_column_count(); ++column)
   {
      value_list.clear();
      grid.extract_column_checked(column,value_list);
      if (value_list.empty())
         continue;
      std::cout << "C["<< column << "]" << "\t";
      compute_stats(value_list);
      std::cout << std::endl;
   }

   for (std::size_t row = 0; row < grid.row_count(); ++row)
   {
      value_list.clear();
      grid.row(row).parse_checked(value_list);
      if (value_list.empty())
         continue;
      std::cout << "R["<< row << "]" << "\t";
      compute_stats(value_list);
      std::cout << std::endl;
   }

   return 0;
}
Beispiel #25
0
static void
ctlstat_standard(struct ctlstat_context *ctx) {
	long double etime;
	uint64_t delta_jiffies, delta_idle;
	uint32_t port;
	long double cpu_percentage;
	int i;
	int j;

	cpu_percentage = 0;

	if (F_CPU(ctx) && (getcpu(&ctx->cur_cpu) != 0))
		errx(1, "error returned from getcpu()");

	etime = ctx->cur_time.tv_sec - ctx->prev_time.tv_sec +                  
	    (ctx->prev_time.tv_nsec - ctx->cur_time.tv_nsec) * 1e-9; 

	if (F_CPU(ctx)) {
		ctx->prev_total_jiffies = ctx->cur_total_jiffies;
		ctx->cur_total_jiffies = ctx->cur_cpu.user +
		    ctx->cur_cpu.nice + ctx->cur_cpu.system +
		    ctx->cur_cpu.intr + ctx->cur_cpu.idle;
		delta_jiffies = ctx->cur_total_jiffies;
		if (F_FIRST(ctx) == 0)
			delta_jiffies -= ctx->prev_total_jiffies;
		ctx->prev_idle = ctx->cur_idle;
		ctx->cur_idle = ctx->cur_cpu.idle;
		delta_idle = ctx->cur_idle - ctx->prev_idle;

		cpu_percentage = delta_jiffies - delta_idle;
		cpu_percentage /= delta_jiffies;
		cpu_percentage *= 100;
	}

	if (F_HDR(ctx)) {
		ctx->header_interval--;
		if (ctx->header_interval <= 0) {
			int hdr_devs;

			hdr_devs = 0;

			if (F_TOTALS(ctx)) {
				fprintf(stdout, "%s     System Read     %s"
					"System Write     %sSystem Total%s\n",
					(F_LUNVAL(ctx) != 0) ? "     " : "",
					(F_LUNVAL(ctx) != 0) ? "     " : "",
					(F_LUNVAL(ctx) != 0) ? "     " : "",
					(F_CPU(ctx) == 0)   ? "    CPU" : "");
				hdr_devs = 3;
			} else {
				if (F_CPU(ctx))
					fprintf(stdout, "  CPU  ");
				for (i = 0; i < min(CTL_STAT_LUN_BITS,
				     ctx->num_luns); i++) {
					int lun;

					/*
					 * Obviously this won't work with
					 * LUN numbers greater than a signed
					 * integer.
					 */
					lun = (int)ctx->cur_lun_stats[i
						].lun_number;

					if (bit_test(ctx->lun_mask, lun) == 0)
						continue;
					fprintf(stdout, "%15.6s%d ",
						"lun", lun);
					hdr_devs++;
				}
				fprintf(stdout, "\n");
			}
			for (i = 0; i < hdr_devs; i++)
				fprintf(stdout, "%s  %sKB/t %s  MB/s ",
					((F_CPU(ctx) != 0) && (i == 0) &&
					(F_TOTALS(ctx) == 0)) ?  "       " : "",
					(F_LUNVAL(ctx) != 0) ? " ms  " : "",
					(F_DMA(ctx) == 0) ? "tps" : "dps");
			fprintf(stdout, "\n");
			ctx->header_interval = 20;
		}
	}

	if (F_TOTALS(ctx) != 0) {
		long double mbsec[3];
		long double kb_per_transfer[3];
		long double transfers_per_sec[3];
		long double ms_per_transfer[3];
		long double ms_per_dma[3];
		long double dmas_per_sec[3];

		for (i = 0; i < 3; i++) 
			ctx->prev_total_stats[i] = ctx->cur_total_stats[i];

		memset(&ctx->cur_total_stats, 0, sizeof(ctx->cur_total_stats));

		/* Use macros to make the next loop more readable. */
#define	ADD_STATS_BYTES(st, p, i, j) \
	ctx->cur_total_stats[st].ports[p].bytes[j] += \
	    ctx->cur_lun_stats[i].ports[p].bytes[j]
#define	ADD_STATS_OPERATIONS(st, p, i, j) \
	ctx->cur_total_stats[st].ports[p].operations[j] += \
	    ctx->cur_lun_stats[i].ports[p].operations[j]
#define	ADD_STATS_NUM_DMAS(st, p, i, j) \
	ctx->cur_total_stats[st].ports[p].num_dmas[j] += \
	    ctx->cur_lun_stats[i].ports[p].num_dmas[j]
#define	ADD_STATS_TIME(st, p, i, j) \
	bintime_add(&ctx->cur_total_stats[st].ports[p].time[j], \
	    &ctx->cur_lun_stats[i].ports[p].time[j])
#define	ADD_STATS_DMA_TIME(st, p, i, j) \
	bintime_add(&ctx->cur_total_stats[st].ports[p].dma_time[j], \
	    &ctx->cur_lun_stats[i].ports[p].dma_time[j])

		for (i = 0; i < ctx->num_luns; i++) {
			for (port = 0; port < CTL_MAX_PORTS; port++) {
				for (j = 0; j < CTL_STATS_NUM_TYPES; j++) {
					ADD_STATS_BYTES(2, port, i, j);
					ADD_STATS_OPERATIONS(2, port, i, j);
					ADD_STATS_NUM_DMAS(2, port, i, j);
					ADD_STATS_TIME(2, port, i, j);
					ADD_STATS_DMA_TIME(2, port, i, j);
				}
				ADD_STATS_BYTES(0, port, i, CTL_STATS_READ);
				ADD_STATS_OPERATIONS(0, port, i,
				    CTL_STATS_READ);
				ADD_STATS_NUM_DMAS(0, port, i, CTL_STATS_READ);
				ADD_STATS_TIME(0, port, i, CTL_STATS_READ);
				ADD_STATS_DMA_TIME(0, port, i, CTL_STATS_READ);

				ADD_STATS_BYTES(1, port, i, CTL_STATS_WRITE);
				ADD_STATS_OPERATIONS(1, port, i,
				    CTL_STATS_WRITE);
				ADD_STATS_NUM_DMAS(1, port, i, CTL_STATS_WRITE);
				ADD_STATS_TIME(1, port, i, CTL_STATS_WRITE);
				ADD_STATS_DMA_TIME(1, port, i, CTL_STATS_WRITE);
			}
		}

		for (i = 0; i < 3; i++) {
			compute_stats(&ctx->cur_total_stats[i],
				F_FIRST(ctx) ? NULL : &ctx->prev_total_stats[i],
				etime, &mbsec[i], &kb_per_transfer[i],
				&transfers_per_sec[i],
				&ms_per_transfer[i], &ms_per_dma[i],
				&dmas_per_sec[i]);
			if (F_DMA(ctx) != 0)
				fprintf(stdout, " %2.2Lf",
					ms_per_dma[i]);
			else if (F_LUNVAL(ctx) != 0)
				fprintf(stdout, " %2.2Lf",
					ms_per_transfer[i]);
			fprintf(stdout, " %5.2Lf %3.0Lf %5.2Lf ",
				kb_per_transfer[i],
				(F_DMA(ctx) == 0) ? transfers_per_sec[i] :
				dmas_per_sec[i], mbsec[i]);
		}
		if (F_CPU(ctx))
			fprintf(stdout, " %5.1Lf%%", cpu_percentage);
	} else {
		if (F_CPU(ctx))
			fprintf(stdout, "%5.1Lf%% ", cpu_percentage);

		for (i = 0; i < min(CTL_STAT_LUN_BITS, ctx->num_luns); i++) {
			long double mbsec, kb_per_transfer;
			long double transfers_per_sec;
			long double ms_per_transfer;
			long double ms_per_dma;
			long double dmas_per_sec;

			if (bit_test(ctx->lun_mask,
			    (int)ctx->cur_lun_stats[i].lun_number) == 0)
				continue;
			compute_stats(&ctx->cur_lun_stats[i], F_FIRST(ctx) ?
				NULL : &ctx->prev_lun_stats[i], etime,
				&mbsec, &kb_per_transfer,
				&transfers_per_sec, &ms_per_transfer,
				&ms_per_dma, &dmas_per_sec);
			if (F_DMA(ctx))
				fprintf(stdout, " %2.2Lf",
					ms_per_dma);
			else if (F_LUNVAL(ctx) != 0)
				fprintf(stdout, " %2.2Lf",
					ms_per_transfer);
			fprintf(stdout, " %5.2Lf %3.0Lf %5.2Lf ",
				kb_per_transfer, (F_DMA(ctx) == 0) ?
				transfers_per_sec : dmas_per_sec, mbsec);
		}
	}
}
Beispiel #26
0
int
main(int argc, char **argv)
{
	uint64_t iterations, i;
	double *jitter_arr, *fraction_arr;
	double *wakeup_second_jitter_arr;
	uint64_t target_time;
	uint64_t sleep_length_abs;
	uint64_t min_sleep_ns = 0;
	uint64_t max_sleep_ns = DEFAULT_MAX_SLEEP_NS;
	uint64_t wake_time;
	unsigned random_seed;
	boolean_t need_seed = TRUE;
	char ch;
	int res;
	kern_return_t kret;
	my_policy_type_t pol;
	boolean_t wakeup_second_thread = FALSE;
	semaphore_t wakeup_semaphore, return_semaphore;

	double avg, stddev, max, min;
	double avg_fract, stddev_fract, max_fract, min_fract;
	uint64_t too_much;

	struct second_thread_args secargs;
	pthread_t secthread;

	mach_timebase_info(&g_mti);

	/* Seed random */
	opterr = 0;
	while ((ch = getopt(argc, argv, "m:n:hs:w")) != -1 && ch != '?') {
		switch (ch) {
			case 's':
				/* Specified seed for random)() */
				random_seed = (unsigned)atoi(optarg);
				srandom(random_seed);
				need_seed = FALSE;
				break;
			case 'm':
				/* How long per timer? */
				max_sleep_ns = strtoull(optarg, NULL, 10);	
				break;
			case 'n':
				/* How long per timer? */
				min_sleep_ns = strtoull(optarg, NULL, 10);	
				break;
			case 'w':
				/* After each timed wait, wakeup another thread */
				wakeup_second_thread = TRUE;
				break;
			case 'h':
				print_usage();
				exit(0);
				break;
			default:
				fprintf(stderr, "Got unexpected result from getopt().\n");
				exit(1);
				break;
		}
	}

	argc -= optind;
	argv += optind;

	if (argc != 3) {
		print_usage();
		exit(1);
	}

	if (min_sleep_ns >= max_sleep_ns) {
		print_usage();
		exit(1);
	}

	if (need_seed) {
		srandom(time(NULL));
	}

	/* What scheduling policy? */
	pol = parse_thread_policy(argv[0]);

	/* How many timers? */
	iterations = strtoull(argv[1], NULL, 10);

	/* How much jitter is so extreme that we should cut a trace point */
	too_much = strtoull(argv[2], NULL, 10);
	
	/* Array for data */
	jitter_arr = (double*)malloc(sizeof(*jitter_arr) * iterations);
	if (jitter_arr == NULL) {
		printf("Couldn't allocate array to store results.\n");
		exit(1);
	}

	fraction_arr = (double*)malloc(sizeof(*fraction_arr) * iterations);
	if (fraction_arr == NULL) {
		printf("Couldn't allocate array to store results.\n");
		exit(1);
	}

	if (wakeup_second_thread) {
		/* Array for data */
		wakeup_second_jitter_arr = (double*)malloc(sizeof(*jitter_arr) * iterations);
		if (wakeup_second_jitter_arr == NULL) {
			printf("Couldn't allocate array to store results.\n");
			exit(1);
		}

		kret = semaphore_create(mach_task_self(), &wakeup_semaphore, SYNC_POLICY_FIFO, 0);
		if (kret != KERN_SUCCESS) {
			printf("Couldn't allocate semaphore %d\n", kret);
			exit(1);
		}

		kret = semaphore_create(mach_task_self(), &return_semaphore, SYNC_POLICY_FIFO, 0);
		if (kret != KERN_SUCCESS) {
			printf("Couldn't allocate semaphore %d\n", kret);
			exit(1);
		}


		secargs.wakeup_semaphore = wakeup_semaphore;
		secargs.return_semaphore = return_semaphore;
		secargs.iterations = iterations;
		secargs.pol = pol;
		secargs.wakeup_second_jitter_arr = wakeup_second_jitter_arr;
		secargs.woke_on_same_cpu = 0;
		secargs.too_much = too_much;
		secargs.last_poke_time = 0ULL;
		secargs.cpuno = 0;

		res = pthread_create(&secthread, NULL, second_thread, &secargs);
		if (res) {
			err(1, "pthread_create");
		}

		sleep(1); /* Time for other thread to start up */
	}

	/* Set scheduling policy */
	res = thread_setup(pol);
	if (res != 0) {
		printf("Couldn't set thread policy.\n");
		exit(1);
	}

	/* 
	 * Repeatedly pick a random timer length and 
	 * try to sleep exactly that long 
	 */
	for (i = 0; i < iterations; i++) {
		sleep_length_abs = (uint64_t) (get_random_sleep_length_abs_ns(min_sleep_ns, max_sleep_ns) * (((double)g_mti.denom) / ((double)g_mti.numer)));
		target_time = mach_absolute_time() + sleep_length_abs;
		
		/* Sleep */
		kret = mach_wait_until(target_time);
		wake_time = mach_absolute_time();
	
		jitter_arr[i] = (double)(wake_time - target_time);
		fraction_arr[i] = jitter_arr[i] / ((double)sleep_length_abs);
		
		/* Too much: cut a tracepoint for a debugger */
		if (jitter_arr[i] >= too_much) {
			kdebug_trace(0xeeeee0 | DBG_FUNC_NONE, 0, 0, 0, 0);
		}

		if (wakeup_second_thread) {
			secargs.last_poke_time = mach_absolute_time();
			secargs.cpuno = cpu_number();
			OSMemoryBarrier();
			kret = semaphore_signal(wakeup_semaphore);
			if (kret != KERN_SUCCESS) {
				errx(1, "semaphore_signal");
			}

			kret = semaphore_wait(return_semaphore);
			if (kret != KERN_SUCCESS) {
				errx(1, "semaphore_wait");
			}

		}
	}

	/*
	 * Compute statistics and output results. 
	 */
	compute_stats(jitter_arr, iterations, &avg, &max, &min, &stddev);
	compute_stats(fraction_arr, iterations, &avg_fract, &max_fract, &min_fract, &stddev_fract);

	putchar('\n');
	print_stats_us("jitter", avg, max, min, stddev);
	print_stats_fract("%", avg_fract, max_fract, min_fract, stddev_fract);

	if (wakeup_second_thread) {

		res = pthread_join(secthread, NULL);
		if (res) {
			err(1, "pthread_join");
		}

		compute_stats(wakeup_second_jitter_arr, iterations, &avg, &max, &min, &stddev);
		
		putchar('\n');
		print_stats_us("second jitter", avg, max, min, stddev);

		putchar('\n');
		printf("%llu/%llu (%.1f%%) wakeups on same CPU\n", secargs.woke_on_same_cpu, iterations,
			   100.0*((double)secargs.woke_on_same_cpu)/iterations);
	}

	return 0;
}
Beispiel #27
0
static void
dinfo(int dn, int lc, struct statinfo *now, struct statinfo *then)
{
	long double kb_per_transfer;
	long double transfers_per_secondr;
	long double transfers_per_secondw;
	long double mb_per_secondr;
	long double mb_per_secondw;
	long double elapsed_time, device_busy;
	int di;

	di = dev_select[dn].position;

	elapsed_time = compute_etime(now->busy_time, then ?
				     then->busy_time :
				     now->dinfo->devices[di].dev_creation_time);

	device_busy =  compute_etime(now->dinfo->devices[di].busy_time, then ?
				     then->dinfo->devices[di].busy_time :
				     now->dinfo->devices[di].dev_creation_time);

	if (compute_stats(
			  &now->dinfo->devices[di],
			  (then ? &then->dinfo->devices[di] : NULL),
			  elapsed_time,
			  NULL, NULL, NULL,
			  &kb_per_transfer,
			  NULL,
			  NULL,
			  NULL, NULL) != 0)
		errx(1, "%s", devstat_errbuf);

	if (compute_stats_read(
			  &now->dinfo->devices[di],
			  (then ? &then->dinfo->devices[di] : NULL),
			  elapsed_time,
			  NULL, NULL, NULL,
			  NULL,
			  &transfers_per_secondr,
			  &mb_per_secondr,
			  NULL, NULL) != 0)
		errx(1, "%s", devstat_errbuf);

	if (compute_stats_write(
			  &now->dinfo->devices[di],
			  (then ? &then->dinfo->devices[di] : NULL),
			  elapsed_time,
			  NULL, NULL, NULL,
			  NULL,
			  &transfers_per_secondw,
			  &mb_per_secondw,
			  NULL, NULL) != 0)
		errx(1, "%s", devstat_errbuf);

	if ((device_busy == 0) &&
	    (transfers_per_secondr > 5 || transfers_per_secondw > 5)) {
		/* the device has been 100% busy, fake it because
		 * as long as the device is 100% busy the busy_time
		 * field in the devstat struct is not updated */
		device_busy = elapsed_time;
	}
	if (device_busy > elapsed_time) {
		/* this normally happens after one or more periods
		 * where the device has been 100% busy, correct it */
		device_busy = elapsed_time;
	}

	lc = DISKCOL + lc * 6;
	putlongdoublez(kb_per_transfer, DISKROW + 1, lc, 5, 2, 0);
	putlongdoublez(transfers_per_secondr, DISKROW + 2, lc, 5, 0, 0);
	putlongdoublez(mb_per_secondr, DISKROW + 3, lc, 5, 2, 0);
	putlongdoublez(transfers_per_secondw, DISKROW + 4, lc, 5, 0, 0);
	putlongdoublez(mb_per_secondw, DISKROW + 5, lc, 5, 2, 0);
	putlongdouble(device_busy * 100 / elapsed_time,
				      DISKROW + 6, lc, 5, 0, 0);
}
Beispiel #28
0
void CErrorAnal_dlg::compute_stats()
{
  compute_stats(active_data());
  if (m_separam) m_mahal=m_peak_data.regress.mahal(m_sadl_data.regress);
}
Beispiel #29
0
double *
diffsquare_transform(short *dcts, int bits, int *pnpoints)
{
	double mean, std, skew, kurt;
	static double output[64];
	double *poutput, *points;
	int i, j, k, n, off, npoints;

	n = bits / DCTSIZE2;

	if ((points = malloc(n * sizeof(double))) == NULL)
		err(1, "malloc");

	npoints = 0;
	poutput = output;

	for (k = 0; k < DCTSIZE; k++) {
		for (i = 0; i < n; i++) {
			double sum = 0;
			double val1, val2, weight = 0;

			off = i * DCTSIZE2;
			for (j = 0; j < DCTSIZE - 1; j++) {
				val1 = dcts[off + k * DCTSIZE + j];
				val2 = dcts[off + k * DCTSIZE + j + 1];

				sum += (val2 - val1) * (val2 - val1);
				weight += abs(val1);
			}
			points[i] = sqrt(sum)/(weight + 1);
		}
		
		compute_stats(points, n, &mean, &std, &skew, &kurt);

		*poutput++ = mean;
		*poutput++ = std;
		*poutput++ = skew;
		*poutput++ = kurt;
		npoints += 4;
	}

	for (k = 0; k < DCTSIZE; k++) {
		for (i = 0; i < n; i++) {
			double sum = 0;
			double val1, val2, weight = 0;

			off = i * DCTSIZE2;
			for (j = 0; j < DCTSIZE - 1; j++) {
				val1 = dcts[off + k + DCTSIZE * j];
				val2 = dcts[off + k + DCTSIZE * (j + 1)];

				sum += (val2 - val1) * (val2 - val1);
				weight += abs(val1);
			}
			points[i] = sqrt(sum)/(weight + 1);
		}
		
		compute_stats(points, n, &mean, &std, &skew, &kurt);

		*poutput++ = mean;
		*poutput++ = std;
		*poutput++ = skew;
		*poutput++ = kurt;
		npoints += 4;
	}

	*pnpoints = npoints;

	free(points);

	return (output);
}
Beispiel #30
0
double
dependency(int one, int two, short *data, int bits,
    double *hmean, double *hstd, double *hskew, double *hkurt)
{
	double mean, std, skew, kurt;
	int i, j, n;
	short dct, dctnext;
	u_short model[256][256];
	double *simple[256];
	size_t nsimple[256];

	memset(hmean, 0, 256*sizeof(double));
	memset(hstd, 0, 256*sizeof(double));
	memset(hskew, 0, 256*sizeof(double));
	memset(hkurt, 0, 256*sizeof(double));

	memset(model, 0, sizeof(model));
	memset(simple, 0, sizeof(simple));
	for (i = 0; i < bits; i+= DCTSIZE2) {
		dct = data[i + one];
		dctnext = data[i + two];

		dct += 128;
		dctnext += 128;

		if (dct > 255 || dctnext > 255)
			continue;

		model[dct][dctnext]++;
	}

	for (i = 0; i < 256; i++) {
		double *p;
		n = 0;
		for (j = 0; j < 256; j++) {
			n += model[i][j];
		}
		nsimple[i] = n;
		simple[i] = malloc(n * sizeof(double));
		if (simple[i] == NULL)
			err(1, "malloc");

		p = simple[i];
		for (j = 0; j < 256; j++) {
			n = model[i][j];
			while (n-- > 0)
				*p++ = j;
		}
	}

	n = 0;
	for (i = 0; i < 256; i++) {
		if (nsimple[i] > 4) {
			compute_stats(simple[i], nsimple[i],
			    &mean, &std, &skew, &kurt);
			hmean[i] = mean;
			hstd[i] = std;
			hskew[i] = skew;
			hkurt[i] = kurt;
			n++;
		}
	}

	for (i = 0; i < 256; i++)
		free(simple[i]);

	return (0);
}