<commit_before>// Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library coverage.src.devtools;

import 'dart:async';
import 'dart:convert' show JSON;
import 'dart:io';
import 'package:logging/logging.dart';

final Logger _log = new Logger('coverage.src.devtools');

class VMService {
  final _VMWebsocketConnection _connection;

  VMService._(this._connection);

  Future<VM> getVM() async {
    var response = await _connection.request('getVM');
    return new VM.fromJson(response);
  }

  Future<Isolate> getIsolate(String isolateId) async {
    var response =
        await _connection.request('getIsolate', {'isolateId': isolateId});
    return new Isolate.fromJson(response);
  }

  Future<AllocationProfile> getAllocationProfile(String isolateId,
      {bool reset, bool gc}) async {
    var params = {'isolateId': isolateId};
    if (reset != null) {
      params['reset'] = reset;
    }
    if (gc != null) {
      params['gc'] = 'full';
    }
    var response = await _connection.request('getAllocationProfile', params);
    return new AllocationProfile.fromJson(response);
  }

  Future getCoverage(String isolateId, {String targetId}) async {
    var params = {'isolateId': isolateId};
    if (targetId != null) {<commit_msg>RPC: fallback to _getAllocationProfile if getAllocationProfile fails<commit_after>// Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library coverage.src.devtools;

import 'dart:async';
import 'dart:convert' show JSON;
import 'dart:io';
import 'package:logging/logging.dart';

final Logger _log = new Logger('coverage.src.devtools');

class VMService {
  final _VMWebsocketConnection _connection;

  VMService._(this._connection);

  Future<VM> getVM() async {
    var response = await _connection.request('getVM');
    return new VM.fromJson(response);
  }

  Future<Isolate> getIsolate(String isolateId) async {
    var response =
        await _connection.request('getIsolate', {'isolateId': isolateId});
    return new Isolate.fromJson(response);
  }

  //TODO(kevmoo): Test this - https://github.com/dart-lang/coverage/issues/90
  Future<AllocationProfile> getAllocationProfile(String isolateId,
      {bool reset, bool gc}) async {
    var params = {'isolateId': isolateId};
    if (reset != null) {
      params['reset'] = reset;
    }
    if (gc != null) {
      params['gc'] = 'full';
    }

    // TODO(kevmoo) Remove fallback logic once 1.11 is stable
    // https://github.com/dart-lang/coverage/issues/91
    var response;
    try {
      // For Dart >=1.11.0-dev.3.0 - _getAllocationProfile is considered private
      response = await _connection.request('_getAllocationProfile', params);
    } on ServiceProtocolErrorBase catch (error) {
      if (error.isMethodNotFound) {
        // For Dart <1.11.0-dev.3.0 - getAllocationProfile is considered public
        response = await _connection.request('getAllocationProfile', params);
      } else {
        rethrow;
      }
    }

    return new AllocationProfile.fromJson(response);
  }

  Future getCoverage(String isolateId, {String targetId}) async {
    var params = {'isolateId': isolateId};
    if (targetId != null) {
{'fraction_non_alphanumeric': 0.11734104046242774, 'fraction_numerical': 0.007803468208092485, 'mean_word_length': 3.627005347593583, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '620652', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1031, 'n_words': 299}