Skip to content

Add some RTD logging #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/ExcelDna.Integration/ExcelRtd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void RegisterRtdServerTypes(IEnumerable<Type> rtdServerTypes)
// ThreadSafe
public static bool TryRTD(out object result, string progId, string server, params string[] topics)
{
Debug.Print("### RtdRegistration.RTD " + progId);
Debug.Print($"[{DateTime.Now:HH:mm:ss.f}] ### RtdRegistration.RTD " + progId);
// Check if this is any of our business.
if (!string.IsNullOrEmpty(server))
{
Expand Down
8 changes: 8 additions & 0 deletions Source/ExcelDna.Integration/ExcelRtdServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using ExcelDna.Logging;

namespace ExcelDna.Integration.Rtd
Expand Down Expand Up @@ -234,6 +235,7 @@ void SetDirty(Topic topic)
// This is the private implementation of the IRtdServer interface
int IRtdServer.ServerStart(IRTDUpdateEvent callbackObject)
{
Debug.WriteLine($"[{DateTime.Now:HH:mm:ss.f}] ServerStart");
try
{
_updateSync = SynchronizationManager.RtdUpdateSynchronization;
Expand Down Expand Up @@ -264,6 +266,7 @@ int IRtdServer.ServerStart(IRTDUpdateEvent callbackObject)
// if newValues is now true, Excel will use the value returned by ConnectData.
object IRtdServer.ConnectData(int topicId, ref Array strings, ref bool newValues)
{
Debug.WriteLine($"[{DateTime.Now:HH:mm:ss.f}] ConnectData");
try
{
// Check for an active topic with the same topicId
Expand Down Expand Up @@ -330,6 +333,7 @@ object IRtdServer.ConnectData(int topicId, ref Array strings, ref bool newValues

Array IRtdServer.RefreshData(ref int topicCount)
{
Debug.WriteLine($"[{DateTime.Now:HH:mm:ss.f}] RefreshData");
// Get a copy of the dirty topics to work with,
// locking as briefly as possible (thanks Naju).
Dictionary<Topic, object> temp;
Expand All @@ -352,13 +356,15 @@ Array IRtdServer.RefreshData(ref int topicCount)
{
result[0, i] = topic.TopicId;
result[1, i] = topic.Value;
Debug.WriteLine($"[{DateTime.Now:HH:mm:ss.f}] RefreshData - TopicId: {topic.TopicId} Value: {topic.Value}");
i++;
}
return result;
}

void IRtdServer.DisconnectData(int topicId)
{
Debug.WriteLine($"[{DateTime.Now:HH:mm:ss.f}] DisconnectData");
try
{
Topic topic;
Expand Down Expand Up @@ -387,6 +393,7 @@ void IRtdServer.DisconnectData(int topicId)
// (though this should not be needed according to the RTD interface contract)
int IRtdServer.Heartbeat()
{
Debug.WriteLine($"[{DateTime.Now:HH:mm:ss.f}] Heartbeat");
try
{
// Re-post the notify in case something went wrong on the Excel side or our sync window
Expand Down Expand Up @@ -418,6 +425,7 @@ int IRtdServer.Heartbeat()

void IRtdServer.ServerTerminate()
{
Debug.WriteLine($"[{DateTime.Now:HH:mm:ss.f}] ServerTerminate");
try
{
// The Unregister call here just tells the reg-free loading that we are gone,
Expand Down
3 changes: 3 additions & 0 deletions Source/ExcelDna.Integration/ExcelSynchronizationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public RtdUpdateSynchronization(SynchronizationWindow syncWindow)
// We assume UpdateNotify is not called too often here (need RTD server to be careful).
public void UpdateNotify(IRTDUpdateEvent updateEvent)
{
Debug.WriteLine($"[{DateTime.Now:HH:mm:ss.f}] RtdUpdateSynchronization.UpdateNotify");
lock (_lockObject)
{
_pendingRtdUpdates[updateEvent] = null;
Expand Down Expand Up @@ -142,6 +143,7 @@ public void DeregisterUpdateNotify(IRTDUpdateEvent updateEvent)
// However, the problem reported there was surely when called from another thread. Does suspension of the object model affect us here?
public void ProcessUpdateNotifications()
{
Debug.WriteLine($"[{DateTime.Now:HH:mm:ss.f}] ProcessUpdateNotifications");
// CONSIDER: Do temp swap trick to reduce locking?
lock (_lockObject)
{
Expand All @@ -152,6 +154,7 @@ public void ProcessUpdateNotifications()
{
if (_registeredRtdUpdates.ContainsKey(pendingRtdUpdate))
{
Debug.WriteLine($"[{DateTime.Now:HH:mm:ss.f}] Calling UpdateNotify - Thread: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
pendingRtdUpdate.UpdateNotify();
}
}
Expand Down