Skip to content

Commit

Permalink
Version 1.10.0-dev.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ricowind committed May 27, 2015
1 parent edc2a7c commit a00604d
Show file tree
Hide file tree
Showing 29 changed files with 332 additions and 130 deletions.
22 changes: 13 additions & 9 deletions pkg/analysis_server/lib/src/analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -585,15 +585,17 @@ class AnalysisServer {
return units;
}
// add a unit for each unit/library combination
Source unitSource = contextSource.source;
List<Source> librarySources = context.getLibrariesContaining(unitSource);
for (Source librarySource in librarySources) {
CompilationUnit unit =
context.resolveCompilationUnit2(unitSource, librarySource);
if (unit != null) {
units.add(unit);
runWithWorkingCacheSize(context, () {
Source unitSource = contextSource.source;
List<Source> librarySources = context.getLibrariesContaining(unitSource);
for (Source librarySource in librarySources) {
CompilationUnit unit =
context.resolveCompilationUnit2(unitSource, librarySource);
if (unit != null) {
units.add(unit);
}
}
}
});
// done
return units;
}
Expand Down Expand Up @@ -1183,7 +1185,9 @@ class AnalysisServer {
return null;
}
// if library has been already resolved, resolve unit
return context.resolveCompilationUnit2(source, librarySource);
return runWithWorkingCacheSize(context, () {
return context.resolveCompilationUnit2(source, librarySource);
});
}

/**
Expand Down
39 changes: 30 additions & 9 deletions pkg/analysis_server/lib/src/operation/operation_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ import 'package:analyzer/src/generated/error.dart';
import 'package:analyzer/src/generated/html.dart';
import 'package:analyzer/src/generated/source.dart';

/**
* Runs the given function [f] with the working cache size in [context].
* Returns the result of [f] invocation.
*/
runWithWorkingCacheSize(AnalysisContext context, f()) {
int currentCacheSize = context.analysisOptions.cacheSize;
if (currentCacheSize < PerformAnalysisOperation.WORKING_CACHE_SIZE) {
setCacheSize(context, PerformAnalysisOperation.WORKING_CACHE_SIZE);
try {
return f();
} finally {
setCacheSize(context, currentCacheSize);
}
} else {
return f();
}
}

/**
* Schedules indexing of the given [file] using the resolved [dartUnit].
*/
Expand Down Expand Up @@ -151,6 +169,16 @@ void sendAnalysisNotificationOverrides(
});
}

/**
* Sets the cache size in the given [context] to the given value.
*/
void setCacheSize(AnalysisContext context, int cacheSize) {
AnalysisOptionsImpl options =
new AnalysisOptionsImpl.con1(context.analysisOptions);
options.cacheSize = cacheSize;
context.analysisOptions = options;
}

