alloc_trace.mx raw

   1  //go:build gc.leaking && alloc_trace
   2  
   3  package runtime
   4  
   5  import "unsafe"
   6  
   7  const maxAllocSites = 8192
   8  
   9  var allocCounters [maxAllocSites]uint64
  10  var numAllocSites int32
  11  
  12  //go:noinline
  13  func logAlloc(siteID int32) {
  14  	if siteID >= 0 && siteID < maxAllocSites {
  15  		allocCounters[siteID]++
  16  		if siteID >= numAllocSites {
  17  			numAllocSites = siteID + 1
  18  		}
  19  	}
  20  }
  21  
  22  //go:export __moxie_alloc_counters_ptr
  23  func allocCountersPtr() uintptr {
  24  	return uintptr(unsafe.Pointer(&allocCounters[0]))
  25  }
  26  
  27  //go:export __moxie_alloc_n_sites
  28  func allocNSites() int32 {
  29  	return numAllocSites
  30  }
  31  
  32  //go:export __moxie_total_alloc
  33  func totalAlloc() uint64 {
  34  	return gcTotalAlloc
  35  }
  36  
  37  //go:export __moxie_mallocs
  38  func mallocs() uint64 {
  39  	return gcMallocs
  40  }
  41  
  42  //go:export __moxie_heap_ptr
  43  func heapPtr() uintptr {
  44  	return heapptr
  45  }
  46