Remote application profiler agent port

Questions about YourKit .NET Profiler
Post Reply
sandeep
Posts: 24
Joined: Wed May 16, 2012 3:08 pm

Remote application profiler agent port

Post by sandeep »

I want to profile all .NET applications on a remoter machine. I've copied the ynpagent.dll and setup as described in he docs. Is there a way to get a list of processes and the port the profiling agent is listening on for all the processes that have started with profiling agent on the remote machine?

I can see this list when I click "Connect to Remote application" in the UI and specify the host machine.
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Remote application profiler agent port

Post by Anton Katilin »

The only way to explicitly get the list is to use "Connect to Remote application" in the UI.

You can use the API to get this information programmatically:
http://www.yourkit.com/docs/net70/help/api.jsp

The following simple code enumerates the ports of at a given host and prints them out to the console:

Code: Select all

using System;
using YourKit.Profiler.Api;

class ListProfiledApplications {
  static int Main(string[] args) {
    if (args.Length != 1) {
      Console.WriteLine("use: <remote host name or IP address>");
      return 1;
    }

    String host = args[0];

    Console.WriteLine("Probing profiler agents at " + host);

    int found = 0;

    for (int port = 10001; port <= 10010; port++) {
      try {
        Controller controller = new Controller(host, port);
        Console.WriteLine("port=" + port);
        found++;
      }
      catch (Exception) {
        // no agent at this port
      }
    }

    Console.WriteLine("Totally found: " + found);

    return 0;
  }
}
Notes:

1. The API dll is located in <profiler installation directory>\api\YourKit.Profiler.Api.dll
You will need to reference it when compiling this example. When running the example, it should be in the PATH or in the current directory.

2. A method to retrieve the PID is not exposed in the public API now. We will add Controller.GetPID() method it in the next build 7.0.2.
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Remote application profiler agent port

Post by Anton Katilin »

Version 7.0.2 has been released.

Please find below the modified example which prints port, PID and name for each found profiled application:

Code: Select all

using System;
using YourKit.Profiler.Api;

class ListProfiledApplications {
  static int Main(string[] args) {
    if (args.Length != 1) {
      Console.WriteLine("use: <remote host name or IP address>");
      return 1;
    }

    String host = args[0];

    Console.WriteLine("Probing profiler agents at " + host);

    int found = 0;

    for (int port = 10001; port <= 10010; port++) {
      try {
        Controller controller = new Controller(host, port);
        Console.WriteLine("port=" + port + " pid=" + controller.GetPID() + " name=" + controller.GetSessionName());
        found++;
      }
      catch (Exception) {
        // no agent at this port
      }
    }

    Console.WriteLine("Totally found: " + found);

    return 0;
  }
}
Post Reply