/// <summary> /// Convert RoleFilter to IfcActorRole, need to be within a transaction /// </summary> /// <param name="role">RoleFilter</param> /// <param name="ifcRole">IfcRole</param> /// <returns></returns> private IIfcActorRole MapRole(RoleFilter role, IfcRoleEnum ifcRole) { if (_fedModel.CurrentTransaction != null) { var actorRole = _fedModel.Instances.New <IfcActorRole>(); if (ifcRole == IfcRoleEnum.USERDEFINED) { actorRole.Role = IfcRoleEnum.USERDEFINED; actorRole.UserDefinedRole = role.ToString(); } else { actorRole.Role = ifcRole; } actorRole.Description = role.ToString(); RoleMap.Add(role, actorRole); return(actorRole); } else { throw new InvalidOperationException("MapRole: No transaction currently in model"); } }
/// <summary> /// Convert RoleFilter to IfcActorRole, need to be within a transaction /// </summary> /// <param name="role">RoleFilter</param> /// <param name="ifcRole">IfcRole</param> /// <returns></returns> private IfcActorRole MapRole(RoleFilter role, IfcRole ifcRole) { if (_fedModel.IsTransacting) { IfcActorRole actorRole = _fedModel.Instances.New <IfcActorRole>(); if (ifcRole == IfcRole.UserDefined) { actorRole.Role = IfcRole.UserDefined; actorRole.UserDefinedRole = role.ToString(); } else { actorRole.Role = ifcRole; } actorRole.Description = role.ToString(); RoleMap.Add(role, actorRole); return(actorRole); } else { throw new InvalidOperationException("MapRole: No transaction currently in model"); } }
private static void ShowProcessesScreen(FdbSystemStatus status, HistoryMetric current, bool repaint) { const int BARSZ = 15; const int COL0 = 1; const int COL1 = COL0 + 18; const int COL2 = COL1 + 12; const int COL3 = COL2 + 15; const int COL4 = COL3 + 11 + BARSZ; const int COL5 = COL4 + 8; const int COL6 = COL5 + 12 + BARSZ; const int COL7 = COL6 + 10 + BARSZ; if (repaint) { Console.Title = "fdbtop - Processes"; RepaintTopBar(); Console.ForegroundColor = ConsoleColor.DarkCyan; WriteAt(COL0, 5, "Address (port)"); WriteAt(COL1, 5, "Network in / out (MB/s)"); WriteAt(COL3, 5, "CPU (%core)"); WriteAt(COL4, 5, "Memory Free / Total (GB)"); WriteAt(COL6, 5, "HDD (%busy)"); WriteAt(COL7, 5, "Roles"); #if DEBUG Console.ForegroundColor = ConsoleColor.DarkGray; WriteAt(COL0, 6, "0 - - - - - -"); WriteAt(COL1, 6, "1 - - - - - -"); WriteAt(COL2, 6, "2 - - - - - -"); WriteAt(COL3, 6, "3 - - - - - -"); WriteAt(COL4, 6, "4 - - - - - -"); WriteAt(COL5, 6, "5 - - - - - -"); WriteAt(COL6, 6, "6 - - - - - -"); WriteAt(COL7, 6, "7 - - - - - -"); #endif } UpdateTopBar(status, current); if (status.Cluster.Machines.Count == 0) { //TODO display error message? return; } var maxVersion = status.Cluster.Processes.Values.Max(p => p.Version); int y = 7; foreach (var machine in status.Cluster.Machines.Values.OrderBy(x => x.Address, StringComparer.Ordinal)) { var procs = status.Cluster.Processes.Values .Where(p => p.MachineId == machine.Id) .OrderBy(p => p.Address, StringComparer.Ordinal) .ToList(); var map = new RoleMap(); foreach (var proc in procs) { foreach (var role in proc.Roles) { map.Add(role.Value); } } Console.ForegroundColor = ConsoleColor.DarkGray; WriteAt(1, y, "{0,15} | {0,8} in {0,8} out | {0,6}% {0,15} | {0,5} / {0,5} GB {0,15} | {0,22} | {0,11} |", "" ); Console.ForegroundColor = ConsoleColor.White; //"{0,-15} | net {2,8:N3} in {3,8:N3} out | cpu {4,5:N1}% | mem {5,5:N1} / {7,5:N1} GB {8,-20} | hdd {9,5:N1}% {10,-20}", WriteAt(COL0, y, machine.Address); WriteAt(COL1, y, "{0,8:N3}", MegaBytes(machine.Network.MegabitsReceived.Hz * 125000)); WriteAt(COL2, y, "{0,8:N3}", MegaBytes(machine.Network.MegabitsSent.Hz * 125000)); WriteAt(COL3, y, "{0,6:N1}", machine.Cpu.LogicalCoreUtilization * 100); WriteAt(COL4, y, "{0,5:N1}", GigaBytes(machine.Memory.CommittedBytes)); WriteAt(COL5, y, "{0,5:N1}", GigaBytes(machine.Memory.TotalBytes)); //WriteAt(COL6, y, "{0,5:N1}", totalDiskBusy * 100); WriteAt(COL7, y, "{0,11}", map); Console.ForegroundColor = machine.Cpu.LogicalCoreUtilization >= 0.9 ? ConsoleColor.Red : ConsoleColor.Green; WriteAt(COL3 + 8, y, "{0,-15}", new string('|', Bar(machine.Cpu.LogicalCoreUtilization, 1, BARSZ))); // 1 = all the (logical) cores Console.ForegroundColor = machine.Memory.CommittedBytes >= 0.95 * machine.Memory.TotalBytes ? ConsoleColor.Red : ConsoleColor.Green; WriteAt(COL5 + 9, y, "{0,-15}", new string('|', Bar(machine.Memory.CommittedBytes, machine.Memory.TotalBytes, BARSZ))); //Console.ForegroundColor = totalDiskBusy >= 0.95 ? ConsoleColor.Red : ConsoleColor.Green; //WriteAt(COL6 + 7, y, "{0,-15}", new string('|', Bar(totalDiskBusy, 1, BARSZ))); ++y; //TODO: use a set to map procs ot machines? Where(..) will be slow if there are a lot of machines x processes foreach (var proc in procs) { int p = proc.Address.IndexOf(':'); string port = p >= 0 ? proc.Address.Substring(p + 1) : proc.Address; map = new RoleMap(); foreach (var role in proc.Roles) { map.Add(role.Value); } Console.ForegroundColor = ConsoleColor.DarkGray; WriteAt(1, y, "{0,7} | {0,5} | {0,8} in {0,8} out | {0,6}% {0,15} | {0,5} / {0,5} GB {0,15} | {0,5}% {0,15} | {0,11} |", "" ); Console.ForegroundColor = proc.Version != maxVersion ? ConsoleColor.DarkCyan : ConsoleColor.Gray; WriteAt(1 + 10, y, "{0,5}", proc.Version); Console.ForegroundColor = proc.Excluded ? ConsoleColor.DarkRed : ConsoleColor.Gray; WriteAt(COL0, y, "{0,7}", port); Console.ForegroundColor = ConsoleColor.Gray; WriteAt(COL1, y, "{0,8:N3}", MegaBytes(proc.Network.MegabitsReceived.Hz * 125000)); WriteAt(COL2, y, "{0,8:N3}", MegaBytes(proc.Network.MegabitsSent.Hz * 125000)); WriteAt(COL3, y, "{0,6:N1}", proc.Cpu.UsageCores * 100); WriteAt(COL4, y, "{0,5:N1}", GigaBytes(proc.Memory.UsedBytes)); WriteAt(COL5, y, "{0,5:N1}", GigaBytes(proc.Memory.AvailableBytes)); WriteAt(COL6, y, "{0,5:N1}", Math.Min(proc.Disk.Busy * 100, 100)); // 1 == 1 core, but a process can go a little bit higher WriteAt(COL7, y, "{0,11}", map); Console.ForegroundColor = proc.Cpu.UsageCores >= 0.95 ? ConsoleColor.DarkRed : ConsoleColor.DarkGreen; WriteAt(COL3 + 8, y, "{0,-15}", new string('|', Bar(proc.Cpu.UsageCores, 1, BARSZ))); Console.ForegroundColor = proc.Memory.UsedBytes >= 0.95 * proc.Memory.AvailableBytes ? ConsoleColor.DarkRed : ConsoleColor.DarkGreen; WriteAt(COL5 + 9, y, "{0,-15}", new string('|', Bar(proc.Memory.UsedBytes, proc.Memory.AvailableBytes, BARSZ))); Console.ForegroundColor = proc.Disk.Busy >= 0.95 ? ConsoleColor.DarkRed : ConsoleColor.DarkGreen; WriteAt(COL6 + 7, y, "{0,-15}", new string('|', Bar(proc.Disk.Busy, 1, BARSZ))); ++y; } ++y; } }
private static void ShowProcessesScreen(FdbSystemStatus status, HistoryMetric current, bool repaint) { const int BARSZ = 15; const int COL0 = 1; const int COL1 = COL0 + 18; const int COL2 = COL1 + 12; const int COL3 = COL2 + 15; const int COL4 = COL3 + 11 + BARSZ; const int COL5 = COL4 + 8; const int COL6 = COL5 + 12 + BARSZ; const int COL7 = COL6 + 10 + BARSZ; if (repaint) { Console.Title = "fdbtop - Processes"; RepaintTopBar(); Console.ForegroundColor = ConsoleColor.DarkCyan; WriteAt(COL0, 5, "Address (port)"); WriteAt(COL1, 5, "Network in / out (MB/s)"); WriteAt(COL3, 5, "CPU (%core)"); WriteAt(COL4, 5, "Memory Free / Total (GB)"); WriteAt(COL6, 5, "HDD (%busy)"); WriteAt(COL7, 5, "Roles"); #if DEBUG Console.ForegroundColor = ConsoleColor.DarkGray; WriteAt(COL0, 6, "0 - - - - - -"); WriteAt(COL1, 6, "1 - - - - - -"); WriteAt(COL2, 6, "2 - - - - - -"); WriteAt(COL3, 6, "3 - - - - - -"); WriteAt(COL4, 6, "4 - - - - - -"); WriteAt(COL5, 6, "5 - - - - - -"); WriteAt(COL6, 6, "6 - - - - - -"); WriteAt(COL7, 6, "7 - - - - - -"); #endif } UpdateTopBar(status, current); if (status.Cluster.Machines.Count == 0) { //TODO display error message? return; } var maxVersion = status.Cluster.Processes.Values.Max(p => p.Version); int y = 7; foreach(var machine in status.Cluster.Machines.Values.OrderBy(x => x.Address, StringComparer.Ordinal)) { var procs = status.Cluster.Processes.Values .Where(p => p.MachineId == machine.Id) .OrderBy(p => p.Address, StringComparer.Ordinal) .ToList(); var map = new RoleMap(); foreach(var proc in procs) { foreach(var role in proc.Roles) { map.Add(role.Value); } } Console.ForegroundColor = ConsoleColor.DarkGray; WriteAt(1, y, "{0,15} | {0,8} in {0,8} out | {0,6}% {0,15} | {0,5} / {0,5} GB {0,15} | {0,22} | {0,11} |", "" ); Console.ForegroundColor = ConsoleColor.White; //"{0,-15} | net {2,8:N3} in {3,8:N3} out | cpu {4,5:N1}% | mem {5,5:N1} / {7,5:N1} GB {8,-20} | hdd {9,5:N1}% {10,-20}", WriteAt(COL0, y, machine.Address); WriteAt(COL1, y, "{0,8:N3}", MegaBytes(machine.Network.MegabitsReceived.Hz * 125000)); WriteAt(COL2, y, "{0,8:N3}", MegaBytes(machine.Network.MegabitsSent.Hz * 125000)); WriteAt(COL3, y, "{0,6:N1}", machine.Cpu.LogicalCoreUtilization * 100); WriteAt(COL4, y, "{0,5:N1}", GigaBytes(machine.Memory.CommittedBytes)); WriteAt(COL5, y, "{0,5:N1}", GigaBytes(machine.Memory.TotalBytes)); //WriteAt(COL6, y, "{0,5:N1}", totalDiskBusy * 100); WriteAt(COL7, y, "{0,11}", map); Console.ForegroundColor = machine.Cpu.LogicalCoreUtilization >= 0.9 ? ConsoleColor.Red : ConsoleColor.Green; WriteAt(COL3 + 8, y, "{0,-15}", new string('|', Bar(machine.Cpu.LogicalCoreUtilization, 1, BARSZ))); // 1 = all the (logical) cores Console.ForegroundColor = machine.Memory.CommittedBytes >= 0.95 * machine.Memory.TotalBytes ? ConsoleColor.Red : ConsoleColor.Green; WriteAt(COL5 + 9, y, "{0,-15}", new string('|', Bar(machine.Memory.CommittedBytes, machine.Memory.TotalBytes, BARSZ))); //Console.ForegroundColor = totalDiskBusy >= 0.95 ? ConsoleColor.Red : ConsoleColor.Green; //WriteAt(COL6 + 7, y, "{0,-15}", new string('|', Bar(totalDiskBusy, 1, BARSZ))); ++y; //TODO: use a set to map procs ot machines? Where(..) will be slow if there are a lot of machines x processes foreach (var proc in procs) { int p = proc.Address.IndexOf(':'); string port = p >= 0 ? proc.Address.Substring(p + 1) : proc.Address; map = new RoleMap(); foreach (var role in proc.Roles) { map.Add(role.Value); } Console.ForegroundColor = ConsoleColor.DarkGray; WriteAt(1, y, "{0,7} | {0,5} | {0,8} in {0,8} out | {0,6}% {0,15} | {0,5} / {0,5} GB {0,15} | {0,5}% {0,15} | {0,11} |", "" ); Console.ForegroundColor = proc.Version != maxVersion ? ConsoleColor.DarkCyan : ConsoleColor.Gray; WriteAt(1 + 10, y, "{0,5}", proc.Version); Console.ForegroundColor = proc.Excluded ? ConsoleColor.DarkRed : ConsoleColor.Gray; WriteAt(COL0, y, "{0,7}", port); Console.ForegroundColor = ConsoleColor.Gray; WriteAt(COL1, y, "{0,8:N3}", MegaBytes(proc.Network.MegabitsReceived.Hz * 125000)); WriteAt(COL2, y, "{0,8:N3}", MegaBytes(proc.Network.MegabitsSent.Hz * 125000)); WriteAt(COL3, y, "{0,6:N1}", proc.Cpu.UsageCores * 100); WriteAt(COL4, y, "{0,5:N1}", GigaBytes(proc.Memory.UsedBytes)); WriteAt(COL5, y, "{0,5:N1}", GigaBytes(proc.Memory.AvailableBytes)); WriteAt(COL6, y, "{0,5:N1}", Math.Min(proc.Disk.Busy * 100, 100)); // 1 == 1 core, but a process can go a little bit higher WriteAt(COL7, y, "{0,11}", map); Console.ForegroundColor = proc.Cpu.UsageCores >= 0.95 ? ConsoleColor.DarkRed : ConsoleColor.DarkGreen; WriteAt(COL3 + 8, y, "{0,-15}", new string('|', Bar(proc.Cpu.UsageCores, 1, BARSZ))); Console.ForegroundColor = proc.Memory.UsedBytes >= 0.95 * proc.Memory.AvailableBytes ? ConsoleColor.DarkRed : ConsoleColor.DarkGreen; WriteAt(COL5 + 9, y, "{0,-15}", new string('|', Bar(proc.Memory.UsedBytes, proc.Memory.AvailableBytes, BARSZ))); Console.ForegroundColor = proc.Disk.Busy >= 0.95 ? ConsoleColor.DarkRed : ConsoleColor.DarkGreen; WriteAt(COL6 + 7, y, "{0,-15}", new string('|', Bar(proc.Disk.Busy, 1, BARSZ))); ++y; } ++y; } }