Fody/MethodTimer

Incorrect method execution time in MethodTimeLogger

satuday opened this issue · 5 comments

Where it is clear that the below content has not read, the issue is likely to be closed with "please read the template". Please don't take offense at this. It is simply a time management decision. When someone raises an issue, without reading the template, then often too much time is spent going back and forth to obtain information that is outlined below.

You should already be a Patron

To be using Fody you should be a Patron. See Licensing/Patron FAQ. With that in mind, it is assumed anyone raising an issue is already a Patron. As such your GitHub Id may be verified against the OpenCollective contributors. This process will depend on the issue quality, your circumstances, and the impact on the larger user base.

Preamble

Questions specific to IL manipulation should be placed on Stack Overflow or the Cecil Forum.

General questions about Fody or weavers should be placed on Stack Overflow or the Fody Gitter room

Where relevant, ensure you are using the current stable versions of the following:

  • Fody (note for this you need an explicit NuGet reference to Fody in your csproj)
  • Any Fody weavers being used
  • Visual Studio
  • .NET Core SDK

Any code or stack traces must be properly formatted with GitHub markdown.

Describe the issue

The method execution time(long milliseconds) passed in to the Log method in MethodTimeLogger is incorrect when MethodTimeLogger is not in the same project. This seems to only happen in .net core projects. I have another project targeting .net framework 451 with pretty much the same setup and dont have this issue.

Minimal Repro

https://github.com/satuday/methodTimerTest

Submit a PR that fixes the bug

Submit a Pull Request (PR) that fixes the bug. Include in this PR a test that verifies the fix. If you were not able to fix the bug, a PR that illustrates your partial progress will suffice. If you prefer someone else fix this bug for you, please donate to the Fody OpenCollective and include a note to that effect in this issue.

Since this could technically affect us (if this is true), I decided to look into it to investigate the risk. I see a total MS of 5001661, where it should be around 500.

Note that using a MethodTimeLogger from another assembly without the TimeSpan is not supported:

Could not find 'Log' method on 'WebApplication1.abc.MethodTimeLogger'.

I don't see any wrong stuff in the generated code. Could it be the injected stopwatch (see https://github.com/Fody/MethodTimer/blob/master/MethodTimer.Fody/ReferenceFinder.cs#L64)?

Risk level: low with workaround (just (re)define in the project itself)

Just tested to be sure, if you define the MethodTimeLogger inside the project itself, it will pass in the correct duration (even for non-timespan (thus long) values).

@satuday , please try the latest version on NuGet released today.

looks good. thanks for quick fix.

@satuday
To be raising issues you should be a patron of Fody. Any issues raised by non Patrons may not be actively triaged, and eventually closed as stale.