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

Side by Side Diff: tools/gardening/lib/src/logdog.dart

Issue 2754123002: Add logdog support to gardening tools. (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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:io';
6 import 'dart:async';
7 import 'dart:collection';
8
9 class LogdogException implements Exception {
10 final int errorCode;
11 final String stdout;
12 final String stderr;
13
14 LogdogException(this.errorCode, this.stdout, this.stderr);
15 LogdogException.fromProcessResult(ProcessResult result)
16 : this(result.exitCode, result.stdout, result.stderr);
17
18 toString() => "Error during logdog execution:\n$stderr";
19 }
20
21 bool logdogCheckDone = false;
22
23 void checkLogdog({bool tryToInstall: true}) {
24 if (logdogCheckDone) return;
25 var result = Process.runSync("cit", []);
26 if (result.exitCode != 0) {
27 print("cit (from depot_tools) must be in the path.");
28 throw new StateError("cit not accessible");
29 }
30 String stdout = result.stdout;
31 if (stdout.contains("logdog")) {
32 logdogCheckDone = true;
33 return;
34 }
35 if (tryToInstall) {
36 print("logdog isn't yet installed. Installation might take some time");
37 result = Process.runSync("cit", ["logdog"]);
38 checkLogdog(tryToInstall: false);
39 } else {
40 print("Couldn't install logdog");
41 throw new StateError("logdog not accessible");
42 }
43 }
44
45 String logdog(List<String> args) {
46 checkLogdog();
47 args = args.toList()..insert(0, "logdog");
48 var result = Process.runSync("cit", args);
49 if (result.exitCode == 0) return result.stdout;
50 throw new LogdogException.fromProcessResult(result);
51 }
52
53 String cat(String log) {
54 return logdog(["cat", "-raw", log]);
55 }
56
57 class LogResult<T> {
58 final String log;
59 final T result;
60
61 LogResult(this.log, this.result);
62 }
63
64 const int maxConcurrentLogdogs = 20;
65
66 /// Fetches the given [logs] concurrently using [logdog].
67 ///
68 /// At most [maxConcurrentLogdogs] connections are opened at the same time.
69 ///
70 /// The resulting [LogResult] has a [LogResult.result] equal to `null` if
71 /// the log didn't exist.
72 Stream<LogResult<String>> catN(Iterable<String> logs) async* {
73 var queue = new Queue<Future<LogResult<ProcessResult>>>();
74 var it = logs.iterator;
75
76 // Launches a new logdog to fetch the next log.
77 // Returns false when nothing was left to enqueue.
78 bool enqueueNext() {
79 if (!it.moveNext()) return false;
80 var log = it.current;
81 queue.add(new Future.sync(() async {
82 var logPath = log.substring(0, log.lastIndexOf("/"));
83 var lsResult = await Process.run("cit", ["logdog", "ls", logPath]);
84 if (lsResult.exitCode != 0) return new LogResult(log, lsResult);
85 if (lsResult.stdout == "") return new LogResult(log, null);
86 return new LogResult(
87 log, await Process.run("cit", ["logdog", "cat", "-raw", log]));
88 }));
89 return true;
90 }
91
92 for (int i = 0; i < maxConcurrentLogdogs; i++) {
93 enqueueNext();
94 }
95
96 while (queue.isNotEmpty) {
97 var logResult =
98 await queue.removeFirst().timeout(const Duration(seconds: 15));
99 enqueueNext();
100 if (logResult.result == null) {
101 yield new LogResult(logResult.log, null);
102 } else if (logResult.result.exitCode != 0) {
103 throw new LogdogException.fromProcessResult(logResult.result);
104 } else {
105 yield new LogResult(logResult.log, logResult.result.stdout);
106 }
107 }
108 }
109
110 /*
floitsch 2017/03/16 18:23:08 I can remove these lines, but currently they serve
111 main() async {
112 // print(cat(
113 // "chromium/bb/client.dart/dart2js-win7-ie11ff-4-4-be/4215/+/recipes/steps /dart2js_ie11_tests/0/stdout"));
114 catN(new Iterable.generate(10, (i) {
115 return "chromium/bb/client.dart/dart2js-win7-ie11ff-4-4-be/"
116 "${4200 + i}"
117 "/+/recipes/steps/dart2js_ie11_tests/0/stdout";
118 })).listen((logResult) {
119 print("--------------------------");
120 if (logResult.result == null) {
121 print("${logResult.log} - empty");
122 } else {
123 print(logResult.result.substring(0, 200));
124 }
125 });
126 }
127 */
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698