code: def measure_power(self, hz, duration, tag, offset=30):
          
          num = duration * hz
          oset = offset * hz
          data = None
          self.usb("auto")
          time.sleep(1)
          with self.dut.handle_usb_disconnect():
              time.sleep(1)
              try:
                  data = self.take_samples(hz, num, sample_offset=oset)
                  if not data:
                      raise MonsoonError(
                          "No data was collected in measurement %s." % tag)
                  data.tag = tag
                  self.dut.log.info("Measurement summary: %s", repr(data))
                  return data
              finally:
                  self.mon.StopDataCollection()
                  self.log.info("Finished taking samples, reconnecting to dut.")
                  self.usb("on")
                  self.dut.adb.wait_for_device(timeout=DEFAULT_TIMEOUT_USB_ON)
                  # Wait for device to come back online.
                  time.sleep(10)
                  self.dut.log.info("Dut reconnected.")
docs: Measure power consumption of the attached device.
  
          Because it takes some time for the device to calm down after the usb
          connection is cut, an offset is set for each measurement. The default
          is 30s. The total time taken to measure will be (duration + offset).
  
          Args:
              hz: Number of samples to take per second.
              duration: Number of seconds to take samples for in each step.
              offset: The number of seconds of initial data to discard.
              tag: A string that's the name of the collected data group.
  
          Returns:
              A MonsoonData object with the measured power data.