1 // 2 // Copyright (c) 2010-2024 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 using System; 8 using System.Linq; 9 using System.Runtime.InteropServices; 10 using Antmicro.Renode.Time; 11 using Antmicro.Renode.Utilities; 12 13 namespace Antmicro.Renode.Logging.Profiling 14 { 15 [Serializable] 16 [StructLayout(LayoutKind.Sequential, Pack = 1)] 17 public abstract class BaseEntry 18 { BaseEntry(ProfilerEntryType type)19 public BaseEntry(ProfilerEntryType type) 20 { 21 RealTime = CustomDateTime.Now.Ticks; 22 VirtualTime = TimeDomainsManager.Instance.VirtualTimeStamp.TimeElapsed.TotalMilliseconds; 23 Type = type; 24 } 25 26 // RealTime and VirtualTime are expressed in other units (ticks, miliseconds). 27 private long RealTime { get; } 28 private double VirtualTime { get; } 29 private ProfilerEntryType Type { get; } 30 } 31 32 [Serializable] 33 [StructLayout(LayoutKind.Sequential, Pack = 1)] 34 public class InstructionEntry : BaseEntry 35 { InstructionEntry(int cpuSlot, ulong executedInstructions)36 public InstructionEntry(int cpuSlot, ulong executedInstructions) : base(ProfilerEntryType.ExecutedInstructions) 37 { 38 CpuSlot = cpuSlot; 39 ExecutedInstructions = executedInstructions; 40 } 41 42 private int CpuSlot { get; } 43 private ulong ExecutedInstructions { get; } 44 } 45 46 [Serializable] 47 [StructLayout(LayoutKind.Sequential, Pack = 1)] 48 public class MemoryEntry : BaseEntry 49 { MemoryEntry(byte operation)50 public MemoryEntry(byte operation) : base(ProfilerEntryType.MemoryAccess) 51 { 52 Operation = operation; 53 } 54 55 private byte Operation { get; } 56 } 57 58 [Serializable] 59 [StructLayout(LayoutKind.Sequential, Pack = 1)] 60 public class PeripheralEntry : BaseEntry 61 { PeripheralEntry(byte operation, ulong address)62 public PeripheralEntry(byte operation, ulong address) : base(ProfilerEntryType.PeripheralAccess) 63 { 64 Operation = operation; 65 Address = address; 66 } 67 68 private byte Operation { get; } 69 private ulong Address { get; } 70 } 71 72 [Serializable] 73 [StructLayout(LayoutKind.Sequential, Pack = 1)] 74 public class ExceptionEntry : BaseEntry 75 { ExceptionEntry(ulong index)76 public ExceptionEntry(ulong index) : base(ProfilerEntryType.Exception) 77 { 78 Index = index; 79 } 80 81 private ulong Index { get; } 82 } 83 84 public enum ProfilerEntryType : byte 85 { 86 ExecutedInstructions, 87 MemoryAccess, 88 PeripheralAccess, 89 Exception 90 } 91 92 public enum MemoryOperation: byte 93 { 94 MemoryIORead, 95 MemoryIOWrite, 96 MemoryRead, 97 MemoryWrite, 98 InsnFetch, 99 } 100 } 101