Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: pkg/analysis_server/benchmark/perf/memory_tests.dart

Issue 2111743002: Add two memory usage benchmarks (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:async';
6 import 'dart:convert';
7 import 'dart:io';
8
9 import 'package:analysis_server/plugin/protocol/protocol.dart';
10 import 'package:unittest/unittest.dart';
11
12 import '../../test/integration/integration_tests.dart';
13
14 void printMemoryResults(String id, String description, List<int> sizes) {
15 String now = new DateTime.now().toUtc().toIso8601String();
16 print('$now ========== $id');
17 print('memory: $sizes');
18 print(description.trim());
19 print('--------------------');
20 print('');
21 print('');
22 }
23
24 /**
25 * Base class for analysis server memory usage tests.
26 */
27 class AnalysisServerMemoryUsageTest
28 extends AbstractAnalysisServerIntegrationTest {
29 static const int vmServicePort = 12345;
30
31 int getMemoryUsage() {
32 ProcessResult result = _run('curl', <String>[
33 'localhost:$vmServicePort/_getAllocationProfile\?isolateId=isolates/root\& gc=full'
34 ]);
35 Map json = JSON.decode(result.stdout);
36 Map heaps = json['result']['heaps'];
37 int newSpace = heaps['new']['used'];
38 int oldSpace = heaps['old']['used'];
39 return newSpace + oldSpace;
40 }
41
42 /**
43 * Send the server an 'analysis.setAnalysisRoots' command directing it to
44 * analyze [sourceDirectory].
45 */
46 Future setAnalysisRoot() =>
47 sendAnalysisSetAnalysisRoots([sourceDirectory.path], []);
48
49 /**
50 * The server is automatically started before every test.
51 */
52 @override
53 Future setUp() {
54 onAnalysisErrors.listen((AnalysisErrorsParams params) {
55 currentAnalysisErrors[params.file] = params.errors;
56 });
57 onServerError.listen((ServerErrorParams params) {
58 // A server error should never happen during an integration test.
59 fail('${params.message}\n${params.stackTrace}');
60 });
61 Completer serverConnected = new Completer();
62 onServerConnected.listen((_) {
63 expect(serverConnected.isCompleted, isFalse);
64 serverConnected.complete();
65 });
66 return startServer(servicesPort: vmServicePort).then((_) {
67 server.listenToOutput(dispatchNotification);
68 server.exitCode.then((_) {
69 skipShutdown = true;
70 });
71 return serverConnected.future;
72 });
73 }
74
75 /**
76 * After every test, the server is stopped.
77 */
78 Future shutdown() async => await shutdownIfNeeded();
79
80 /**
81 * Enable [ServerService.STATUS] notifications so that [analysisFinished]
82 * can be used.
83 */
84 Future subscribeToStatusNotifications() async {
85 await sendServerSetSubscriptions([ServerService.STATUS]);
86 }
87
88 /**
89 * Synchronously run the given [executable] with the given [arguments]. Return
90 * the result of running the process.
91 */
92 ProcessResult _run(String executable, List<String> arguments) {
93 return Process.runSync(executable, arguments,
94 stderrEncoding: UTF8, stdoutEncoding: UTF8);
95 }
96
97 /**
98 * 1. Start Analysis Server.
99 * 2. Set the analysis [roots].
100 * 3. Wait for analysis to complete.
101 * 4. Record the time to finish analysis.
scheglov 2016/07/06 17:55:04 Record the heap size after analysis is finished?
102 * 5. Shutdown.
103 * 6. Go to (1).
104 */
105 static Future<List<int>> start_waitInitialAnalysis_shutdown(
106 {List<String> roots, int numOfRepeats}) async {
107 expect(roots, isNotNull, reason: 'roots');
108 expect(numOfRepeats, isNotNull, reason: 'numOfRepeats');
109 // Repeat.
110 List<int> sizes = <int>[];
111 for (int i = 0; i < numOfRepeats; i++) {
112 AnalysisServerMemoryUsageTest test = new AnalysisServerMemoryUsageTest();
113 // Initialize Analysis Server.
114 await test.setUp();
115 await test.subscribeToStatusNotifications();
116 // Set roots and analyze.
117 await test.sendAnalysisSetAnalysisRoots(roots, []);
118 await test.analysisFinished;
119 sizes.add(test.getMemoryUsage());
120 // Stop the server.
121 await test.shutdown();
122 }
123 return sizes;
124 }
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698