예제 #1
0
파일: demo.c 프로젝트: 5kg/lttng-tools
int main(int argc, char **argv)
{
	int i, netint;
	long values[] = { 1, 2, 3 };
	char text[10] = "test";
	double dbl = 2.0;
	float flt = 2222.0;
	int delay = 0;

	if (argc == 2)
		delay = atoi(argv[1]);

	fprintf(stderr, "Demo program starting.\n");

	sleep(delay);

	fprintf(stderr, "Tracing... ");
	tracepoint(ust_tests_demo, starting, 123);
	for (i = 0; i < 5; i++) {
		netint = htonl(i);
		tracepoint(ust_tests_demo2, loop, i, netint, values,
			   text, strlen(text), dbl, flt);
	}
	tracepoint(ust_tests_demo, done, 456);
	tracepoint(ust_tests_demo3, done, 42);
	fprintf(stderr, " done.\n");
	return 0;
}
예제 #2
0
void run_test(int num_threads, int num_iters, int cache_size, int lock_type) {
	int rc;
	long t;
	struct timespec start, end;
	pthread_t* threads = malloc(sizeof(pthread_t) * num_threads);

	shared.num_iters = num_iters;
	shared.cache = malloc(sizeof(Cache));
	cache_init(shared.cache, cache_size, lock_type);
	pthread_barrier_init(&shared.barrier, NULL, num_threads);

	tracepoint(tl, start_test, num_threads, num_iters, (!lock_type ? "mutex" : "rwlock"));
	clock_gettime(CLOCK_MONOTONIC, &start);
	for(t = 0; t < num_threads; t++) {
		rc = pthread_create(&threads[t], NULL, run_thread, (void *)t);
		if (rc != 0) {
			fprintf(stderr, "Error at pthread_create() with id %d\n", rc);
			exit(-1);
		}
	}
	for(t = 0; t < num_threads; t++) {
		pthread_join(threads[t], NULL);
	}
	clock_gettime(CLOCK_MONOTONIC, &end);
	tracepoint(tl, end_test, ELAPSED_TIME(start, end));

	cache_destroy(shared.cache);
	free(shared.cache);
	pthread_barrier_destroy(&shared.barrier);
	free(threads);
}
예제 #3
0
int pthread_mutex_lock(pthread_mutex_t *mutex)
{
	static int (*mutex_lock)(pthread_mutex_t *);
	int retval;

	if (!mutex_lock) {
		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
		if (!mutex_lock) {
			if (thread_in_trace) {
				abort();
			}
			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
			return EINVAL;
		}
	}
	if (thread_in_trace) {
		return mutex_lock(mutex);
	}

	thread_in_trace = 1;
	tracepoint(lttng_ust_pthread, pthread_mutex_lock_req, mutex,
		LTTNG_UST_CALLER_IP());
	retval = mutex_lock(mutex);
	tracepoint(lttng_ust_pthread, pthread_mutex_lock_acq, mutex,
		retval, LTTNG_UST_CALLER_IP());
	thread_in_trace = 0;
	return retval;
}
예제 #4
0
파일: main.c 프로젝트: 5kg/lttng-tools
/*
 * Thread recording a tracepoint every minute for 20 minutes.
 */
