• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ perf_event_open函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中perf_event_open函数的典型用法代码示例。如果您正苦于以下问题:C++ perf_event_open函数的具体用法?C++ perf_event_open怎么用?C++ perf_event_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了perf_event_open函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: memset

void Performance::_add(perf_type_id type, long long config) {
    struct perf_event_attr pe;
    memset(&pe, 0, sizeof(struct perf_event_attr));
    pe.size = sizeof(struct perf_event_attr);
    pe.exclude_kernel = 1;
    pe.exclude_hv = 1;

    pe.type = type;
    pe.config = config;


    order[events].type = type;
    order[events].config = config;
    events++;

    if (fd == -1) {
        /* if changed: change calculations in get */
        pe.read_format = PERF_FORMAT_GROUP;
        pe.disabled = 1;

        fd = perf_event_open(&pe, 0, -1, -1, 0);
        if (fd < 0) {
            fprintf(stderr, "Error opening leader for %llx / %llx\n", (long long) type, config);
            exit(EXIT_FAILURE);
        }
    } else {
        int ret = perf_event_open(&pe, 0, -1, fd, 0);
        if (ret < 0) {
            fprintf(stderr, "Error connecting to leader for %llx / %llx\n", (long long) type, config);
            exit(EXIT_FAILURE);
        }
    }
}
开发者ID:YnkDK,项目名称:dynAlg14,代码行数:33,代码来源:performance.cpp


示例2: malloc

int *fd_group_init(int num_events, char **events) {
  struct perf_event_attr *attr;
  int fd, ret, leader_fd, i;
  int *fds = malloc(num_events * sizeof(int));
  if (!fds) err(1, "could not allocate memory");
  attr = calloc(num_events, sizeof(*attr));
  // do refs, then misses
  for (i = 0; i < num_events; i++) {
    /*
     * 1st argument: event string
     * 2nd argument: default privilege level (used if not specified in the event string)
     * 3rd argument: the perf_event_attr to initialize
     */
    ret = pfm_get_perf_event_encoding(events[i], PFM_PLM3, &attr[i], NULL, NULL);
    if (ret != PFM_SUCCESS) errx(1, "evt %d: cannot find encoding: %s", i, pfm_strerror(ret));
    printf("Using encoding %lx for event %s\n", attr[i].config, events[i]);

    attr[i].inherit = 0; // inheritance currently doesn't work with FORMAT_GROUP

    /*
     * request timing information because event may be multiplexed
     * and thus it may not count all the time. The scaling information
     * will be used to scale the raw count as if the event had run all
     * along
     */
    attr[i].read_format = PERF_FORMAT_TOTAL_TIME_ENABLED|PERF_FORMAT_TOTAL_TIME_RUNNING
                          | PERF_FORMAT_GROUP;

    /* do not start immediately after perf_event_open() */
    attr[i].disabled = 1;

    /*
     * create the event and attach to self
     * Note that it attaches only to the main thread, there is no inheritance
     * to threads that may be created subsequently.
     *
     * if mulithreaded, then getpid() must be replaced by gettid()
     */
    if (i == 0) {
      fd = perf_event_open(&attr[i], 0, -1, -1, 0);
      fds[i] = fd;
      leader_fd = fd;
    } else {
      fd = perf_event_open(&attr[i], 0, -1, leader_fd, 0);
      fds[i] = fd;
    }
    if (fd < 0) {
      warn("warning: evt %d: cannot create event", i);
      free(attr);
      free(fds);
      return NULL;
    }
  }
  free(attr);
  return fds;
}
开发者ID:Qilewuqiong,项目名称:ReuseDistancePintool,代码行数:56,代码来源:perfctr_op.c


示例3: setup

