/// <summary> /// Print type statistics diff. /// </summary> /// <param name="typeInfos"></param> /// <param name="typeInfos2"></param> /// <param name="vmmap"></param> /// <param name="vmmap2"></param> /// <param name="topN"></param> /// <param name="orderBySize"></param> /// <param name="minCount"></param> /// <returns>Allocated memory diff in KB. If VMmap data is present the total allocated memory diff for allocated managed heap, heap, private, file mappings and sharable memory is returned.</returns> private int PrintTypeStatisticsDiff(List <TypeInfo> typeInfos, List <TypeInfo> typeInfos2, VMMapData vmmap, VMMapData vmmap2, int topN, int minCount, bool orderBySize) { int allocatedMemoryInKB = 0; TypeDiffStatistics delta = GetDiffStatistics(typeInfos, typeInfos2, orderBySize); if (minCount > 0) { delta.TypeDiffs = delta.TypeDiffs.Where(x => Math.Abs(orderBySize ? x.InstanceCountDiff : x.AllocatedBytesDiff) > minCount).ToList(); } string fmt = "{0,-12:N0}\t{1,-17:N0}\t{2,-11:N0}\t{3,-11:N0}\t{4,-17:N0}\t{5,-18:N0}" + "\t{6,-14}\t{7,-15}\t{8}"; OutputStringWriter.FormatAndWriteHeader(fmt, $"Delta({DisplayUnit})", "Delta(Instances)", "Instances", "Instances2", $"Allocated({DisplayUnit})", $"Allocated2({DisplayUnit})", "AvgSize(Bytes)", "AvgSize2(Bytes)", "Type"); long unitDivisor = (long)DisplayUnit; if (topN > 0) { foreach (var diff in delta.TypeDiffs.Take(topN)) { if (diff.Name == FreeTypeName) { continue; } OutputStringWriter.FormatAndWrite(fmt, diff.AllocatedBytesDiff / unitDivisor, diff.InstanceCountDiff, diff?.Info.SafeCount(), diff?.Info2.SafeCount(), diff?.Info.TotalSize() / unitDivisor, diff?.Info2.TotalSize() / unitDivisor, diff?.Info?.AverageSizePerInstance, diff?.Info2?.AverageSizePerInstance, diff.Name); } } allocatedMemoryInKB = (int)(delta.DeltaBytes / (long)DisplayUnit.KB); OutputStringWriter.FormatAndWrite(fmt, delta.DeltaBytes / unitDivisor, delta.DeltaInstances, delta.Count, delta.Count2, delta.SizeInBytes / unitDivisor, delta.SizeInBytes2 / unitDivisor, "", "", ManagedHeapAllocated); long heap1Size = Heap.GetTotalHeapSize(); long heap2Size = Heap2.GetTotalHeapSize(); OutputStringWriter.FormatAndWrite(fmt, (heap2Size - heap1Size) / unitDivisor, 0, 0, 0, heap1Size / unitDivisor, heap2Size / unitDivisor, "", "", ManagedHeapSize); if (vmmap != null && vmmap2 != null && vmmap.HasValues && vmmap2.HasValues) { var diff = vmmap2 - vmmap; WriteVMMapDataDiff(GetSimpleDiffFormatter(fmt, DisplayUnit), vmmap, vmmap2, diff); OutputStringWriter.FormatAndWrite(fmt, (diff.AllocatedBytesWithoutManagedHeap + delta.DeltaBytes) / unitDivisor, "", "", "", (delta.SizeInBytes + vmmap.AllocatedBytesWithoutManagedHeap) / unitDivisor, (vmmap2.AllocatedBytesWithoutManagedHeap + delta.SizeInBytes2) / unitDivisor, "" , "", AllocatedTotal); // When VMMap data is present add the other memory types which usually leak as well also to the allocation number. allocatedMemoryInKB += (int)(diff.AllocatedBytesWithoutManagedHeap / (long)DisplayUnit.KB); } return(allocatedMemoryInKB); }
// LOADING INPUT DATA FROM FILE private void ReadFromFile() { Console.WriteLine("Przeciagnij plik inicjalizacyjny i wcisnij enter:"); string str = Console.ReadLine(); if (str[0] == '"') str = str.Substring(1,str.Length-2); //string str = "F:\\Multimedia\\Dokumenty\\Studia\\PW Notatki\\Semestr 3\\AISDE\\Projekty\\Projekt1\\AISDE_nr1\\AISDE_nr1\\bin\\Debug\\Download\\Input\\router.txt"; FileStream fs = new FileStream(str, FileMode.OpenOrCreate, FileAccess.ReadWrite); System.IO.StreamReader filestream = new System.IO.StreamReader(fs); string tmp = ""; string[] words; bool logic = true; while (logic) { tmp = filestream.ReadLine(); if(!string.IsNullOrEmpty(tmp)) if (tmp[0] != '#') { logic = false; } } logic = true; while (logic) { tmp = filestream.ReadLine(); if (!string.IsNullOrEmpty(tmp)) if (tmp[0] != '#') { logic = false; } } words = tmp.Split(' '); channel_capacity = int.Parse(words[2]); logic = true; while (logic) { tmp = filestream.ReadLine(); if (!string.IsNullOrEmpty(tmp)) if (tmp[0] != '#') { logic = false; } } words = tmp.Split(' '); number_of_buffers = int.Parse(words[2]); int[] lbuffers = new int[number_of_buffers]; string[] buffers_names = new string[number_of_buffers]; for(int i=0;i< number_of_buffers; i++) { tmp = filestream.ReadLine(); words = tmp.Split(' '); lbuffers[i]= int.Parse(words[5]); buffers_names[i] = words[2]; } logic = true; while (logic) { tmp = filestream.ReadLine(); if (!string.IsNullOrEmpty(tmp)) if (tmp[0] != '#') { logic = false; } } words = tmp.Split(' '); int R = int.Parse(words[2]); float[] lambdas = new float[R]; for (int i = 0; i < R; i++) { tmp = filestream.ReadLine(); tmp = filestream.ReadLine(); words = tmp.Split(' '); words[2] = words[2].Replace(".",","); lambdas[i] = float.Parse(words[2]); } logic = true; while (logic) { tmp = filestream.ReadLine(); if (!string.IsNullOrEmpty(tmp)) if (tmp[0] != '#') { logic = false; } } words = tmp.Split(' '); number_of_streams = int.Parse(words[2]); names_of_streams = new string[number_of_streams]; string[] names_of_buffers = new string[number_of_streams]; string[] time_lambdas = new string[number_of_streams]; string[] size_lambdas = new string[number_of_streams]; for (int i = 0; i < number_of_streams; i++) { tmp = filestream.ReadLine(); words = tmp.Split(' '); names_of_streams[i] = words[2]; names_of_buffers[i] = words[5]; time_lambdas[i] = words[8]; size_lambdas[i] = words[11]; } filestream.Close(); // End of file reading // Setting up initial values flag = true; buffers = new Buffer[number_of_buffers]; streams = new Stream[number_of_streams]; for (int i = 0; i < number_of_buffers; i++) { buffers[i] = new Buffer(); buffers[i].SetSize(lbuffers[i]); } for (int i = 0; i < number_of_streams; i++) { streams[i] = new Stream(); for (int j = 0; j < R; j++) if("WYK"+(j+1)==time_lambdas[i]) streams[i].time_lambda = lambdas[j]; for (int j = 0; j < R; j++) if ("WYK" + (j+1) == size_lambdas[i]) streams[i].size_lambda = lambdas[j]; for (int j = 0; j < number_of_buffers; j++) if ("KOL" + (j + 1) == names_of_buffers[i]) streams[i].buffer_number = j; } heap = new Heap2<Times>(); Times times1 = new Times(); times1.action = 1; times1.time = 0; heap.Add(times1); for (int i = 0; i < number_of_streams; i++) { Times times = new Times(); times.action = 0; times.time = 0; times.stream_id = i; heap.Add(times); } // Statistics init simulation_timer = new Stopwatch(); last_buffer_modify_time = new double[number_of_buffers]; free_buffers2 = new double[number_of_buffers]; for (int i = 0; i < number_of_buffers; i++) { last_buffer_modify_time[i] = new double(); free_buffers2[i] = new double(); } losted_packets_counter = new int[number_of_streams]; packets_counter = new int[number_of_streams]; for (int i = 0; i < number_of_streams; i++) { packets_counter[i] = new int(); losted_packets_counter[i] = new int(); } packet_processing_mil = new double(); last_link_modify_time = new double(); free_link2 = new double(); }