about summary refs log tree commit diff
path: root/MatrixUtils.Web/Shared
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixUtils.Web/Shared')
-rw-r--r--MatrixUtils.Web/Shared/MainLayout.razor8
-rw-r--r--MatrixUtils.Web/Shared/ResourceUsage.razor64
-rw-r--r--MatrixUtils.Web/Shared/RoomListItem.razor2
-rw-r--r--MatrixUtils.Web/Shared/TimelineComponents/BaseTimelineItem.razor4
-rw-r--r--MatrixUtils.Web/Shared/TimelineComponents/TimelineUnknownStateItem.razor16
5 files changed, 89 insertions, 5 deletions
diff --git a/MatrixUtils.Web/Shared/MainLayout.razor b/MatrixUtils.Web/Shared/MainLayout.razor
index 41c3d69..c67f73c 100644
--- a/MatrixUtils.Web/Shared/MainLayout.razor
+++ b/MatrixUtils.Web/Shared/MainLayout.razor
@@ -1,4 +1,5 @@
-@inherits LayoutComponentBase
+@using ArcaneLibs
+@inherits LayoutComponentBase
 
 <div class="page">
     <div class="sidebar">
@@ -7,7 +8,8 @@
 
     <main>
         <div class="top-row px-4">
-            <PortableDevTools></PortableDevTools>
+            @* <PortableDevTools/> *@
+            @* <ResourceUsage/> *@
             <a style="color: #ccc; text-decoration: underline" href="https://cgit.rory.gay/matrix/MatrixRoomUtils.git/" target="_blank">Git</a>
             <a style="color: #ccc; text-decoration: underline" href="https://matrix.to/#/%23mru%3Arory.gay?via=rory.gay&via=matrix.org&via=feline.support" target="_blank">Matrix</a>
         </div>
@@ -15,6 +17,8 @@
         <article class="Content px-4">
             @Body
         </article>
+
+
     </main>
 </div>
 