static void setup(void)
{
	int i;
	struct perf_event_attr tsk_event, hw_event;

	/*
	 * According to perf_event_open's manpage, the official way of
	 * knowing if perf_event_open() support is enabled is checking for
	 * the existence of the file /proc/sys/kernel/perf_event_paranoid.
	 */
	if (access("/proc/sys/kernel/perf_event_paranoid", F_OK) == -1)
		tst_brkm(TCONF, NULL, "Kernel doesn't have perf_event support");

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	nhw = count_hardware_counters();
	n = nhw + 4;

	memset(&hw_event, 0, sizeof(struct perf_event_attr));
	memset(&tsk_event, 0, sizeof(struct perf_event_attr));

	tsk_event.type =  PERF_TYPE_SOFTWARE;
	tsk_event.size = sizeof(struct perf_event_attr);
	tsk_event.disabled = 1;
	tsk_event.config = PERF_COUNT_SW_TASK_CLOCK;

	hw_event.type = PERF_TYPE_HARDWARE;
	hw_event.size = sizeof(struct perf_event_attr);
	hw_event.disabled = 1;
	hw_event.config =  PERF_COUNT_HW_INSTRUCTIONS;

	tsk0 = perf_event_open(&tsk_event, 0, -1, -1, 0);
	if (tsk0 == -1) {
		tst_brkm(TBROK | TERRNO, cleanup, "perf_event_open failed");
	} else {
		tsk_event.disabled = 0;
		for (i = 0; i < n; ++i) {
			hwfd[i] = perf_event_open(&hw_event, 0, -1, -1, 0);
			tskfd[i] = perf_event_open(&tsk_event, 0, -1,
						   hwfd[i], 0);
			if (tskfd[i] == -1 || hwfd[i] == -1) {
				tst_brkm(TBROK | TERRNO, cleanup,
					 "perf_event_open failed");
			}
		}
	}
}
开发者ID:cjp0209,项目名称:ltp,代码行数:49,代码来源:perf_event_open02.c


示例4: perf_event__open

struct mmap_pages *
perf_event__open(struct event_open *e_open)
{
	int fd = -1;

	e_open->attr.disabled 		= 0;
	e_open->attr.size 		= sizeof(e_open->attr);
	e_open->attr.sample_period	= 1;
	e_open->attr.inherit		= 1;
	e_open->attr.sample_type 	= PERF_SAMPLE_TIME 	|
					  PERF_SAMPLE_RAW  	|
					  PERF_SAMPLE_CPU	|
					  PERF_SAMPLE_TID  	;
	e_open->attr.__reserved_1	= 0;
	e_open->attr.read_format	= PERF_FORMAT_TOTAL_TIME_ENABLED |
					  PERF_FORMAT_TOTAL_TIME_RUNNING ;

	fd = perf_event_open(&e_open->attr,e_open->pid,e_open->cpu	\
				,e_open->group_id,e_open->flags);

	if(fd < 0) {
		fprintf(stderr,"Failed to open event FD\n");
		return NULL;
	}

	struct mmap_pages *mmap_pages = NULL;
	mmap_pages = mmap_pages__new(fd,8);
	if(mmap_pages != NULL) {
		mmap_pages->attr = e_open->attr;
		fcntl(fd, F_SETFL, O_NONBLOCK);
	}
	return mmap_pages;
}
开发者ID:SahilAggarwal,项目名称:prof,代码行数:33,代码来源:perf_event.c


示例5: main

int main(int ac, char **av)
{
	int test = 0;
	int ret = 0;

	while (*++av) {
		if (!strcmp(*av, "--test")) {
			test = 1;
			continue;
		}

		struct perf_event_attr attr;
		if (resolve_event(*av, &attr) < 0) {
			fprintf(stderr, "Cannot resolve %s\n", *av); 
			ret = 1;
			continue;
		}
		char *ev = format_raw_event(&attr, *av);
		printf("%s\n", ev);
		free(ev);
		if (test) {
			if (perf_event_open(&attr, 0, -1, -1, 0) < 0)
				perror("perf_event_open");
		}
	}
	return ret;
}
开发者ID:Atlantic777,项目名称:pmu-tools,代码行数:27,代码来源:showevent.c


示例6: perf_start

