void oprofile_add_trace(unsigned long pc) { struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()]; #ifdef CONFIG_CA_CSS if (pc == 0) return; #endif if (!cpu_buf->tracing) return; if (nr_available_slots(cpu_buf) < 1) { cpu_buf->tracing = 0; cpu_buf->sample_lost_overflow++; return; } /* broken frame can give an eip with the same value as an escape code, * abort the trace if we get it */ if (pc == ESCAPE_CODE) { cpu_buf->tracing = 0; cpu_buf->backtrace_aborted++; return; } #ifdef CONFIG_CA_CSS /* Use -1 for ca_css record */ add_sample(cpu_buf, pc, -1); #else add_sample(cpu_buf, pc, 0); #endif }
/* This must be safe from any context. It's safe writing here * because of the head/tail separation of the writer and reader * of the CPU buffer. * * cpu_mode is needed because on some architectures you cannot * tell if you are in kernel or user space simply by looking at * pc. We tag this in the buffer by generating kernel/user (and xen) * enter events whenever cpu_mode changes */ static int log_sample(struct oprofile_cpu_buffer * cpu_buf, unsigned long pc, int cpu_mode, unsigned long event) { struct task_struct * task; cpu_buf->sample_received++; if (nr_available_slots(cpu_buf) < 3) { cpu_buf->sample_lost_overflow++; return 0; } WARN_ON(cpu_mode > CPU_MODE_XEN); task = current; /* notice a switch from user->kernel or vice versa */ if (cpu_buf->last_cpu_mode != cpu_mode) { cpu_buf->last_cpu_mode = cpu_mode; add_code(cpu_buf, cpu_mode); } /* notice a task switch */ if (cpu_buf->last_task != task) { cpu_buf->last_task = task; add_code(cpu_buf, (unsigned long)task); } add_sample(cpu_buf, pc, event); return 1; }
void ME_Regression_DataSet::add_samples(const vector<ME_Regression_Sample>& new_samples) { int i; for (i=0; i<new_samples.size(); i++) add_sample(new_samples[i]); }
/* This must be safe from any context. It's safe writing here * because of the head/tail separation of the writer and reader * of the CPU buffer. * * cpu_mode is needed because on some architectures you cannot * tell if you are in kernel or user space simply by looking at * pc. We tag this in the buffer by generating kernel/user (and xen) * enter events whenever cpu_mode changes */ static int log_sample(struct oprofile_cpu_buffer * cpu_buf, unsigned long pc, int cpu_mode, unsigned long event) { struct task_struct * task; cpu_buf->sample_received++; if (nr_available_slots(cpu_buf) < 3) { cpu_buf->sample_lost_overflow++; return 0; } task = current; /* notice a switch from user->kernel or vice versa */ if (cpu_buf->last_cpu_mode != cpu_mode) { cpu_buf->last_cpu_mode = cpu_mode; add_code(cpu_buf, cpu_mode); } /* notice a task switch */ /* if not processing other domain samples */ if ((cpu_buf->last_task != task) && (current_domain == COORDINATOR_DOMAIN)) { cpu_buf->last_task = task; add_code(cpu_buf, (unsigned long)task); } if (pc == IBS_FETCH_CODE || pc == IBS_OP_CODE) add_code(cpu_buf, cpu_mode); add_sample(cpu_buf, pc, event); return 1; }
void Partitioner::RegionStats::add_samples(const RegionStats *x) { assert(x!=NULL); for (size_t id=0; id<dictionary.size(); ++id) add_sample(id, x->get_sum(id), x->get_nsamples(id)); }
/* This must be safe from any context. It's safe writing here * because of the head/tail separation of the writer and reader * of the CPU buffer. * * is_kernel is needed because on some architectures you cannot * tell if you are in kernel or user space simply by looking at * pc. We tag this in the buffer by generating kernel enter/exit * events whenever is_kernel changes */ static int log_sample(struct oprofile_cpu_buffer * cpu_buf, unsigned long pc, int is_kernel, unsigned long event) { struct task_struct * task; cpu_buf->sample_received++; if (nr_available_slots(cpu_buf) < 3) { cpu_buf->sample_lost_overflow++; return 0; } is_kernel = !!is_kernel; task = current; /* notice a switch from user->kernel or vice versa */ if (cpu_buf->last_is_kernel != is_kernel) { cpu_buf->last_is_kernel = is_kernel; add_code(cpu_buf, is_kernel); } /* notice a task switch */ if (cpu_buf->last_task != task) { cpu_buf->last_task = task; add_code(cpu_buf, (unsigned long)task); } add_sample(cpu_buf, pc, event); return 1; }
// adds the samples from the other dataset, and adjust weights void ME_Regression_DataSet::add_other_dataset_samples(const ME_Regression_DataSet& other) { int i; for (i=0; i<other.num_samples; i++) add_sample(other.samples[i]); tally_samples(); }
double fcyc2_full(test_funct f, int param1, int param2, int clear_cache, int k, double epsilon, int maxsamples, int compensate) { double result; init_sampler(k, maxsamples); if (compensate) { do { double cyc; if (clear_cache) clear(); f(param1, param2); /* warm cache */ start_comp_counter(); f(param1, param2); cyc = get_comp_counter(); add_sample(cyc, k); } while (!has_converged(k, epsilon, maxsamples) && samplecount < maxsamples); } else { do { double cyc; if (clear_cache) clear(); f(param1, param2); /* warm cache */ start_counter(); f(param1, param2); cyc = get_counter(); add_sample(cyc, k); } while (!has_converged(k, epsilon, maxsamples) && samplecount < maxsamples); } #ifdef DEBUG { int i; printf(" %d smallest values: [", k); for (i = 0; i < k; i++) printf("%.0f%s", values[i], i==k-1 ? "]\n" : ", "); } #endif result = values[0]; #if !KEEP_VALS free(values); values = NULL; #endif return result; }
double fcyc(test_funct f, long int *params) { double result; init_sampler(); if (compensate) { do { double cyc; if (clear_cache) clear(); start_counter(); f(params); cyc = get_counter(); if (cyc > 0.0) add_sample(cyc); } while (!has_converged() && samplecount < maxsamples); } else { do { double cyc; if (clear_cache) clear(); start_counter(); f(params); cyc = get_counter(); if (cyc > 0.0) add_sample(cyc); } while (!has_converged() && samplecount < maxsamples); } #ifdef DEBUG { long int i; printf(" %ld smallest values: [", kbest); for (i = 0; i < kbest; i++) printf("%.0f%s", values[i], i==kbest-1 ? "]\n" : ", "); } #endif result = values[0]; #if !KEEP_VALS free(values); values = NULL; #endif return result; }
void calibrate (unsigned direction) { typedef vector <DIM> vector_t; const double L = period[direction]; const double r_decay = sr_lr_split; // first decaying inner shell const double r_tail = 2*L; // last (decaying) inner shell, begin tail std::cerr << "jellium3_init shell_radii " << r_decay << " " << r_tail << "\n"; std::cerr << "jellium3_init error_bound " << error_bound << "\n"; prober[direction].calib_begin (DIM, r_decay, exponent+0.5, // inner paralpha r_tail, exponent+3); // tail paralpha (= exponent+4 decay) // scan along the sr_lr_split for_all_angles <DIM> (100, [&] (const vector_t &unit_vec) { const double r = sr_lr_split; add_sample (direction, r, lr_event_rate (r*unit_vec, direction)); }); // in extremely small systems, the first few copies can cause trouble for (int i = -10; i <= 10; ++i) { vector_t ridge = zero_vector <DIM> (); ridge[direction] = i*L; for (; ridge[direction] < 3*sr_lr_split; ridge[direction] += 1e-3*sr_lr_split) add_sample (direction, norm (ridge), lr_event_rate (ridge, direction)); } for_all_angles <DIM> (30, [&] (const vector_t &unit_vec) { for (double r = 0; r < 2*L; r += 1e-3*sr_lr_split) add_sample (direction, r, lr_event_rate (r*unit_vec, direction)); for (double r = 1.; r < 1e15*L; r *= 1.0001) add_sample (direction, r, lr_event_rate (r*unit_vec, direction)); }); prober[direction].calib_finish (DIM); }
/* Scale the IN_LEN RGB values from IN to OUT_LEN RGB values in OUT. */ static void scale_line(color_t* out, int out_len, color_t *in, int in_len) { double scaling_factor = (double)(in_len) / (double)(out_len); apr_size_t i; memset(out, 0, out_len * sizeof(color_t)); for (i = 0; i < out_len; ++i) { color_t color = { 0 }; double source_start = i * scaling_factor; double source_end = (i + 1) * scaling_factor; if ((apr_size_t)source_start == (apr_size_t)source_end) { add_sample(color, in, source_start, source_end, scaling_factor); } else { apr_size_t k; apr_size_t first_sample_end = (apr_size_t)source_start + 1; apr_size_t last_sample_start = (apr_size_t)source_end; add_sample(color, in, source_start, first_sample_end, scaling_factor); for (k = first_sample_end; k < last_sample_start; ++k) add_sample(color, in, k, k + 1, scaling_factor); add_sample(color, in, last_sample_start, source_end, scaling_factor); } memcpy(out[i], color, sizeof(color)); } }
int oprofile_add_domain_switch(int32_t domain_id) { struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()]; /* should have space for switching into and out of domain (2 slots each) plus one sample and one cpu mode switch */ if (((nr_available_slots(cpu_buf) < 6) && (domain_id != COORDINATOR_DOMAIN)) || (nr_available_slots(cpu_buf) < 2)) return 0; add_code(cpu_buf, CPU_DOMAIN_SWITCH); add_sample(cpu_buf, domain_id, 0); current_domain = domain_id; return 1; }
bool DashVideoSegmenter::addToSegment(AVCCFrame* frame, DashSegment* segment) { size_t segmentSize = 0; if (!frame || !segment || !dashContext || frame->getDataLength() <= 0 || frame->getDuration() <= 0) { return false; } segmentSize = add_sample(frame->getDataBuffer(), frame->getDataLength(), frame->getDuration(), frame->getPresentationTime(), frame->getDecodeTime(), segment->getSeqNumber(), VIDEO_TYPE, segment->getDataBuffer(), frame->isIntra(), &dashContext); if (segmentSize <= I2ERROR_MAX) { return false; } segment->setTimestamp(dashContext->ctxvideo->earliest_presentation_time); segment->setDataLength(segmentSize); return true; }
/* Returns the estimated value of the CPU frequncy in cycles per second (Hz) */ long get_cpu_frequency() { u_int64_t samples[MAX_SAMPLES]; u_int64_t sample; int sample_count = 0; // Init sample array init_sample_array(samples, MAX_SAMPLES); // Initialize the counter start_counter(); do { if (!get_sample(SLEEP_TIME, &sample)) { continue; } add_sample(samples, MAX_SAMPLES, sample); sample_count++; } while (!k_lowest_tolerance(samples, sample_count, K, TOLERANCE) && sample_count <= MAX_SAMPLES); return (long)(samples[0] / ((double)SLEEP_TIME / 1000)); }
void oprofile_add_trace(unsigned long pc) { struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer); if (!cpu_buf->tracing) return; if (nr_available_slots(cpu_buf) < 1) { cpu_buf->tracing = 0; cpu_buf->sample_lost_overflow++; return; } /* broken frame can give an eip with the same value as an escape code, * abort the trace if we get it */ if (pc == ESCAPE_CODE) { cpu_buf->tracing = 0; cpu_buf->backtrace_aborted++; return; } add_sample(cpu_buf, pc, 0); }
void oprofile_add_ibs_sample(struct pt_regs *const regs, unsigned int *const ibs_sample, int ibs_code) { int is_kernel = !user_mode(regs); struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer); struct task_struct *task; cpu_buf->sample_received++; if (nr_available_slots(cpu_buf) < MAX_IBS_SAMPLE_SIZE) { /* we can't backtrace since we lost the source of this event */ cpu_buf->sample_lost_overflow++; return; } /* notice a switch from user->kernel or vice versa */ if (cpu_buf->last_is_kernel != is_kernel) { cpu_buf->last_is_kernel = is_kernel; add_code(cpu_buf, is_kernel); } /* notice a task switch */ if (!is_kernel) { task = current; if (cpu_buf->last_task != task) { cpu_buf->last_task = task; add_code(cpu_buf, (unsigned long)task); } } add_code(cpu_buf, ibs_code); add_sample(cpu_buf, ibs_sample[0], ibs_sample[1]); add_sample(cpu_buf, ibs_sample[2], ibs_sample[3]); add_sample(cpu_buf, ibs_sample[4], ibs_sample[5]); if (ibs_code == IBS_OP_BEGIN) { add_sample(cpu_buf, ibs_sample[6], ibs_sample[7]); add_sample(cpu_buf, ibs_sample[8], ibs_sample[9]); add_sample(cpu_buf, ibs_sample[10], ibs_sample[11]); } if (backtrace_depth) oprofile_ops.backtrace(regs, backtrace_depth); }
static int log_ibs_sample(struct oprofile_cpu_buffer *cpu_buf, unsigned long pc, int is_kernel, unsigned int *ibs, int ibs_code) { struct task_struct *task; cpu_buf->sample_received++; if (nr_available_slots(cpu_buf) < MAX_IBS_SAMPLE_SIZE) { cpu_buf->sample_lost_overflow++; return 0; } is_kernel = !!is_kernel; /* notice a switch from user->kernel or vice versa */ if (cpu_buf->last_is_kernel != is_kernel) { cpu_buf->last_is_kernel = is_kernel; add_code(cpu_buf, is_kernel); } /* notice a task switch */ if (!is_kernel) { task = current; if (cpu_buf->last_task != task) { cpu_buf->last_task = task; add_code(cpu_buf, (unsigned long)task); } } add_code(cpu_buf, ibs_code); add_sample(cpu_buf, ibs[0], ibs[1]); add_sample(cpu_buf, ibs[2], ibs[3]); add_sample(cpu_buf, ibs[4], ibs[5]); if (ibs_code == IBS_OP_BEGIN) { add_sample(cpu_buf, ibs[6], ibs[7]); add_sample(cpu_buf, ibs[8], ibs[9]); add_sample(cpu_buf, ibs[10], ibs[11]); } return 1; }
static int log_ibs_sample(struct oprofile_cpu_buffer *cpu_buf, unsigned long pc, int cpu_mode, unsigned int *ibs, int ibs_code) { struct task_struct *task; cpu_buf->sample_received++; if (nr_available_slots(cpu_buf) < 14) { cpu_buf->sample_lost_overflow++; return 0; } task = current; /* notice a switch from user->kernel or vice versa */ if (cpu_buf->last_cpu_mode != cpu_mode) { cpu_buf->last_cpu_mode = cpu_mode; add_code(cpu_buf, cpu_mode); } /* notice a task switch */ /* if not processing other domain samples */ if ((cpu_buf->last_task != task) && (current_domain == COORDINATOR_DOMAIN)) { cpu_buf->last_task = task; add_code(cpu_buf, (unsigned long)task); } add_code(cpu_buf, ibs_code); add_sample(cpu_buf, ibs[0], ibs[1]); add_sample(cpu_buf, ibs[2], ibs[3]); add_sample(cpu_buf, ibs[4], ibs[5]); if (ibs_code == IBS_OP_BEGIN) { add_sample(cpu_buf, ibs[6], ibs[7]); add_sample(cpu_buf, ibs[8], ibs[9]); add_sample(cpu_buf, ibs[10], ibs[11]); } return 1; }
T operator()( const T& value, float delta_time ) { add_sample( value, delta_time ); return delayed_value(); }
bool GurlsClassificationInterface::read(yarp::os::ConnectionReader& connection) { yarp::os::idl::WireReader reader(connection); reader.expectAccept(); if (!reader.readListHeader()) { reader.fail(); return false; } yarp::os::ConstString tag = reader.readTag(); while (!reader.isError()) { // TODO: use quick lookup, this is just a test if (tag == "add_sample") { std::string className; yarp::sig::Vector sample; if (!reader.readString(className)) { reader.fail(); return false; } if (!reader.read(sample)) { reader.fail(); return false; } bool _return; _return = add_sample(className,sample); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "save") { std::string className; if (!reader.readString(className)) { reader.fail(); return false; } bool _return; _return = save(className); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "train") { bool _return; _return = train(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "forget") { std::string className; if (!reader.readString(className)) { reader.fail(); return false; } bool _return; _return = forget(className); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "classList") { std::vector<std::string> _return; _return = classList(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; { if (!writer.writeListBegin(BOTTLE_TAG_STRING, static_cast<uint32_t>(_return.size()))) return false; std::vector<std::string> ::iterator _iter16; for (_iter16 = _return.begin(); _iter16 != _return.end(); ++_iter16) { if (!writer.writeString((*_iter16))) return false; } if (!writer.writeListEnd()) return false; } } reader.accept(); return true; } if (tag == "stop") { bool _return; _return = stop(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "recognize") { bool _return; _return = recognize(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "classify_sample") { yarp::sig::Vector sample; if (!reader.read(sample)) { reader.fail(); return false; } std::string _return; _return = classify_sample(sample); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeString(_return)) return false; } reader.accept(); return true; } if (tag == "get_scores_for_sample") { yarp::sig::Vector sample; if (!reader.read(sample)) { reader.fail(); return false; } std::vector<ClassScore> _return; _return = get_scores_for_sample(sample); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; { if (!writer.writeListBegin(BOTTLE_TAG_LIST, static_cast<uint32_t>(_return.size()))) return false; std::vector<ClassScore> ::iterator _iter17; for (_iter17 = _return.begin(); _iter17 != _return.end(); ++_iter17) { if (!writer.writeNested((*_iter17))) return false; } if (!writer.writeListEnd()) return false; } } reader.accept(); return true; } if (tag == "get_parameter") { std::string parameterName; if (!reader.readString(parameterName)) { reader.fail(); return false; } std::string _return; _return = get_parameter(parameterName); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeString(_return)) return false; } reader.accept(); return true; } if (tag == "set_parameter") { std::string parameterName; std::string parameterValue; if (!reader.readString(parameterName)) { reader.fail(); return false; } if (!reader.readString(parameterValue)) { reader.fail(); return false; } bool _return; _return = set_parameter(parameterName,parameterValue); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (reader.noMore()) { reader.fail(); return false; } yarp::os::ConstString next_tag = reader.readTag(); if (next_tag=="") break; tag = tag + "_" + next_tag; } return false; }
static inline void add_code(struct oprofile_cpu_buffer *buffer, unsigned long value) { add_sample(buffer, ESCAPE_CODE, value); }