(deviceCount int, da deviceAllocator)
| 131 | } |
| 132 | |
| 133 | func reportAllocatedMemory(deviceCount int, da deviceAllocator) { |
| 134 | // getAllocatedMemory may panic, therefore we should recover here |
| 135 | defer func() { |
| 136 | if r := recover(); r != nil { |
| 137 | var err error |
| 138 | switch x := r.(type) { |
| 139 | case string: |
| 140 | err = utils.StackError(nil, x) |
| 141 | case error: |
| 142 | err = utils.StackError(x, "Panic happens when reporting allocated memory") |
| 143 | default: |
| 144 | err = utils.StackError(nil, "Panic happens when reporting allocated memory %v", x) |
| 145 | } |
| 146 | utils.GetLogger().With("err", err).Error("Failed to report allocated memory") |
| 147 | } |
| 148 | }() |
| 149 | |
| 150 | for device := 0; device < deviceCount; device++ { |
| 151 | utils.GetRootReporter().GetChildGauge(map[string]string{ |
| 152 | "device": strconv.Itoa(device), |
| 153 | }, utils.AllocatedDeviceMemory).Update(float64(da.getAllocatedMemory(device))) |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // newDeviceAllocator returns a new device allocator instances. |
| 158 | func newDeviceAllocator() deviceAllocator { |
no test coverage detected