void perf_start(const char* kname) {
  if (!enabled) return;

  char* prof_envvar = getenv("MXPA_PROFILE");

  int tids[32];
  int ntid;
  get_tids(tids, &ntid);
  g_nthreads = ntid;

  int n;
  for (n = 0; n < ntid; n++) {
    int ret;
    ret = perf_setup_list_events(prof_envvar, &(g_fds[n]), &num_fds);
    perf_event_desc_t *fds = g_fds[n];
    int cpu = -1;
    int group_fd = -1;
    int pid = tids[n];
    fds[0].fd = -1;
    int i;
    for(i=0; i < num_fds; i++) {
      fds[i].hw.read_format = PERF_FORMAT_SCALE;
      fds[i].hw.disabled = 1; /* do not start now */
      fds[i].hw.inherit = 1;  /* XXX child process will inherit, when forked only? */

      /* each event is in an independent group (multiplexing likely) */
      fds[i].fd = perf_event_open(&fds[i].hw, pid, cpu, group_fd, 0);
      if (fds[i].fd == -1) {
        fprintf(stderr, "cannot open event %d\n", i);
        exit(2);
      }
    }
  }
  prctl(PR_TASK_PERF_EVENTS_ENABLE);
}
开发者ID:abduld,项目名称:Parboil,代码行数:35,代码来源:perfmon.c


示例7: perfevent_initialize

void perfevent_initialize(char*events) {
  int i, ret;
  perfevent_events = strdup(events);

  /*
   * Initialize pfm library (required before we can use it)
   */
  ret = pfm_initialize();
  if (ret != PFM_SUCCESS)
    errx(1, "Cannot initialize library: %s", pfm_strerror(ret));

  ret = perf_setup_list_events(events, &perfevent_fds, &perfevent_num_fds);
  if (ret || !perfevent_num_fds)
    errx(1, "cannot setup events");

  perfevent_fds[0].fd = -1;
  for(i=0; i < perfevent_num_fds; i++) {
    /* request timing information necessary for scaling */
    perfevent_fds[i].hw.read_format = PERF_FORMAT_SCALE;

    perfevent_fds[i].hw.disabled = (i == 0); /* do not start now */
    perfevent_fds[i].hw.inherit = 1; /* pass on to child threads */

    /* each event is in an independent group (multiplexing likely) */
    perfevent_fds[i].fd = perf_event_open(&perfevent_fds[i].hw, 0, -1, perfevent_fds[0].fd, 0);
    if (perfevent_fds[i].fd == -1)
      err(1, "cannot open event %d", i);
  }
}
开发者ID:ShimProfiler,项目名称:SHIM,代码行数:29,代码来源:perf_event_agent.c


示例8: parent

void parent(int sock) {

	ssize_t size;
	int fd,i;
	struct perf_event_attr pe;

	memset(&pe,0,sizeof(struct perf_event_attr));
	pe.type=PERF_TYPE_HARDWARE;
	pe.size=sizeof(struct perf_event_attr);
	pe.config=PERF_COUNT_HW_INSTRUCTIONS;
	pe.disabled=1;
	pe.exclude_kernel=1;
	pe.exclude_hv=1;

	arch_adjust_domain(&pe,quiet);

	fd=perf_event_open(&pe,0,-1,-1,0);
	if (fd<0) {
		fprintf(stderr,"Error opening leader %llx %s\n",pe.config,strerror(errno));
		test_fail(test_string);
	}

	size = sock_fd_write(sock, "1", 1, fd);
	if (!quiet) printf ("wrote fd %d (size %d)\n", fd, (int)size);

	sleep(1);

	for(i=0;i<20;i++) instructions_million();

}
开发者ID:alexpark07,项目名称:perf_event_tests,代码行数:30,代码来源:socket_pass.c


示例9: setup_event

int setup_event(struct event *e, int cpu, struct event *leader,
		bool measure_all, int measure_pid)
{
	e->attr.inherit = 1;
	if (!measure_all) {
		e->attr.disabled = 1;
		e->attr.enable_on_exec = 1;
	}
	e->attr.read_format |= PERF_FORMAT_TOTAL_TIME_ENABLED |
				PERF_FORMAT_TOTAL_TIME_RUNNING;

	e->efd[cpu].fd = perf_event_open(&e->attr,
			measure_all ? -1 : measure_pid,
			cpu,
			leader ? leader->efd[cpu].fd : -1,
			0);

	if (e->efd[cpu].fd < 0) {
		/* Handle offline CPU */
		if (errno == EINVAL && !cpu_online(cpu))
			return 0;

		fprintf(stderr, "Cannot open perf event for %s/%d: %s\n",
				e->event, cpu, strerror(errno));
		return -1;
	}
	return 0;
}
开发者ID:Atlantic777,项目名称:pmu-tools,代码行数:28,代码来源:session.c