/**
* Runs the given notification producing function [f], catching exceptions.
*/
Expand Down Expand Up @@ -207,13 +235,13 @@ class PerformAnalysisOperation extends ServerOperation {
// sendStatusNotification(context.toString(), taskDescription);
// });
if (!isContinue) {
_setCacheSize(WORKING_CACHE_SIZE);
setCacheSize(context, WORKING_CACHE_SIZE);
}
// prepare results
AnalysisResult result = context.performAnalysisTask();
List<ChangeNotice> notices = result.changeNotices;
if (notices == null) {
_setCacheSize(IDLE_CACHE_SIZE);
setCacheSize(context, IDLE_CACHE_SIZE);
server.sendContextAnalysisDoneNotifications(
context, AnalysisDoneReason.COMPLETE);
return;
Expand Down Expand Up @@ -245,13 +273,6 @@ class PerformAnalysisOperation extends ServerOperation {
}
}

void _setCacheSize(int cacheSize) {
AnalysisOptionsImpl options =
new AnalysisOptionsImpl.con1(context.analysisOptions);
options.cacheSize = cacheSize;
context.analysisOptions = options;
}

void _updateIndex(AnalysisServer server, List<ChangeNotice> notices) {
if (server.index == null) {
return;
Expand Down
16 changes: 6 additions & 10 deletions pkg/analysis_server/lib/src/services/index/store/codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,17 @@ class ElementCodec {
for (Source unitSource in unitSources) {
List<Source> libSources = context.getLibrariesContaining(unitSource);
for (Source libSource in libSources) {
LibraryElement libraryElement = context.getLibraryElement(libSource);
if (libraryElement == null) {
CompilationUnitElement unitElement =
context.getCompilationUnitElement(unitSource, libSource);
if (unitElement == null) {
return null;
}
if (kindId == ElementKind.LIBRARY.ordinal) {
return libraryElement;
return unitElement.library;
} else if (kindId == ElementKind.COMPILATION_UNIT.ordinal) {
for (CompilationUnitElement unit in libraryElement.units) {
if (unit.source.fullName == filePath) {
return unit;
}
}
return null;
return unitElement;
} else {
Element element = libraryElement.getElementAt(offset);
Element element = unitElement.getElementAt(offset);
if (element == null) {
return null;
}
Expand Down
46 changes: 46 additions & 0 deletions pkg/analyzer/lib/instrumentation/instrumentation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

library instrumentation;

import 'dart:convert';

/**
* A container with analysis performance constants.
*/
Expand Down Expand Up @@ -62,6 +64,8 @@ class InstrumentationService {
static const String TAG_PERFORMANCE = 'Perf';
static const String TAG_REQUEST = 'Req';
static const String TAG_RESPONSE = 'Res';
static const String TAG_SUBPROCESS_START = 'SPStart';
static const String TAG_SUBPROCESS_RESULT = 'SPResult';
static const String TAG_VERSION = 'Ver';
static const String TAG_WATCH_EVENT = 'Watch';

Expand All @@ -71,6 +75,11 @@ class InstrumentationService {
*/
InstrumentationServer _instrumentationServer;

/**
* Counter used to generate unique ID's for [logSubprocessStart].
*/
int _subprocessCounter = 0;

/**
* Initialize a newly created instrumentation service to comunicate with the
* given [instrumentationServer].
Expand Down Expand Up @@ -190,6 +199,43 @@ class InstrumentationService {
_log(TAG_RESPONSE, response);
}

/**
* Log the result of executing a subprocess. [subprocessId] should be the
* unique IDreturned by [logSubprocessStart].
*/
void logSubprocessResult(
int subprocessId, int exitCode, String stdout, String stderr) {
if (_instrumentationServer != null) {
_instrumentationServer.log(_join([
TAG_SUBPROCESS_RESULT,
subprocessId.toString(),
exitCode.toString(),
JSON.encode(stdout),
JSON.encode(stderr)
]));
}
}

/**
* Log that the given subprocess is about to be executed. Returns a unique
* identifier that can be used to identify the subprocess for later log
* entries.
*/
int logSubprocessStart(
String executablePath, List<String> arguments, String workingDirectory) {
int subprocessId = _subprocessCounter++;
if (_instrumentationServer != null) {
_instrumentationServer.log(_join([
TAG_SUBPROCESS_START,
subprocessId.toString(),
executablePath,
workingDirectory,
JSON.encode(arguments)
]));
}
return subprocessId;
}

/**
* Signal that the client has started analysis server.
* This method should be invoked exactly one time.
Expand Down
13 changes: 10 additions & 3 deletions pkg/analyzer/lib/source/pub_package_map_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,15 @@ class PubPackageMapProvider implements PackageMapProvider {
* Run pub list to determine the packages and input files.
*/
io.ProcessResult _runPubListDefault(Folder folder) {
return io.Process.runSync(sdk.pubExecutable.getAbsolutePath(), [
PUB_LIST_COMMAND
], workingDirectory: folder.path);
String executablePath = sdk.pubExecutable.getAbsolutePath();
List<String> arguments = [PUB_LIST_COMMAND];
String workingDirectory = folder.path;
int subprocessId = AnalysisEngine.instance.instrumentationService
.logSubprocessStart(executablePath, arguments, workingDirectory);
io.ProcessResult result = io.Process.runSync(executablePath, arguments,
workingDirectory: workingDirectory);
AnalysisEngine.instance.instrumentationService.logSubprocessResult(
subprocessId, result.exitCode, result.stdout, result.stderr);
return result;
}
}
50 changes: 25 additions & 25 deletions pkg/analyzer/lib/src/generated/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,11 @@ abstract class CompilationUnitElement implements Element, UriReferencedElement {
*/
List<ClassElement> get types;

/**
* Return the element at the given [offset], maybe `null` if no such element.
*/
Element getElementAt(int offset);

/**
* Return the enum defined in this compilation unit that has the given [name],
* or `null` if this compilation unit does not define an enum with the given
Expand Down Expand Up @@ -1279,6 +1284,11 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
List<TopLevelVariableElement> _variables =
TopLevelVariableElementImpl.EMPTY_ARRAY;

/**
* A map from offsets to elements of this unit at these offsets.
*/
final Map<int, Element> _offsetToElementMap = new HashMap<int, Element>();

/**
* Initialize a newly created compilation unit element to have the given
* [name].
Expand Down Expand Up @@ -1400,6 +1410,13 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
@override
accept(ElementVisitor visitor) => visitor.visitCompilationUnitElement(this);

/**
* This method is invoked after this unit was incrementally resolved.
*/
void afterIncrementalResolution() {
_offsetToElementMap.clear();
}

@override
void appendTo(StringBuffer buffer) {
if (source == null) {
Expand Down Expand Up @@ -1450,6 +1467,14 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
return null;
}

@override
Element getElementAt(int offset) {
if (_offsetToElementMap.isEmpty) {
accept(new _BuildOffsetToElementMap(_offsetToElementMap));
}
return _offsetToElementMap[offset];
}

@override
ClassElement getEnum(String enumName) {
for (ClassElement enumDeclaration in _enums) {
Expand Down Expand Up @@ -6765,11 +6790,6 @@ abstract class LibraryElement implements Element {
*/
List<LibraryElement> get visibleLibraries;

/**
* Return the element at the given [offset], maybe `null` if no such element.
*/
Element getElementAt(int offset);

/**
* Return a list containing all of the imports that share the given [prefix],
* or an empty array if there are no such imports.
Expand Down Expand Up @@ -6839,11 +6859,6 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
*/
FunctionElement _loadLibraryFunction;

/**
* A map from offsets to elements of this library at these offsets.
*/
final Map<int, Element> _offsetToElementMap = new HashMap<int, Element>();

/**
* The export [Namespace] of this library, `null` if it has not been
* computed yet.
Expand Down Expand Up @@ -7119,13 +7134,6 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
@override
accept(ElementVisitor visitor) => visitor.visitLibraryElement(this);

/**
* This method is invoked after this library was incrementally resolved.
*/
void afterIncrementalResolution() {
_offsetToElementMap.clear();
}

@override
ElementImpl getChild(String identifier) {
if ((_definingCompilationUnit as CompilationUnitElementImpl).identifier ==
Expand All @@ -7150,14 +7158,6 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
return null;
}

@override
Element getElementAt(int offset) {
if (_offsetToElementMap.isEmpty) {
accept(new _BuildOffsetToElementMap(_offsetToElementMap));
}
return _offsetToElementMap[offset];
}

@override
List<ImportElement> getImportsWithPrefix(PrefixElement prefixElement) {
int count = _imports.length;
Expand Down
8 changes: 5 additions & 3 deletions pkg/analyzer/lib/src/generated/element_handle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ class CompilationUnitElementHandle extends ElementHandle
@override
int get uriOffset => actualElement.uriOffset;

@override
Element getElementAt(int offset) {
return actualElement.getElementAt(offset);
}

@override
ClassElement getEnum(String enumName) => actualElement.getEnum(enumName);

Expand Down Expand Up @@ -802,9 +807,6 @@ class LibraryElementHandle extends ElementHandle implements LibraryElement {
@override
List<LibraryElement> get visibleLibraries => actualElement.visibleLibraries;

@override
Element getElementAt(int offset) => actualElement.getElementAt(offset);

@override
List<ImportElement> getImportsWithPrefix(PrefixElement prefixElement) =>
actualElement.getImportsWithPrefix(prefixElement);
Expand Down
6 changes: 3 additions & 3 deletions pkg/analyzer/lib/src/generated/incremental_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ class IncrementalResolver {
/**
* The element of the compilation unit being resolved.
*/
final CompilationUnitElement _definingUnit;
final CompilationUnitElementImpl _definingUnit;

/**
* The context the compilation unit being resolved in.
Expand Down Expand Up @@ -887,8 +887,8 @@ class IncrementalResolver {
_generateLints(rootNode);
// update entry errors
_updateEntry();
// notify library
_definingLibrary.afterIncrementalResolution();
// notify unit
_definingUnit.afterIncrementalResolution();
// OK
return true;
} finally {
Expand Down
Loading

0 comments on commit a00604d

Please sign in to comment.