private void DisplayTreeStats(IProtoBufSerializer serializer, GetFileSystemResponse response, bool verbose) { Trace.WriteLine("====================================================================="); Trace.WriteLine("FileSystem tree stats:"); { var mem = new MemoryStream(); var sw = new Stopwatch(); var ipcResponse = new IpcResponse { RequestId = 0, Protocol = IpcProtocols.TypedMessage, Data = response }; sw.Start(); serializer.Serialize(mem, ipcResponse); sw.Stop(); Trace.WriteLine(string.Format("ProtoBuf request of {0:n0} bytes serialized in {1} msec.", mem.Length, sw.ElapsedMilliseconds)); } var stats = new TreeStats(); stats.ProcessTree(null, "", response.Tree.Root); Trace.WriteLine(string.Format("Directory count: {0:n0}", stats.DirectoryCount)); Trace.WriteLine(string.Format("File count: {0:n0}", stats.FileCount)); Trace.WriteLine(string.Format("Total File size: {0:n0} bytes", stats.TotalSize)); if (verbose) { Trace.WriteLine("====================================================================="); Trace.WriteLine(" Files sorted by count"); foreach (var item in stats.Extensions.OrderByDescending(x => x.Value.FileCount)) { Trace.WriteLine(string.Format("Extension \"{0}\": {1:n0} files, {2:n0} bytes", item.Key.ToUpperInvariant(), item.Value.FileCount, item.Value.TotalSize)); } Trace.WriteLine("====================================================================="); Trace.WriteLine(" Files sorted by total length"); foreach (var item in stats.Extensions.OrderByDescending(x => x.Value.TotalSize)) { Trace.WriteLine(string.Format("Extension \"{0}\": {2:n0} bytes, {1:n0} files", item.Key.ToUpperInvariant(), item.Value.FileCount, item.Value.TotalSize)); } OutputDirectorytree(0, "", stats.RootDirectory); } }
private static T RoundTrip <T>(IProtoBufSerializer serializer, T req) where T : IpcMessage { var sw = Stopwatch.StartNew(); var stream = new MemoryStream(); serializer.Serialize(stream, req); sw.Stop(); Trace.WriteLine(string.Format("Serialized message of type {0} into {1:n0} bytes in {2} msec.", req.Data.GetType().FullName, stream.Length, sw.ElapsedMilliseconds)); stream.Position = 0; sw.Restart(); var result = serializer.Deserialize(stream); sw.Stop(); Trace.WriteLine(string.Format("Deserialized message of type {0} from {1:n0} bytes in {2} msec.", req.Data.GetType().FullName, stream.Length, sw.ElapsedMilliseconds)); return((T)result); }
private void WriteMessage(IpcMessage message) { lock (_writerLock) { _serializer.Serialize(_stream, message); } }