示例10: main

int main(int argc, char **argv) {

	int fd;

	struct perf_event_attr pe;

	int i;
	int result;
	long long counts[1],prev=0;

	long long total=0,average,max=0,min=0x7ffffffffffffffULL;

	memset(&pe,0,sizeof(struct perf_event_attr));
	pe.type=PERF_TYPE_HARDWARE;
	pe.size=sizeof(struct perf_event_attr);
	pe.config=PERF_COUNT_HW_INSTRUCTIONS;
	pe.disabled=1;
	pe.exclude_kernel=1;
	pe.exclude_hv=1;

	fd=perf_event_open(&pe,0,-1,-1,0);
	if (fd<0) {
     		fprintf(stderr,"Error opening leader %llx %s\n",pe.config,strerror(errno));
		exit(1);
	}

	ioctl(fd, PERF_EVENT_IOC_RESET, 0);
	ioctl(fd, PERF_EVENT_IOC_ENABLE,0);

	for(i=0;i<NUM_RUNS;i++) {

		result=instructions_million();

		result=read(fd,&counts,sizeof(long long));

		results[i]=counts[0]-prev;
		prev=counts[0];

 	}

	ioctl(fd, PERF_EVENT_IOC_DISABLE,0);

	close(fd);

	for(i=0;i<NUM_RUNS;i++) {
		total+=results[i];
		if (results[i]>max) max=results[i];
		if (results[i]<min) min=results[i];
	}

	average=total/NUM_RUNS;
	printf("Average=%lld max=%lld min=%lld\n",average,max,min);

	(void) result;

	return 0;
}
开发者ID:alexpark07,项目名称:perf_event_tests,代码行数:57,代码来源:100b_perf.c


示例11: measure

int
measure(pid_t pid)
{
	perf_event_desc_t *fds = NULL;
	int i, ret, num_fds = 0;
	char fn[32];

	if (pfm_initialize() != PFM_SUCCESS)
		errx(1, "libpfm initialization failed\n");

	ret = perf_setup_list_events(options.events, &fds, &num_fds);
	if (ret || (num_fds == 0))
		exit(1);

	fds[0].fd = -1;
	for(i=0; i < num_fds; i++) {
		fds[i].hw.disabled = 0; /* start immediately */

		/* request timing information necessary for scaling counts */
		fds[i].hw.read_format = PERF_FORMAT_SCALE;
		fds[i].hw.pinned = !i && options.pinned;
		fds[i].fd = perf_event_open(&fds[i].hw, pid, -1, (options.group? fds[0].fd : -1), 0);
		if (fds[i].fd == -1)
			errx(1, "cannot attach event %s", fds[i].name);
	}
	/*
	 * no notification is generated by perf_counters
	 * when the monitored thread exits. Thus we need
	 * to poll /proc/ to detect it has disappeared,
	 * otherwise we have to wait until the end of the
	 * timeout
	 */
	sprintf(fn, "/proc/%d/status", pid);

	while(access(fn, F_OK) == 0 && options.delay) {
		sleep(1);
		options.delay--;
		if (options.print)
			print_counts(fds, num_fds, 1);
	}
	if (options.delay)
		warn("thread %d terminated before timeout", pid);

	if (!options.print)
		print_counts(fds, num_fds, 0);

	for(i=0; i < num_fds; i++)
		close(fds[i].fd);

	free(fds);

	/* free libpfm resources cleanly */
	pfm_terminate();

	return 0;
}
开发者ID:multics69,项目名称:danbi,代码行数:56,代码来源:task_attach_timeout.c


示例12: main

