dfaf77
commit a37160c18eb8106a2b61ed181e2479a83381f3dc
dfaf77
Author: James Ralph <ralph@icl.utk.edu>
dfaf77
Date:   Fri Jul 25 15:59:41 2014 -0400
dfaf77
dfaf77
    perf_event.c: cleanup error messages
dfaf77
    
dfaf77
    Thanks to Gary Mohr
dfaf77
    -------------------
dfaf77
    This patch contains general cleanup code.  Calls to PAPIERROR pass a string which does
dfaf77
    not need to end with a new line because this function will always add one.  New lines at
dfaf77
    the end of strings passed to this function have been removed.  These changes also add
dfaf77
    some additional debug messages.
dfaf77
dfaf77
diff --git a/src/components/perf_event/perf_event.c b/src/components/perf_event/perf_event.c
dfaf77
index 049c810..3eea38d 100644
dfaf77
--- a/src/components/perf_event/perf_event.c
dfaf77
+++ b/src/components/perf_event/perf_event.c
dfaf77
@@ -300,11 +300,10 @@ sys_perf_event_open( struct perf_event_attr *hw_event, pid_t pid, int cpu,
dfaf77
 {
dfaf77
 	int ret;
dfaf77
 
dfaf77
-   SUBDBG("sys_perf_event_open(%p,%d,%d,%d,%lx\n",hw_event,pid,cpu,group_fd,flags);
dfaf77
+   SUBDBG("sys_perf_event_open(hw_event: %p, pid: %d, cpu: %d, group_fd: %d, flags: %lx\n", hw_event, pid, cpu, group_fd, flags);
dfaf77
    SUBDBG("   type: %d\n",hw_event->type);
dfaf77
    SUBDBG("   size: %d\n",hw_event->size);
dfaf77
-   SUBDBG("   config: %"PRIx64" (%"PRIu64")\n",hw_event->config,
dfaf77
-	  hw_event->config);
dfaf77
+   SUBDBG("   config: %"PRIx64" (%"PRIu64")\n",hw_event->config, hw_event->config);
dfaf77
    SUBDBG("   sample_period: %"PRIu64"\n",hw_event->sample_period);
dfaf77
    SUBDBG("   sample_type: %"PRIu64"\n",hw_event->sample_type);
dfaf77
    SUBDBG("   read_format: %"PRIu64"\n",hw_event->read_format);
dfaf77
@@ -323,6 +322,21 @@ sys_perf_event_open( struct perf_event_attr *hw_event, pid_t pid, int cpu,
dfaf77
    SUBDBG("   enable_on_exec: %d\n",hw_event->enable_on_exec);
dfaf77
    SUBDBG("   task: %d\n",hw_event->task);
dfaf77
    SUBDBG("   watermark: %d\n",hw_event->watermark);
dfaf77
+   SUBDBG("   precise_ip: %d\n",hw_event->precise_ip);
dfaf77
+   SUBDBG("   mmap_data: %d\n",hw_event->mmap_data);
dfaf77
+   SUBDBG("   sample_id_all: %d\n",hw_event->sample_id_all);
dfaf77
+   SUBDBG("   exclude_host: %d\n",hw_event->exclude_host);
dfaf77
+   SUBDBG("   exclude_guest: %d\n",hw_event->exclude_guest);
dfaf77
+   SUBDBG("   exclude_callchain_kernel: %d\n",hw_event->exclude_callchain_kernel);
dfaf77
+   SUBDBG("   exclude_callchain_user: %d\n",hw_event->exclude_callchain_user);
dfaf77
+   SUBDBG("   wakeup_events: %"PRIx32" (%"PRIu32")\n", hw_event->wakeup_events, hw_event->wakeup_events);
dfaf77
+   SUBDBG("   bp_type: %"PRIx32" (%"PRIu32")\n", hw_event->bp_type, hw_event->bp_type);
dfaf77
+   SUBDBG("   config1: %"PRIx64" (%"PRIu64")\n", hw_event->config1, hw_event->config1);
dfaf77
+   SUBDBG("   config2: %"PRIx64" (%"PRIu64")\n", hw_event->config2, hw_event->config2);
dfaf77
+   SUBDBG("   branch_sample_type: %"PRIx64" (%"PRIu64")\n", hw_event->branch_sample_type, hw_event->branch_sample_type);
dfaf77
+   SUBDBG("   sample_regs_user: %"PRIx64" (%"PRIu64")\n", hw_event->sample_regs_user, hw_event->sample_regs_user);
dfaf77
+   SUBDBG("   sample_stack_user: %"PRIx32" (%"PRIu32")\n", hw_event->sample_stack_user, hw_event->sample_stack_user);
dfaf77
+
dfaf77
 	ret =
dfaf77
 		syscall( __NR_perf_event_open, hw_event, pid, cpu, group_fd, flags );
dfaf77
 	SUBDBG("Returned %d %d %s\n",ret,
dfaf77
@@ -470,14 +484,14 @@ check_scheduability( pe_context_t *ctx, pe_control_t *ctl, int idx )
dfaf77
       /* start the event */
dfaf77
       retval = ioctl( group_leader_fd, PERF_EVENT_IOC_ENABLE, NULL );
dfaf77
       if (retval == -1) {
dfaf77
-	 PAPIERROR("ioctl(PERF_EVENT_IOC_ENABLE) failed.\n");
dfaf77
+	 PAPIERROR("ioctl(PERF_EVENT_IOC_ENABLE) failed");
dfaf77
 	 return PAPI_ESYS;
dfaf77
       }
dfaf77
 
dfaf77
       /* stop the event */
dfaf77
       retval = ioctl(group_leader_fd, PERF_EVENT_IOC_DISABLE, NULL );
dfaf77
       if (retval == -1) {
dfaf77
-	 PAPIERROR( "ioctl(PERF_EVENT_IOC_DISABLE) failed.\n" );
dfaf77
+	 PAPIERROR( "ioctl(PERF_EVENT_IOC_DISABLE) failed" );
dfaf77
 	 return PAPI_ESYS;
dfaf77
       }
dfaf77
 
dfaf77
@@ -514,7 +528,7 @@ check_scheduability( pe_context_t *ctx, pe_control_t *ctl, int idx )
dfaf77
 	   retval=ioctl( ctl->events[i].event_fd, PERF_EVENT_IOC_RESET, NULL );
dfaf77
 	   if (retval == -1) {
dfaf77
 	      PAPIERROR( "ioctl(PERF_EVENT_IOC_RESET) #%d/%d %d "
dfaf77
-			 "(fd %d)failed.\n",
dfaf77
+			 "(fd %d)failed",
dfaf77
 			 i,ctl->num_events,idx,ctl->events[i].event_fd);
dfaf77
 	      return PAPI_ESYS;
dfaf77
 	   }
dfaf77
@@ -794,7 +808,7 @@ close_pe_events( pe_context_t *ctx, pe_control_t *ctl )
dfaf77
    if (ctl->num_events!=num_closed) {
dfaf77
       if (ctl->num_events!=(num_closed+events_not_opened)) {
dfaf77
          PAPIERROR("Didn't close all events: "
dfaf77
-		   "Closed %d Not Opened: %d Expected %d\n",
dfaf77
+		   "Closed %d Not Opened: %d Expected %d",
dfaf77
 		   num_closed,events_not_opened,ctl->num_events);
dfaf77
          return PAPI_EBUG;
dfaf77
       }
dfaf77
@@ -824,9 +838,7 @@ _pe_set_domain( hwd_control_state_t *ctl, int domain)
dfaf77
    int i;
dfaf77
    pe_control_t *pe_ctl = ( pe_control_t *) ctl;
dfaf77
 
dfaf77
-   SUBDBG("old control domain %d, new domain %d\n",
dfaf77
-	  pe_ctl->domain,domain);
dfaf77
-
dfaf77
+   SUBDBG("old control domain %d, new domain %d\n", pe_ctl->domain,domain);
dfaf77
    pe_ctl->domain = domain;
dfaf77
 
dfaf77
    /* Force the domain on all events */
dfaf77
@@ -915,6 +927,8 @@ int
dfaf77
 _pe_read( hwd_context_t *ctx, hwd_control_state_t *ctl,
dfaf77
 	       long long **events, int flags )
dfaf77
 {
dfaf77
+	SUBDBG("ENTER: ctx: %p, ctl: %p, events: %p, flags: %#x\n", ctx, ctl, events, flags);
dfaf77
+
dfaf77
    ( void ) flags;			 /*unused */
dfaf77
    int i, ret = -1;
dfaf77
    pe_context_t *pe_ctx = ( pe_context_t *) ctx;
dfaf77
@@ -964,7 +978,7 @@ _pe_read( hwd_context_t *ctx, hwd_control_state_t *ctl,
dfaf77
 
dfaf77
 	 /* We should read 3 64-bit values from the counter */
dfaf77
 	 if (ret<(signed)(3*sizeof(long long))) {
dfaf77
-	    PAPIERROR("Error!  short read!\n");
dfaf77
+	    PAPIERROR("Error!  short read");
dfaf77
 	    return PAPI_ESYS;
dfaf77
 	 }
dfaf77
 
dfaf77
@@ -1020,8 +1034,8 @@ _pe_read( hwd_context_t *ctx, hwd_control_state_t *ctl,
dfaf77
 
dfaf77
 	 /* we should read one 64-bit value from each counter */
dfaf77
 	 if (ret!=sizeof(long long)) {
dfaf77
-	    PAPIERROR("Error!  short read!\n");
dfaf77
-	    PAPIERROR("read: fd: %2d, tid: %ld, cpu: %d, ret: %d\n",
dfaf77
+	    PAPIERROR("Error!  short read");
dfaf77
+	    PAPIERROR("read: fd: %2d, tid: %ld, cpu: %d, ret: %d",
dfaf77
 		   pe_ctl->events[i].event_fd,
dfaf77
 		   (long)pe_ctl->tid, pe_ctl->cpu, ret);
dfaf77
 	    return PAPI_ESYS;
dfaf77
@@ -1042,7 +1056,7 @@ _pe_read( hwd_context_t *ctx, hwd_control_state_t *ctl,
dfaf77
 
dfaf77
    else {
dfaf77
       if (pe_ctl->events[0].group_leader_fd!=-1) {
dfaf77
-	 PAPIERROR("Was expecting group leader!\n");
dfaf77
+	 PAPIERROR("Was expecting group leader");
dfaf77
       }
dfaf77
 
dfaf77
       ret = read( pe_ctl->events[0].event_fd, papi_pe_buffer,
dfaf77
@@ -1056,7 +1070,7 @@ _pe_read( hwd_context_t *ctx, hwd_control_state_t *ctl,
dfaf77
       /* we read 1 64-bit value (number of events) then     */
dfaf77
       /* num_events more 64-bit values that hold the counts */
dfaf77
       if (ret<(signed)((1+pe_ctl->num_events)*sizeof(long long))) {
dfaf77
-	 PAPIERROR("Error! short read!\n");
dfaf77
+	 PAPIERROR("Error! short read");
dfaf77
 	 return PAPI_ESYS;
dfaf77
       }
dfaf77
 
dfaf77
@@ -1072,7 +1086,7 @@ _pe_read( hwd_context_t *ctx, hwd_control_state_t *ctl,
dfaf77
 
dfaf77
       /* Make sure the kernel agrees with how many events we have */
dfaf77
       if (papi_pe_buffer[0]!=pe_ctl->num_events) {
dfaf77
-	 PAPIERROR("Error!  Wrong number of events!\n");
dfaf77
+	 PAPIERROR("Error!  Wrong number of events");
dfaf77
 	 return PAPI_ESYS;
dfaf77
       }
dfaf77
 
dfaf77
@@ -1106,6 +1120,7 @@ _pe_read( hwd_context_t *ctx, hwd_control_state_t *ctl,
dfaf77
    /* point PAPI to the values we read */
dfaf77
    *events = pe_ctl->counts;
dfaf77
 
dfaf77
+   SUBDBG("EXIT: *events: %p\n", *events);
dfaf77
    return PAPI_OK;
dfaf77
 }
dfaf77
 
dfaf77
@@ -1134,7 +1149,7 @@ _pe_start( hwd_context_t *ctx, hwd_control_state_t *ctl )
dfaf77
 
dfaf77
 	 /* ioctls always return -1 on failure */
dfaf77
          if (ret == -1) {
dfaf77
-            PAPIERROR("ioctl(PERF_EVENT_IOC_ENABLE) failed.\n");
dfaf77
+            PAPIERROR("ioctl(PERF_EVENT_IOC_ENABLE) failed");
dfaf77
             return PAPI_ESYS;
dfaf77
 	 }
dfaf77
 
dfaf77
@@ -1143,7 +1158,7 @@ _pe_start( hwd_context_t *ctx, hwd_control_state_t *ctl )
dfaf77
    }
dfaf77
 
dfaf77
    if (!did_something) {
dfaf77
-      PAPIERROR("Did not enable any counters.\n");
dfaf77
+      PAPIERROR("Did not enable any counters");
dfaf77
       return PAPI_EBUG;
dfaf77
    }
dfaf77
 
dfaf77
@@ -1157,6 +1172,7 @@ _pe_start( hwd_context_t *ctx, hwd_control_state_t *ctl )
dfaf77
 int
dfaf77
 _pe_stop( hwd_context_t *ctx, hwd_control_state_t *ctl )
dfaf77
 {
dfaf77
+	SUBDBG( "ENTER: ctx: %p, ctl: %p\n", ctx, ctl);
dfaf77
 
dfaf77
    int ret;
dfaf77
    int i;
dfaf77
@@ -1178,6 +1194,7 @@ _pe_stop( hwd_context_t *ctx, hwd_control_state_t *ctl )
dfaf77
 
dfaf77
    pe_ctx->state &= ~PERF_EVENTS_RUNNING;
dfaf77
 
dfaf77
+	SUBDBG( "EXIT:\n");
dfaf77
    return PAPI_OK;
dfaf77
 }
dfaf77
 
dfaf77
@@ -1190,6 +1207,7 @@ _pe_update_control_state( hwd_control_state_t *ctl,
dfaf77
 			       NativeInfo_t *native,
dfaf77
 			       int count, hwd_context_t *ctx )
dfaf77
 {
dfaf77
+   SUBDBG( "ENTER: ctl: %p, native: %p, count: %d, ctx: %p\n", ctl, native, count, ctx);
dfaf77
    int i = 0, ret;
dfaf77
    pe_context_t *pe_ctx = ( pe_context_t *) ctx;
dfaf77
    pe_control_t *pe_ctl = ( pe_control_t *) ctl;
dfaf77
@@ -1202,7 +1220,7 @@ _pe_update_control_state( hwd_control_state_t *ctl,
dfaf77
    /* Calling with count==0 should be OK, it's how things are deallocated */
dfaf77
    /* when an eventset is destroyed.                                      */
dfaf77
    if ( count == 0 ) {
dfaf77
-      SUBDBG( "Called with count == 0\n" );
dfaf77
+      SUBDBG( "EXIT: Called with count == 0\n" );
dfaf77
       return PAPI_OK;
dfaf77
    }
dfaf77
 
dfaf77
@@ -1236,15 +1254,16 @@ _pe_update_control_state( hwd_control_state_t *ctl,
dfaf77
    pe_ctl->num_events = count;
dfaf77
    _pe_set_domain( ctl, pe_ctl->domain );
dfaf77
 
dfaf77
-   /* actuall open the events */
dfaf77
+   /* actually open the events */
dfaf77
    /* (why is this a separate function?) */
dfaf77
    ret = open_pe_events( pe_ctx, pe_ctl );
dfaf77
    if ( ret != PAPI_OK ) {
dfaf77
-      SUBDBG("open_pe_events failed\n");
dfaf77
+      SUBDBG("EXIT: open_pe_events returned: %d\n", ret);
dfaf77
       /* Restore values ? */
dfaf77
       return ret;
dfaf77
    }
dfaf77
 
dfaf77
+   SUBDBG( "EXIT:\n" );
dfaf77
    return PAPI_OK;
dfaf77
 }
dfaf77
 
dfaf77
@@ -1914,7 +1933,7 @@ _pe_dispatch_timer( int n, hwd_siginfo_t *info, void *uc)
dfaf77
   }
dfaf77
         
dfaf77
   if (ioctl( fd, PERF_EVENT_IOC_DISABLE, NULL ) == -1 ) {
dfaf77
-      PAPIERROR("ioctl(PERF_EVENT_IOC_DISABLE) failed.\n");
dfaf77
+      PAPIERROR("ioctl(PERF_EVENT_IOC_DISABLE) failed");
dfaf77
   }
dfaf77
 
dfaf77
   if ( ( thread->running_eventset[cidx]->state & PAPI_PROFILING ) &&