static void *th_event_minute(void *data)
{
	int i;

	/* Loop for 20 minutes */
	for (i = 1; i < 21; i++) {
		/* Sleep 60 seconds */
		poll(NULL, 0, 60000);

		/* 20 minutes tracepoint */
		if ((i % 20) == 0) {
			tracepoint(tp, slow, i, "twenty");
		}

		/* 10 minutes tracepoint */
		if ((i % 10) == 0) {
			tracepoint(tp, slow, i, "ten");
		}

		/* 1 minute tracepoint */
		tracepoint(tp, slow, i, "one");
	}

	return NULL;
}
예제 #5
0
static
void lttng_ust_dl_dlopen(void *so_base, const char *so_name, void *ip)
{
	char resolved_path[PATH_MAX];
	struct lttng_ust_elf *elf;
	uint64_t memsz;
	uint8_t *build_id;
	size_t build_id_len;
	char *dbg_file;
	uint32_t crc;
	int has_build_id = 0, has_debug_link = 0;
	int ret;

	if (!realpath(so_name, resolved_path)) {
		ERR("could not resolve path '%s'", so_name);
		return;
	}

	elf = lttng_ust_elf_create(resolved_path);
	if (!elf) {
		ERR("could not acces file %s", resolved_path);
		return;
	}

	ret = lttng_ust_elf_get_memsz(elf, &memsz);
	if (ret) {
		goto end;
	}
	ret = lttng_ust_elf_get_build_id(
		elf, &build_id, &build_id_len, &has_build_id);
	if (ret) {
		goto end;
	}
	ret = lttng_ust_elf_get_debug_link(
		elf, &dbg_file, &crc, &has_debug_link);
	if (ret) {
		goto end;
	}

	tracepoint(lttng_ust_dl, dlopen,
		ip, so_base, resolved_path, memsz);

	if (has_build_id) {
		tracepoint(lttng_ust_dl, build_id,
			ip, so_base, build_id, build_id_len);
		free(build_id);
	}

	if (has_debug_link) {
		tracepoint(lttng_ust_dl, debug_link,
			ip, so_base, dbg_file, crc);
		free(dbg_file);
	}

end:
	lttng_ust_elf_destroy(elf);
	return;
}
예제 #6
0
int main(int argc, char **argv) {
	unsigned int v = 42;
	/* Tracepoint 1 : ust_event */
	tracepoint(ust_event, v);
	/* Tracepoint 2 : ust_event2 */
	tracepoint(ust_event2, v);

	return 0;
}
예제 #7
0
파일: zipkin_c.c 프로젝트: mradhuber/blkin
int blkin_record(const struct blkin_trace *trace,
		 const struct blkin_annotation *annotation)
{
	int res;
	if (!annotation || !trace || !trace->name) {
		res = -EINVAL;
		goto OUT;
	}

	const struct blkin_endpoint *endpoint =
		annotation->endpoint ? : trace->endpoint;
	if (!endpoint || !endpoint->ip || !endpoint->name) {
		res = -EINVAL;
		goto OUT;
	}

	if (annotation->type == ANNOT_STRING) {
		if ((!annotation->key) || (!annotation->val_str)) {
			res = -EINVAL;
			goto OUT;
		}
		tracepoint(zipkin, keyval_string, trace->name,
			   endpoint->name, endpoint->port, endpoint->ip,
			   trace->info.trace_id, trace->info.span_id,
			   trace->info.parent_span_id,
			   annotation->key, annotation->val_str);
	}
	else if (annotation->type == ANNOT_INTEGER) {
		if (!annotation->key) {
			res = -EINVAL;
			goto OUT;
		}
		tracepoint(zipkin, keyval_integer, trace->name,
			   endpoint->name, endpoint->port, endpoint->ip,
			   trace->info.trace_id, trace->info.span_id,
			   trace->info.parent_span_id,
			   annotation->key, annotation->val_int);
	}
	else {
		if (!annotation->val_str) {
			res = -EINVAL;
			goto OUT;
		}
		tracepoint(zipkin, timestamp , trace->name,
			   endpoint->name, endpoint->port, endpoint->ip,
			   trace->info.trace_id, trace->info.span_id,
			   trace->info.parent_span_id,
			   annotation->val_str);
	}
	res = 0;
OUT:
	return res;
}
예제 #8
0
int main(int argc, char *argv[])
{
	int i;

	for (i = 0; i < 2; i++) {
		tracepoint(ust_tests_td, tptest, i % 2, (i+1) % 2, i % 21);
		tracepoint(ust_tests_td, tptest_bis,  i % 2);
	}

	tracepoint(ust_tests_td, test_auto);

	return 0;
}
예제 #9
0
void *worker(void *data) {
	struct worker_data *info = (struct worker_data *) data;
	int i;
	pthread_t self = pthread_self();
	tracepoint(bossthread, id, self);

	for(i=0; i<info->count; i++) {
		info->res++;
	}

	tracepoint(bossthread, id, self);
	return 0;
}
double PerlinNoise::noise(double x, double y, double z) const {
	// Find the unit cube that contains the point
	int X = (int) floor(x) & 255;
	int Y = (int) floor(y) & 255;
	int Z = (int) floor(z) & 255;

	// Find relative x, y,z of point in cube
	x -= floor(x);

	y -= floor(y);
	z -= floor(z);

	// Compute fade curves for each of x, y, z
	double u = fade(x);
	double v = fade(y);
	double w = fade(z);

	// Hash coordinates of the 8 cube corners
	int A = p[X] + Y;
	int AA = p[A] + Z;
	int AB = p[A + 1] + Z;
	int B = p[X + 1] + Y;
	int BA = p[B] + Z;
	int BB = p[B + 1] + Z;

	// Add blended results from 8 corners of cube
	double res = lerp(w, lerp(v, lerp(u, grad(p[AA], x, y, z), grad(p[BA], x-1, y, z)), lerp(u, grad(p[AB], x, y-1, z), grad(p[BB], x-1, y-1, z))),	lerp(v, lerp(u, grad(p[AA+1], x, y, z-1), grad(p[BA+1], x-1, y, z-1)), lerp(u, grad(p[AB+1], x, y-1, z-1),	grad(p[BB+1], x-1, y-1, z-1))));
	res += 1.0;
	res /= 2.0;
	tracepoint(com_vanwinkeljan_lttng_test_perlinnoise,noise,x,y,z,res);
	return res;
}
예제 #11
0
void CConfigManager::makedefault(void)
{
	CConfigReader reader;
	if(!copyFile(m_defaultFilePath.c_str(), m_mainFilePath.c_str()))
	{
		errorf("CConfigManager::CConfigManager() copy config file failed\n");
		assert(0);
	}
	else
	{
		if (!readConfig(m_defaultFilePath.c_str(), m_stream))
		{
			errorf("default config error!\n");
			assert(0);
		}
		else
		{
			if(reader.parse(m_stream, m_configDefault))
			{
				tracepoint();
				m_configAll = m_configDefault;
				std::cout << m_configAll << std::endl;
			}
			else
			{
				errorf("read default error!\n");
				assert(0);
			}
		}
	}
}
예제 #12
0
//create a PPM object and fill it with data stored in fname 
ppm::ppm(const std::string &fname) {
    init();
    read(fname);
    std::stringstream tmpStrStream;
    tmpStrStream << "Created PPM class and read data from file " << fname;
    tracepoint(com_vanwinkeljan_lttng_test_ppm, create, width,height,fname.c_str());
}
예제 #13
0
bool CConfigManager::getConfig(const char* name, CConfigTable& table)
{
	CGuard guard(m_mutex);
	int ret = applySuccess;

	if (strcmp(name, "All") == 0)
	{
		table = m_configAll;
		tracef("CConfigManager::getConfig get all Configs.\n");
		return true;
	}

	if(m_configDefault[name].type() == Json::nullValue)
	{
		warnf("CConfigManager::getConfig '%s', but default config is not set yet!\n", name);

		// 直接返回,不做默认配置替换和配置校验
		table = m_configAll[name];
		return table.type() != Json::nullValue;
	}

	table = m_configAll[name];
	tracepoint();
	infof("name is [%s]\n", name);
	//std::cout << table << std::endl;

	return table.type() != Json::nullValue;
}
예제 #14
0
void CConfigManager::saveFile()
{
	CGuard guard(m_mutex);

	CConfigWriter writer;

	if(!m_changed)
	{
		return;
	}

	m_changed = false;

	m_stream = "";
	m_stream = writer.write(m_configAll);
	m_fileConfig.Open(m_mainFilePath.c_str(), CFile::modeWrite | CFile::modeCreate);
	if (m_stream.size() != m_fileConfig.Write((char*)m_stream.c_str(), m_stream.size()))
	{
		errorf("CConfigManager::saveFile write main config file failed!\n");
	}
	tracepoint();
	m_fileConfig.Flush();
	m_fileConfig.Close();

}
예제 #15
0
파일: event.c 프로젝트: FrankYu/sheepdog
static void do_event_loop(int timeout, bool sort_with_prio)
{
	int i, nr;

refresh:
	event_loop_refresh = false;
	nr = epoll_wait(efd, events, nr_events, timeout);
	if (sort_with_prio)
		xqsort(events, nr, epoll_event_cmp);

	if (nr < 0) {
		if (errno == EINTR)
			return;
		sd_err("epoll_wait failed: %m");
		exit(1);
	} else if (nr) {
		tracepoint(event, loop_start, nr_events);

		for (i = 0; i < nr; i++) {
			struct event_info *ei;

			ei = (struct event_info *)events[i].data.ptr;
			ei->handler(ei->fd, events[i].events, ei->data);

			if (event_loop_refresh)
				goto refresh;
		}
	}
}
예제 #16
0
파일: event.c 프로젝트: FrankYu/sheepdog
int register_event_prio(int fd, event_handler_t h, void *data, int prio)
{
	int ret;
	struct epoll_event ev;
	struct event_info *ei;

	ei = xzalloc(sizeof(*ei));
	ei->fd = fd;
	ei->handler = h;
	ei->data = data;
	ei->prio = prio;

	memset(&ev, 0, sizeof(ev));
	ev.events = EPOLLIN;
	ev.data.ptr = ei;

	ret = epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ev);
	if (ret) {
		sd_err("failed to add epoll event for fd %d: %m", fd);
		free(ei);
	} else
		rb_insert(&events_tree, ei, rb, event_cmp);

	tracepoint(event, _register, fd, (void *)h, data, prio);

	return ret;
}
예제 #17
0
파일: ptask.c 프로젝트: glipari/ptask
void tpoint(char* flag, char* state) {
    pid_t tid = gettid();
    pid_t pid = getpid();
    struct timespec now;
    clock_gettime(CLOCK_REALTIME, &now);
    tracepoint(ptask_provider, ptask_tracepoint, pid, tid, ptask_idx, flag, state, tspec_to_rel(&now, MILLI), _tp[ptask_idx].priority, tspec_to(&_tp[ptask_idx].period, MICRO), tspec_to(&_tp[ptask_idx].deadline, MICRO));
}
예제 #18
0
파일: main.c 프로젝트: tanghaohao/examples
int main()
{
    int count = 0;
    while(count < 10) {
	tracepoint(osd, do_osd_op_pre_copy_get, "XXXX", count);
	count ++;
    }
}
예제 #19
0
파일: zipkin_c.c 프로젝트: agshew/blkin
int _blkin_record(struct blkin_trace *trace, struct blkin_annotation *annotation)
{
    int res;
    if ((!annotation) || (!trace)){
        res = -EINVAL;
        goto OUT;
    }
    if (!annotation->annotation_endpoint && trace->trace_endpoint)
        annotation->annotation_endpoint = trace->trace_endpoint;
    if (!trace->name) 
        trace->name = default_name;
    if (!annotation->annotation_endpoint->ip)
        annotation->annotation_endpoint->ip = default_ip;
    if (!annotation->annotation_endpoint->name)
        annotation->annotation_endpoint->name = default_name;

    if (annotation->type == ANNOT_STRING) {
        if ((!annotation->key) || (!annotation->val)) {
            res = -EINVAL;
            goto OUT;
        }
        tracepoint(zipkin, keyval, trace->name,
                annotation->annotation_endpoint->name,
                annotation->annotation_endpoint->port,
                annotation->annotation_endpoint->ip,
                trace->info.trace_id, trace->info.span_id,
                trace->info.parent_span_id,
                annotation->key, annotation->val);
    }
    else {
        if (!annotation->val) {
            res = -EINVAL;
            goto OUT;
        }
        tracepoint(zipkin, timestamp , trace->name,
                annotation->annotation_endpoint->name,
                annotation->annotation_endpoint->port,
                annotation->annotation_endpoint->ip,
                trace->info.trace_id, trace->info.span_id,
                trace->info.parent_span_id,
                annotation->val);
    }
    res = 0;
OUT:
    return res;
}
예제 #20
0
파일: main.c 프로젝트: tanghaohao/examples
int main()
{
    int count = 100;
    while(count--) {
	tracepoint(th, tracepoint_1, count, "aaa");
    }
    return 0;
}
예제 #21
0
파일: fork2.c 프로젝트: 5kg/lttng-tools
int main()
{
	printf("IN FORK2\n");

	tracepoint(ust_tests_fork, after_exec, getpid());

	return 0;
}
double PerlinNoise::grad(int hash, double x, double y, double z) const {
	int h = hash & 15;
	// Convert lower 4 bits of hash into 12 gradient directions
	double u = h < 8 ? x : y;
	double v = h < 4 ? y : h == 12 || h == 14 ? x : z;
	double res = ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
	tracepoint(com_vanwinkeljan_lttng_test_perlinnoise,grad,h,x,y,z,res);
	return res;
}
예제 #23
0
static
void trace_build_id_cb(struct lttng_session *session, void *priv)
{
	struct bin_info_data *bin_data = (struct bin_info_data *) priv;

	tracepoint(lttng_ust_statedump, build_id,
		session, bin_data->base_addr_ptr,
		bin_data->build_id, bin_data->build_id_len);
}
예제 #24
0
static
void trace_debug_link_cb(struct lttng_session *session, void *priv)
{
	struct bin_info_data *bin_data = (struct bin_info_data *) priv;

	tracepoint(lttng_ust_statedump, debug_link,
		session, bin_data->base_addr_ptr,
		bin_data->dbg_file, bin_data->crc);
}
예제 #25
0
int main(int argc, char **argv)
{
	int i, nr_iter = 100;
	long value = 42;

	if (argc == 2) {
		nr_iter = atoi(argv[1]);
	}

	for (i = 0; i < nr_iter; i++) {
		tracepoint(ust_gen_nevents, tptest0, i, value);
		tracepoint(ust_gen_nevents, tptest1, i, value);
		tracepoint(ust_gen_nevents, tptest2, i, value);
		tracepoint(ust_gen_nevents, tptest3, i, value);
	}

	return 0;
}
예제 #26
0
int main(int argc, char **argv)
{
	int i, netint, ret = 0;
	long values[] = { 1, 2, 3 };
	char text[10] = "test";
	double dbl = 2.0;
	float flt = 2222.0;
	unsigned int nr_iter = 100;
	useconds_t nr_usec = 0;

	if (argc >= 2) {
		nr_iter = atoi(argv[1]);
	}

	if (argc == 3) {
		/* By default, don't wait unless user specifies. */
		nr_usec = atoi(argv[2]);
	}

	for (i = 0; i < nr_iter; i++) {
		netint = htonl(i);
		tracepoint(tp, tptest1, i, netint, values, text, strlen(text),
			   dbl, flt);
		tracepoint(tp, tptest2, i, netint, values, text, strlen(text),
				dbl, flt);
		tracepoint(tp, tptest3, i, netint, values, text, strlen(text),
				dbl, flt);
		tracepoint(tp, tptest4, i, netint, values, text, strlen(text),
				dbl, flt);
		tracepoint(tp, tptest5, i, netint, values, text, strlen(text),
				dbl, flt);
		if (nr_usec) {
		        if (usleep_safe(nr_usec)) {
				ret = -1;
				goto end;
			}
		}
	}

end:
        exit(!ret ? EXIT_SUCCESS : EXIT_FAILURE);
}
예제 #27
0
파일: btraced.c 프로젝트: xaos-project/XaoS
static void
queue (void *data, struct taskinfo *task, int r1, int r2)
{
    int x, y, d, c;
    int pos = 0;

    while (1) {
        int nstack;
        xth_lock (0);
        while (!size) {         /*Well stack is empty. */
            if (exitnow) {      /*Possibly everything is done now.. */
                xth_unlock (0);
                return;
            }
            if (nwaiting == nthreads - 1) {     /*We are last working CPU */
                exitnow = 1;    /*So we should exit now */
                xth_wakeup (0); /*Wake up all waiting tasks */
                xth_unlock (0);
                return;         /*and exit :) */
            }
            nwaiting++;         /*We are not latest task. */
            xth_sleep (0, 0);   /*Wait until other task will push some data */
            nwaiting--;
            if (exitnow) {      /*Evrything is done now? */
                xth_unlock (0);
                return;
            }
        }
        nstack = xth_nthread (task);
        while (!sizes[nstack])
            if (nstack != nthreads - 1)
                nstack++;
            else
                nstack = 0;
        sizes[nstack]--;
        size--;
        pos++;
        if (pos >= sizes[nstack])
            pos = 0;
        x = starts[nstack][pos >> PAGESHIFT][pos & (PAGESIZE - 1)].x;
        y = starts[nstack][pos >> PAGESHIFT][pos & (PAGESIZE - 1)].y;
        d = starts[nstack][pos >> PAGESHIFT][pos & (PAGESIZE - 1)].direction;
        c = starts[nstack][pos >> PAGESHIFT][pos & (PAGESIZE - 1)].color;
        /* Well stack currently is queue. Should have better results at
         * SMP, since has tendency trace all ways at time, so (I believe)
         * should avoid some cache conflict and situation where queue is
         * empty. At the other hand, makes queue bigger and needs following
         * copy:
         */
        starts[nstack][pos >> PAGESHIFT][pos & (PAGESIZE - 1)] = starts[nstack][sizes[nstack] >> PAGESHIFT][sizes[nstack] & (PAGESIZE - 1)];
        xth_unlock (0);
        tracepoint (x, y, d, c, xstart, xend, ystart, yend);
    }
}
예제 #28
0
static
void trace_lib_load(const struct bin_info_data *bin_data, void *ip)
{
	tracepoint(lttng_ust_lib, load,
		ip, bin_data->base_addr_ptr, bin_data->resolved_path,
		bin_data->memsz, bin_data->has_build_id,
		bin_data->has_debug_link);

	if (bin_data->has_build_id) {
		tracepoint(lttng_ust_lib, build_id,
			ip, bin_data->base_addr_ptr, bin_data->build_id,
			bin_data->build_id_len);
	}

	if (bin_data->has_debug_link) {
		tracepoint(lttng_ust_lib, debug_link,
			ip, bin_data->base_addr_ptr, bin_data->dbg_file,
			bin_data->crc);
	}
}
int dlclose(void *handle)
{
	if (__tracepoint_ptrs_registered && handle) {
		struct link_map *p = NULL;
		if (dlinfo(handle, RTLD_DI_LINKMAP, &p) != -1 && p != NULL
				&& p->l_addr != 0)
			tracepoint(lttng_ust_dl, dlclose, (void *) p->l_addr,
				__builtin_return_address(0));
	}
	return _lttng_ust_dl_libc_dlclose(handle);
}
예제 #30
0
void thorium_actor_send_range_default(struct thorium_actor *actor, struct core_vector *actors,
                int first, int last,
                struct thorium_message *message)
{
    int use_binomial_tree;
    struct core_vector destinations;
    struct core_memory_pool *ephemeral_memory;
    int name;
    int action;

