.NET Framework Developer Center > .NET Development Forums > Building Development and Diagnostic Tools for .Net > How To Differentiate Different Components (Namespace) in Same Assembly in Profiler
Ask a questionAsk a question
 

AnswerHow To Differentiate Different Components (Namespace) in Same Assembly in Profiler

  • Tuesday, November 03, 2009 4:03 PMPRATIK BHADKOLIYA Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    I am trying to make a custom profiler that gives me information about method call sequence only when i try to call a method of different namespace from current namespace...
    Example,
    namespace sample
    {
        class abc
        {
             public static void Main(String[] args)
             {
                  double x = System.Math.Sin(1.5);
                  xyz.print(x);
             }
        }
        public class xyz
        {
            public static void print(double x)
            {
                   System.Console.WriteLine(x.ToString());
            }
        }
    }

    So, in above example when i try to call to method of System.Math (other than sample namespace) then i want information about method enter/exit but if my method call is of diiferent class but same namespace as in case of xyz.print method then i dont want information


    So, i want to make a profiler that gives me information about all method calls belonging to another namespace..............
    Is there any ID that differentiate two namespace as ObjectID and ThreadID that differentiate different class and threads????


    Thanks in Advance................

    • Moved byRoahn LuoMSFTWednesday, November 04, 2009 10:41 AMmove to the correct forum. (From:Visual Studio Performance Tools (Profiler))
    •  

Answers

  • Wednesday, November 04, 2009 7:03 PMKarel ZikmundMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Threads don't belong to any namespace, only types do (ClassID).

    You can go through method's IL code, check all calls and ask for the callee method's type name (I guess you would have to use MetaData API). This might be tricky for virtual calls - as the call could be 'callvirt System.ToString()', but end up in Sample.abc.ToString(), when called on Sample.abc instance or instance of inheritted type.

    You can get the type from ObjectID (ICorProfilerInfo::GetClassFromObject).

    -Karel

All Replies

  • Wednesday, November 04, 2009 7:03 PMKarel ZikmundMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Threads don't belong to any namespace, only types do (ClassID).

    You can go through method's IL code, check all calls and ask for the callee method's type name (I guess you would have to use MetaData API). This might be tricky for virtual calls - as the call could be 'callvirt System.ToString()', but end up in Sample.abc.ToString(), when called on Sample.abc instance or instance of inheritted type.

    You can get the type from ObjectID (ICorProfilerInfo::GetClassFromObject).

    -Karel
  • Tuesday, November 24, 2009 4:53 AMKarel ZikmundMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Pratik, if you don't think that my answer is sufficient, please give us more information why.
    -Karel