runMemNative function

Future<MemNativeResult> runMemNative(
  1. MemNativeInput input, {
  2. void onCommand(
    1. String command
    )?,
})

Shells out to a platform-native memory tool and returns its raw output.

Platform dispatch: Android — adb shell dumpsys meminfo <appId> iOS simulator — vmmap <pid> iOS physical — unsupported in v1; returns MemNativeUnsupportedPlatform macOS — footprint <pid> (default) or vmmap <pid> (--tool vmmap)

The exact command is reported via onCommand before execution so callers can echo it to stderr.

Never throws; all error conditions are represented as sealed result cases.

Implementation

Future<MemNativeResult> runMemNative(
  MemNativeInput input, {
  void Function(String command)? onCommand,
}) async {
  try {
    final platformInfo = readPlatformInfo();
    if (platformInfo == null) {
      return const MemNativeError('No platform info found. Is the app running?');
    }

    final platform = platformInfo.platform.toLowerCase();
    final emulator = platformInfo.emulator;
    final device = readDevice();

    if (platform.startsWith('android')) {
      return _runAndroid(input: input, device: device, onCommand: onCommand);
    } else if (platform == 'ios' || platform.startsWith('ios-')) {
      if (emulator) {
        return _runIosSimulator(input: input, onCommand: onCommand);
      } else {
        return const MemNativeUnsupportedPlatform(
          platform: 'ios-physical',
          message: 'fdb mem native is not supported on physical iOS devices in v1. '
              'Use Xcode Instruments (Product > Profile > Allocations) for native iOS memory profiling.',
        );
      }
    } else if (platform == 'darwin' || platform == 'macos') {
      return _runMacos(input: input, onCommand: onCommand);
    } else {
      return MemNativeUnsupportedPlatform(
        platform: platform,
        message: 'fdb mem native is not supported on platform: $platform',
      );
    }
  } catch (e) {
    return MemNativeError(e.toString());
  }
}