    action = thorium_message_action(message);
    use_binomial_tree = 0;

#ifdef USE_BINOMIAL_TREE

    /*
     * ACTION_ASK_TO_STOP basically kills actors (if they agree to).
     * It is a bad idea to use a binomial tree to send this death signal
     * since intermediate actors can die before acting as relays.
     */
    if (action != ACTION_ASK_TO_STOP)
        use_binomial_tree = 1;
#endif

    if (!use_binomial_tree) {
        thorium_actor_send_range_loop(actor, actors, first, last, message);
        return;
    }

    tracepoint(thorium_binomial_tree, send_range, message, (int)core_vector_size(actors));

    /*
     * Otherwise, use the binomial tree code path. This algorithm is better since it distributed
     * the sending operations intot a binomial tree where there are a lot of intermediate
     * actors (to be exact, the number of intermediate actors is close to log2(actors.size)).
     */
    ephemeral_memory = thorium_actor_get_ephemeral_memory(actor);
    core_vector_init(&destinations, sizeof(int));
    core_vector_set_memory_pool(&destinations, ephemeral_memory);

    CORE_DEBUGGER_ASSERT(core_vector_empty(&destinations));

    core_vector_copy_range(actors, first, last, &destinations);

    /*
     * Set the source now.
     */
    name = thorium_actor_name(actor);
    thorium_message_set_source(message, name);

    thorium_actor_send_range_binomial_tree(actor, &destinations, message);

    core_vector_destroy(&destinations);
}