StackTracing

Updated on December 24, 2017 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on December 1, 2017

Hey all,

I’ve got a question about stacktracing, wich is best explained using pseudo code:

public class A : NetworkBehaviour //yes its over a network, this is why im asking this in the first place
{
//code code code
void DoSomething()
{
CmdInvokeSomething();
}
[Command]
void CmdInvokeSomething()
{
FindObjectOfClass<B>().InvokeThis();
}
}
public class B : NetworkBehaviour
{
public void InvokeThis()
{
Debug.Log("Hello");
}
}

now this code will run and invoke the Cmd wich will start calling stuff on the lower levels of unity.
I don’t want this to show up in my debugs.

(yes its a very shitty debug but i feel like this would be a fun little fiddle..)

anyway, now that this example is out of the way lets go into more verbose stuff.

so i’ve got a class A and a class B wich are part of my project, as in, I wrote them.
A.CmdInvokeSomething() invokes not just the Cmd on the server but goes through a bunch of functions before getting there. Now I don’t want to show all this, I’d want to see a debug like:

(server) “Hello” in B.InvokeThis invoked by (client) B.CmdInvokeSomething invoked by B.DoSomething

this would be handy for me.
please help
thank you in advance
regards
-pre

  • Liked by
Reply
0 on December 1, 2017

Why do you need to know two levels of what invoked what?

Why not just debug log yourself when you need?

  • Liked by
Reply
Cancel
0 on December 8, 2017

I would suggest writing Debug.Log() in every method:

public class A : NetworkBehaviour 
{
 void DoSomething()
 { 
 Debug.Log(this.name + " : DoSomething()");
 CmdInvokeSomething();
 }
[Command]
 void CmdInvokeSomething()
 { 
 Debug.Log(this.name + " :CmdInvokeSomething()");
 FindObjectOfClass<B>().InvokeThis();
 }
}
public class B : NetworkBehaviour
{
 public void InvokeThis()
 {
 Debug.Log(this.name + " :InvokeThis()"); 
 } 
}

 

  • Liked by
Reply
Cancel
0 on December 24, 2017

I’m jumping into this a bit late… but if you haven’t figured something out yourself yet:

Short of creating your own stack trace that sends information about the stack between the client(s) and server.. there isn’t much you can do (or at least much that I am aware of).

The most basic way to do this would just to be send a string that compiles the stack as it goes around.. but that could easily become an enormous amount of data to be sending around depending on how you’ve designed your networking. A slightly more sophisticated way might be to store everything locally, then stitch it together when you need it. To do this, you could probably get away with storing the incoming and outgoing calls as well as sticking a unique id of sorts in each call. This way you should be able to follow the trail back and generate the callback when needed. Of course this isn’t exactly the most elegant of solutions, and it would increase overhead and places where things could go wrong.

On a different note.. this is something I’ve never tried messing with before, so I might try to make what I just described a reality. If you would be interested in seeing how this might look as a fully fleshed out idea, let me know 🙂

  • Liked by
Reply
Cancel