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

Unified Diff: sdk/lib/io/file_impl.dart

Issue 1326703004: Add resource metadata for open files. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: address comments Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/io/file_impl.dart
diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart
index 8ed6c58b89b8b0d07327ac5c6c030bde19de9851..2164bc94a02b5a6d33fa76e9c31015ef13a41724 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -566,56 +566,43 @@ class _File extends FileSystemEntity implements File {
class _RandomAccessFile
- extends Object with _ServiceObject
implements RandomAccessFile {
- // Use default Map so we keep order.
- static Map<int, _RandomAccessFile> _files = new Map<int, _RandomAccessFile>();
+ static bool _connectedResourceHandler = false;
final String path;
int _id;
bool _asyncDispatched = false;
SendPort _fileService;
- int _totalRead = 0;
- int _totalWritten = 0;
- int _readCount = 0;
- int _writeCount = 0;
-
+ _FileResourceInfo _resourceInfo;
_RandomAccessFile(this._id, this.path) {
- _files[_serviceId] = this;
- }
-
- String get _serviceTypePath => 'io/file/randomaccessfiles';
- String get _serviceTypeName => 'RandomAccessFile';
-
- Map _toJSON(bool ref) {
- var r = {
- 'id': _servicePath,
- 'type': _serviceType(ref),
- 'name': '$path',
- 'user_name': '$path',
- };
- if (ref) {
- return r;
- }
- r['asyncDispatched'] = _asyncDispatched;
- r['fd'] = _getFD(_id);
- r['totalRead'] = _totalRead;
- r['totalWritten'] = _totalWritten;
- r['readCount'] = _totalWritten;
- r['writeCount'] = _writeCount;
- return r;
+ _resourceInfo = new _FileResourceInfo(this);
+ _maybeConnectHandler();
}
void _maybePerformCleanup() {
if (closed) {
- _files.remove(_serviceId);
+ _FileResourceInfo.FileClosed(_resourceInfo);
}
}
external static int _getFD(int id);
+ _maybeConnectHandler() {
+ if (!_connectedResourceHandler) {
+ // TODO(ricow): we probably need set these in some initialization code.
+ // We need to make sure that these are always awailable from the
+ // observatory even if no files (or sockets for the socket ones) are
+ // open.
Ivan Posva 2015/09/08 18:06:36 Correct, this should be done with the overall init
Cutch 2015/09/10 14:42:44 We probably also need to do this automatically for
+ registerExtension('__getOpenFiles',
+ _FileResourceInfo.getOpenFiles);
+ registerExtension('__getFileByID',
+ _FileResourceInfo.getFileInfoMapByID);
+ _connectedResourceHandler = true;
+ }
+ }
+
Future<RandomAccessFile> close() {
return _dispatch(_FILE_CLOSE, [_id], markClosed: true).then((result) {
if (result != -1) {
@@ -645,8 +632,8 @@ class _RandomAccessFile
if (_isErrorResponse(response)) {
throw _exceptionFromResponse(response, "readByte failed", path);
}
- _readCount++;
- _totalRead++;
+ _resourceInfo.readCount++;
+ _resourceInfo.totalRead++;
return response;
});
}
@@ -659,8 +646,8 @@ class _RandomAccessFile
if (result is OSError) {
throw new FileSystemException("readByte failed", path, result);
}
- _readCount++;
- _totalRead++;
+ _resourceInfo.readCount++;
+ _resourceInfo.totalRead++;
return result;
}
@@ -672,8 +659,8 @@ class _RandomAccessFile
if (_isErrorResponse(response)) {
throw _exceptionFromResponse(response, "read failed", path);
}
- _readCount++;
- _totalRead += response[1].length;
+ _resourceInfo.readCount++;
+ _resourceInfo.totalRead += response[1].length;
return response[1];
});
}
@@ -689,8 +676,8 @@ class _RandomAccessFile
if (result is OSError) {
throw new FileSystemException("readSync failed", path, result);
}
- _readCount++;
- _totalRead += result.length;
+ _resourceInfo.readCount++;
+ _resourceInfo.totalRead += result.length;
return result;
}
@@ -710,8 +697,8 @@ class _RandomAccessFile
var read = response[1];
var data = response[2];
buffer.setRange(start, start + read, data);
- _readCount++;
- _totalRead += read;
+ _resourceInfo.readCount++;
+ _resourceInfo.totalRead += read;
return read;
});
}
@@ -731,8 +718,8 @@ class _RandomAccessFile
if (result is OSError) {
throw new FileSystemException("readInto failed", path, result);
}
- _readCount++;
- _totalRead += result;
+ _resourceInfo.readCount++;
+ _resourceInfo.totalRead += result;
return result;
}
@@ -744,8 +731,8 @@ class _RandomAccessFile
if (_isErrorResponse(response)) {
throw _exceptionFromResponse(response, "writeByte failed", path);
}
- _writeCount++;
- _totalWritten++;
+ _resourceInfo.writeCount++;
+ _resourceInfo.totalWritten++;
return this;
});
}
@@ -761,8 +748,8 @@ class _RandomAccessFile
if (result is OSError) {
throw new FileSystemException("writeByte failed", path, result);
}
- _writeCount++;
- _totalWritten++;
+ _resourceInfo.writeCount++;
+ _resourceInfo.totalWritten++;
return result;
}
@@ -791,8 +778,8 @@ class _RandomAccessFile
if (_isErrorResponse(response)) {
throw _exceptionFromResponse(response, "writeFrom failed", path);
}
- _writeCount++;
- _totalWritten += end - (start - result.start);
+ _resourceInfo.writeCount++;
+ _resourceInfo.totalWritten += end - (start - result.start);
return this;
});
}
@@ -817,8 +804,8 @@ class _RandomAccessFile
if (result is OSError) {
throw new FileSystemException("writeFrom failed", path, result);
}
- _writeCount++;
- _totalWritten += end - (start - bufferAndStart.start);
+ _resourceInfo.writeCount++;
+ _resourceInfo.totalWritten += end - (start - bufferAndStart.start);
}
Future<RandomAccessFile> writeString(String string,

Powered by Google App Engine
This is Rietveld 408576698