diff --git a/MatrixUtils.Web/Shared/ResourceUsage.razor b/MatrixUtils.Web/Shared/ResourceUsage.razor
new file mode 100644
index 0000000..2a6365f
--- /dev/null
+++ b/MatrixUtils.Web/Shared/ResourceUsage.razor
@@ -0,0 +1,64 @@
+@using ArcaneLibs
+@using System.Diagnostics
+<h3>ResourceUsage</h3>
+<ModalWindow Title="Resource usage">
+    <div style="background-color: white; color: black;">
+        <span>Memory usage: @lastMemoryUsage</span>
+        <br/>
+        <TimelineGraph Data="MemoryUsage" ValueFormatter="@((double val) => Util.BytesToString((long)val))" Width="400"></TimelineGraph>
+    </div>
+    
+    <div style="background-color: white; color: black;">
+        <span>Time jitter: @lastCpuJitter</span>
+        <br/>
+        <TimelineGraph Data="CpuUsage" ValueFormatter="@(val => TimeSpan.FromTicks((long)val).ToString())" Width="400"></TimelineGraph>
+    </div>
+</ModalWindow>
+
+@code {
+    private Dictionary<DateTime, double> MemoryUsage = new();
+    private Dictionary<DateTime, double> CpuUsage = new();
+    private string lastMemoryUsage = "";
+    private string lastCpuJitter = "";
+
+    protected override async Task OnInitializedAsync() {
+        Task.Run(async () => {
+            try {
+                while (true) {
+                    lastMemoryUsage = Util.BytesToString((long)(MemoryUsage[DateTime.Now] = GC.GetTotalMemory(false)));
+                    if (MemoryUsage.Count > 60)
+                        MemoryUsage.Remove(MemoryUsage.Keys.First());
+                    await Task.Delay(1000);
+                }
+            }
+            catch (Exception e) {
+                Console.WriteLine(e);
+            }
+        });
+        
+        // calculate cpu usage estimate without Process or PerformanceCounter
+        Task.Run(async () => {
+            try {
+                var sw = new Stopwatch();
+                while (true) {
+                    sw.Restart();
+                    await Task.Delay(1000);
+                    sw.Stop();
+                    // CpuUsage[DateTime.Now] = sw.ElapsedTicks - TimeSpan.TicksPerSecond;
+                    var usage = sw.Elapsed - TimeSpan.FromSeconds(1);
+                    CpuUsage[DateTime.Now] = usage.Ticks - TimeSpan.TicksPerSecond;
+                    lastCpuJitter = usage.ToString();
+                    if (CpuUsage.Count > 60)
+                        CpuUsage.Remove(MemoryUsage.Keys.First());
+                    StateHasChanged();
+                }
+            }
+            catch (Exception e) {
+                Console.WriteLine(e);
+            }
+        });
+
+        await base.OnInitializedAsync();
+    }
+
+}
\ No newline at end of file
diff --git a/MatrixUtils.Web/Shared/RoomListItem.razor b/MatrixUtils.Web/Shared/RoomListItem.razor
index 623a03a..5a33b65 100644
--- a/MatrixUtils.Web/Shared/RoomListItem.razor
+++ b/MatrixUtils.Web/Shared/RoomListItem.razor
@@ -11,7 +11,7 @@
     <div class="roomListItem @(HasDangerousRoomVersion ? "dangerousRoomVersion" : HasOldRoomVersion ? "oldRoomVersion" : "")" id="@RoomInfo.Room.RoomId">
         @if (OwnMemberState != null) {
             @* Class="@("avatar32" + (OwnMemberState?.AvatarUrl != GlobalProfile?.AvatarUrl ? " highlightChange" : "") + (ChildContent is not null ? " vcenter" : ""))" *@
-            <MxcImage Circular="true" Height="32" Width="32" MxcUri="@(OwnMemberState.AvatarUrl ?? GlobalProfile.AvatarUrl)"/>
+            <MxcImage Homeserver="hs" Circular="true" Height="32" Width="32" MxcUri="@(OwnMemberState.AvatarUrl ?? GlobalProfile.AvatarUrl)"/>
             <span class="centerVertical border75 @(OwnMemberState?.AvatarUrl != GlobalProfile?.AvatarUrl ? "highlightChange" : "")">
                 @(OwnMemberState?.DisplayName ?? GlobalProfile?.DisplayName ?? "Loading...")
             </span>
diff --git a/MatrixUtils.Web/Shared/TimelineComponents/BaseTimelineItem.razor b/MatrixUtils.Web/Shared/TimelineComponents/BaseTimelineItem.razor
index c7bfd51..08aeffe 100644
--- a/MatrixUtils.Web/Shared/TimelineComponents/BaseTimelineItem.razor
+++ b/MatrixUtils.Web/Shared/TimelineComponents/BaseTimelineItem.razor
@@ -14,9 +14,9 @@
     [Parameter]
     public AuthenticatedHomeserverGeneric Homeserver { get; set; }
 
-    public List<StateEventResponse> EventsBefore => Events.TakeWhile(e => e.EventId != Event.EventId).ToList();
+    public IEnumerable<StateEventResponse> EventsBefore => Events.TakeWhile(e => e.EventId != Event.EventId);
 
-    public List<StateEventResponse> MatchingEventsBefore => EventsBefore.Where(x => x.Type == Event.Type && x.StateKey == Event.StateKey).ToList();
+    public IEnumerable<StateEventResponse> MatchingEventsBefore => EventsBefore.Where(x => x.Type == Event.Type && x.StateKey == Event.StateKey);
 
     public StateEventResponse? PreviousState => MatchingEventsBefore.LastOrDefault();
 
diff --git a/MatrixUtils.Web/Shared/TimelineComponents/TimelineUnknownStateItem.razor b/MatrixUtils.Web/Shared/TimelineComponents/TimelineUnknownStateItem.razor
new file mode 100644
index 0000000..4f05b30
--- /dev/null
+++ b/MatrixUtils.Web/Shared/TimelineComponents/TimelineUnknownStateItem.razor
@@ -0,0 +1,16 @@
+@using ArcaneLibs.Extensions
+@inherits BaseTimelineItem
+
+<div>
+    <details style="display: inline;">
+        <summary>
+            <i style="color: red;">Unknown event type: <pre style="display: inline;">@Event.Type</pre></i>
+        </summary>
+        <pre>@Event.ToJson(ignoreNull: true)</pre>
+    </details>
+</div>
+
+@code {
+
+
+}