int main()
{
#ifdef __NR_perf_event_open
    struct perf_event_attr pe;
    int fd;
    long long count;

    memset(&pe, 0, sizeof(struct perf_event_attr));
    pe.type = PERF_TYPE_SOFTWARE;
    pe.size = sizeof(struct perf_event_attr);
    pe.config = PERF_COUNT_SW_CPU_CLOCK;
    pe.disabled = 0;
    pe.exclude_kernel = 1;
    pe.exclude_hv = 1;

    fd = perf_event_open(&pe, 0, -1, -1, 0);
    //staptest// perf_event_open (XXXX, 0, -1, -1, 0x0) = NNNN

    sleep(1);
    
    ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
    read(fd, &count, sizeof(count));
    
    // Limit testing.

    fd = perf_event_open((struct perf_event_attr*)-1, 0, -1, -1, 0);
#ifdef __s390__
    //staptest// perf_event_open (0x[7]?[f]+, 0, -1, -1, 0x0) = -NNNN
#else
    //staptest// perf_event_open (0x[f]+, 0, -1, -1, 0x0) = -NNNN
#endif

    fd = perf_event_open(&pe, -1, -1, -1, 0);
    //staptest// perf_event_open (XXXX, -1, -1, -1, 0x0) = -NNNN

    fd = perf_event_open(&pe, 0, -1, -1, -1);
    //staptest// perf_event_open (XXXX, 0, -1, -1, PERF_FLAG_[^ ]+|XXXX) = -NNNN
    
    close(fd);
#endif
    return 0;
}
开发者ID:h4ck3rm1k3,项目名称:systemtap,代码行数:42,代码来源:perf_event.c


示例13: setupHandler

int setupHandler(int sig) {
  // Perf event settings
  struct perf_event_attr pe;

	memset(&pe, 0, sizeof(struct perf_event_attr));
	 
  pe.type = PERF_TYPE_HW_CACHE;
  pe.size = sizeof(struct perf_event_attr);
	pe.config = (PERF_COUNT_HW_CACHE_L1D << 0) | (PERF_COUNT_HW_CACHE_OP_READ << 8) | (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16); 
	//pe.config = (PERF_COUNT_HW_CACHE_L1D << 0) | (PERF_COUNT_HW_CACHE_OP_WRITE << 8) | (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16); 
  pe.disabled = 1;
	pe.exclude_kernel = 1;
	pe.exclude_hv = 1;
//	pe.exclude_callchain_kernel = 1;
//  pe.exclude_idle = 1;
  pe.sample_period = 1000;
//	pe.sample_id_all = 1;
	pe.sample_type=sample_type;
//	pe.precise_ip = 0;
 // pe.read_format=read_format;
	// Record those information when trap happens
	//pe.sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID | PERF_SAMPLE_ADDR;
 
  // Create the perf_event for this thread on all CPUs with no event group
  int perf_fd = perf_event_open(&pe, 0, -1, -1, 0);
  if(perf_fd == -1) {
    fprintf(stderr, "Failed to open perf event file: %s\n", strerror(errno));
    abort();
  }
 
	// Setting up 9 pages to pass information about a trap
	our_mmap=mmap(NULL, 9*4096,
      PROT_READ|PROT_WRITE, MAP_SHARED, perf_fd, 0);
 
  // Set the perf_event file to async mode
  if(fcntl(perf_fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC) == -1) {
    fprintf(stderr, "Failed to set perf event file to ASYNC mode: %s\n", strerror(errno));
    abort();
  }
  
  // Tell the file to send a SIGUSR1 when an event occurs
  if(fcntl(perf_fd, F_SETSIG, sig) == -1) {
    fprintf(stderr, "Failed to set perf event file's async signal: %s\n", strerror(errno));
    abort();
  }
  
  // Deliver the signal to this thread
  if(fcntl(perf_fd, F_SETOWN, getpid()) == -1) {
    fprintf(stderr, "Failed to set the owner of the perf event file: %s\n", strerror(errno));
    abort();
  }
  
  return perf_fd;
}
开发者ID:UTSASRG,项目名称:DifferentTries,代码行数:54,代码来源:getaddrMmap.cpp


示例14: perf_init

int perf_init(unsigned int num_ctrs, ...) {
    va_list args;
	int ctr, ret = 0;
	number = num_ctrs;

	attr = (struct perf_event_attr*)calloc(num_ctrs, sizeof(struct perf_event_attr));
	fds  = (int*) malloc(sizeof(int) * num_ctrs);
	if (attr == NULL || fds == NULL) {
		perror("Could not allocate space for counter data: ");
		ret = -1;
		goto error;
	}

    //Configure each counter, staring with 1
    va_start(args, num_ctrs);
    for (ctr=0; ctr<num_ctrs; ctr++) {
        unsigned event, conf;
        conf = va_arg(args, unsigned int) & 0xFFFFFF;
        event = conf & 0xFFFF;

		attr[ctr].type = PERF_TYPE_RAW;
		attr[ctr].config = event; /* generic PMU event*/
		attr[ctr].disabled = 0;
		attr[ctr].pinned = 1;
		attr[ctr].inherit = 1;
		fds[ctr] = perf_event_open(&attr[ctr], getpid(), -1, -1, 0);
		if ((conf & PERFMON_EVENTSEL_OS) == 0)
			attr[ctr].exclude_kernel = 1; 
		if ((conf & PERFMON_EVENTSEL_USR) == 0)
			attr[ctr].exclude_user= 1; 

		if (fds[ctr] < 0) {
			perror("Opening performance counter");
			goto error;
		}
    }
    va_end(args);

    return ret;

error:
	number = 0;
	if (attr) {
		free(attr);
		attr = NULL;
	}
	if (fds) {
		free(fds);
		fds = NULL;
	}
	return ret;
}
开发者ID:castl,项目名称:easyperf,代码行数:52,代码来源:easyperf.c


示例15: perf_open

static int perf_open(void)
{
	struct perf_event_attr attr;

	memset(&attr, 0, sizeof (attr));

	attr.type = i915_type_id();
	if (attr.type == 0)
		return -ENOENT;
	attr.config = I915_PERF_ENERGY;

	attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED;
	return perf_event_open(&attr, -1, 0, -1, 0);
}
开发者ID:Acidburn0zzz,项目名称:intel-gpu-tools,代码行数:14,代码来源:power.c


示例16: perf_tracepoint_open

static int perf_tracepoint_open(struct gpu_perf *gp,
				const char *sys, const char *name,
				int (*func)(struct gpu_perf *, const void *))
{
	struct perf_event_attr attr;
	struct gpu_perf_sample *sample;
	int n, *fd;

	memset(&attr, 0, sizeof (attr));

	attr.type = PERF_TYPE_TRACEPOINT;
	attr.config = tracepoint_id(sys, name);
	if (attr.config == 0)
		return ENOENT;

	attr.sample_period = 1;
	attr.sample_type = (PERF_SAMPLE_TIME | PERF_SAMPLE_STREAM_ID | PERF_SAMPLE_TID | PERF_SAMPLE_RAW);
	attr.read_format = PERF_FORMAT_ID;

	attr.exclude_guest = 1;

	n = gp->nr_cpus * (gp->nr_events+1);
	fd = realloc(gp->fd, n*sizeof(int));
	sample = realloc(gp->sample, n*sizeof(*gp->sample));
	if (fd == NULL || sample == NULL)
		return ENOMEM;
	gp->fd = fd;
	gp->sample = sample;

	fd += gp->nr_events * gp->nr_cpus;
	sample += gp->nr_events * gp->nr_cpus;
	for (n = 0; n < gp->nr_cpus; n++) {
		uint64_t track[2];

		fd[n] = perf_event_open(&attr, -1, n, -1, 0);
		if (fd[n] == -1)
			return errno;

		/* read back the event to establish id->tracepoint */
		if (read(fd[n], track, sizeof(track)) < 0)
			return errno;
		sample[n].id = track[1];
		sample[n].func = func;
	}

	gp->nr_events++;
	return 0;
}
开发者ID:vsyrjala,项目名称:intel-gpu-tools,代码行数:48,代码来源:gpu-perf.c


示例17: sysPerfEventCreate

 EXTERNAL void sysPerfEventCreate(int id, const char *eventName)
 {
   TRACE_PRINTF("%s: sysPerfEventCreate\n", Me);
   struct perf_event_attr *pe = (perf_event_attrs + id);
   int ret = pfm_get_perf_event_encoding(eventName, PFM_PLM3, pe, NULL, NULL);
   if (ret != PFM_SUCCESS) {
     errx(1, "error creating event %d '%s': %s\n", id, eventName, pfm_strerror(ret));
   }
   pe->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING;
   pe->disabled = 1;
   pe->inherit = 1;
   perf_event_fds[id] = perf_event_open(pe, 0, -1, -1, 0);
   if (perf_event_fds[id] == -1) {
     err(1, "error in perf_event_open for event %d '%s'", id, eventName);
   }
 }
开发者ID:abhijangda,项目名称:JikesRVM,代码行数:16,代码来源:sysPerfEvent.c


示例18: perf_i915_open

static int perf_i915_open(int config, int group)
{
	struct perf_event_attr attr;

	memset(&attr, 0, sizeof (attr));

	attr.type = i915_type_id();
	if (attr.type == 0)
		return -ENOENT;
	attr.config = config;

	attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED;
	if (group == -1)
		attr.read_format |= PERF_FORMAT_GROUP;

	return perf_event_open(&attr, -1, 0, group, 0);
}
开发者ID:vsyrjala,项目名称:intel-gpu-tools,代码行数:17,代码来源:gpu-freq.c


示例19: kprobe_attach_one

static int kprobe_attach_one(kprobe_t *kp, const char *func)
{
	struct perf_event_attr attr = {};
	int efd, i, id;

	id = kprobe_event_id(kp, func);
	if (id < 0)
		return id;

	attr.type = PERF_TYPE_TRACEPOINT;
	attr.sample_type = PERF_SAMPLE_RAW;
	attr.sample_period = 1;
	attr.wakeup_events = 1;
	attr.config = id;

	for (i = 0; i < /* sysconf(_SC_NPROCESSORS_ONLN) */ 1; i++) {
		efd = perf_event_open(&attr, -1/*pid*/, i/*cpu*/, -1/*group_fd*/, 0);
		if (efd < 0) {
			perror("perf_event_open");
			return -errno;
		}

		if (ioctl(efd, PERF_EVENT_IOC_ENABLE, 0)) {
			perror("perf enable");
			close(efd);
			return -errno;
		}

		if (!i && ioctl(efd, PERF_EVENT_IOC_SET_BPF, kp->bfd)) {
			_pe("perf-set-bpf: %s", func);
			close(efd);
			return -errno;
		}

		if (kp->efds.len == kp->efds.cap) {
			size_t sz = kp->efds.cap * sizeof(*kp->efds.fds);

			kp->efds.fds = realloc(kp->efds.fds, sz << 1);
			assert(kp->efds.fds);
			kp->efds.cap <<= 1;
		}

		kp->efds.fds[kp->efds.len++] = efd;
	}
	return 1;
}
开发者ID:GeassDB,项目名称:ply,代码行数:46,代码来源:kprobe.c


示例20: setup_perf_event

int setup_perf_event(int cpu_id, PerfmonEvent* event)
{
    struct perf_event_attr attr;
    if (event == NULL)
    {
        return -EINVAL;
    }
    if (cpu_event_fds[cpu_id] == NULL)
    {
        return -EFAULT;
    }
    if (cpu_event_fds[cpu_id][event->umask] != -1)
    {
        return 0;
    }
    memset(&attr, 0, sizeof(struct perf_event_attr));
    attr.type = PERF_TYPE_SOFTWARE;
    attr.size = sizeof(struct perf_event_attr);
    attr.config = configList[event->umask];
    attr.exclude_kernel = 1;
    attr.exclude_hv = 1;
    attr.disabled = 1;
    attr.inherit = 1;
    if (event->numberOfOptions > 0)
    {
        for(int j = 0; j < event->numberOfOptions; j++)
        {
            switch (event->options[j].type)
            {
                case EVENT_OPTION_COUNT_KERNEL:
                    attr.exclude_kernel = 0;
                    break;
                default:
                    break;
            }
        }
    }
    cpu_event_fds[cpu_id][event->umask] = perf_event_open(&attr, 0, cpu_id, -1, 0);
    if (cpu_event_fds[cpu_id][event->umask] < 0)
    {
        printf("Setup of event %llu failed\n", event->umask);
        return -EFAULT;
    }
    return 0;
}
开发者ID:ProgramFan,项目名称:likwid,代码行数:45,代码来源:perfmon_perf.c



注:本文中的perf_event_open函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ perf_free函数代码示例发布时间:2022-05-30
下一篇:
C++ perf_event_init_task函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap