3

我有一个使用在 Service Fabric 上运行的 EventFlow 的 ETW 侦听器。

这是我的配置文件(eventFlowConfig.json):

{
  "inputs": [
    {
      "type": "ETW",
      "sessionNamePrefix": "MyListenerService",
      "cleanupOldSessions": true,
      "reuseExistingSession": true,
      "providers": [
        {
          "providerName": "Provider0"
        }
      ]
    }
  ],
  "filters": [],
  "outputs": [
    {
      "type": "CustomOutput"
    }
  ],
  "schemaVersion": "2018-04-04",

  "extensions": [
    {
      "category": "outputFactory",
      "type": "CustomOutput",
      "qualifiedTypeName": "MyNamespace.EventFlow.Outputs.CustomOutputFactory, MyAssembly"
    }
  ]
}

这是我的切入点:

private static void Main()
{
    try
    {
        string configurationFileName = "eventFlowConfig.json";

        using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("MyService", configurationFileName))
        {
            ServiceRuntime.RegisterServiceAsync("MyServiceType",
                context => new Service(context)).GetAwaiter().GetResult();

            ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(Service).Name);
            // Prevents this host process from terminating so services keeps running. 
            Thread.Sleep(Timeout.Infinite);
        }
    }
    catch (Exception e)
    {
        ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
        throw;
    }
}

当我在调试时在本地集群中多次启动/停止我的服务时,我得到了这个异常:

System.Runtime.InteropServices.COMException: 'Insufficient system resources exist to complete the requested service. (Exception from HRESULT: 0x800705AA)'

在重新启动计算机之前,我无法重新启动服务。问题是我在本地以外的其他环境中遇到了同样的异常。

我试过这个:ServiceFabric 应用程序中的 TraceEventSession 使用引发资源不足错误:我的服务是无状态的,并且只有一个节点实例。

此配置是否足以释放/重用 ETW 会话?

"sessionNamePrefix": "MyListenerService",
"cleanupOldSessions": true,
"reuseExistingSession": true,

有没有其他人遇到过这个问题?

编辑 在@Diego Mendes 的回答之后,我已经执行了这个logman -ets

...
EventFlow-EtwInput-a8aefb3c-594f-4ac7-b9d8-6da1791fb122 Trace                         Running
EventFlow-EtwInput-fe5f58e6-d1a7-4198-95b2-d343584cf46b Trace                         Running
EventFlow-EtwInput-33f67287-5563-4835-b3a1-5527e4fc5e5e Trace                         Running
EventFlow-EtwInput-959eef04-a5ae-47eb-9b7e-057a9fd3fb28 Trace                         Running
EventFlow-EtwInput-0095f186-d657-4974-a613-213d7eb49def Trace                         Running
EventFlow-EtwInput-8fbc52f5-2de6-4826-bce2-36d8abf0c264 Trace                         Running
EventFlow-EtwInput-8e654b40-c299-48f4-818e-5ebe3c2341a4 Trace                         Running
EventFlow-EtwInput-7ec63ec9-428b-4658-b059-698b5ae66986 Trace                         Running

EventFlow 忽略了我sessionNamePrefix并用EventFlow-EtwInput? 可能是 EventFlow 的错误?

我会尝试EventFlow-EtwInput用作我的sessionNamePrefix.

4

2 回答 2

5

正如您所指出的,这是因为您多次启动和停止服务。每次启动服务时,都会创建一个新会话,当您在调试模式下执行此操作时,调试器会在关闭活动会话之前终止进程。

从您链接的马特回答中:

Windows 有 64 个可以同时运行的 ETW 会话的限制。考虑使用在每个节点上运行的单个无状态应用程序来创建单个会话。

您可以通过运行以下命令检查它何时再次发生,是否有任何会话处于打开状态:

logman -ets

它将列出所有活动会话,您的会话可能显示为如下所示:

MyListenerService-A402EE30-53B7-48E4-B602-76B101C0AB97

如果您有多个会话处于活动状态,是因为它没有正确关闭,也没有重用旧会话。

在配置中,当您设置:

cleanupOldSessions:如果设置为 TRUE,与 sessionNamePrefix 匹配的现有 ETW 跟踪会话将被关闭。这有助于收集剩余的会话实例,因为它们的数量是有限的。

reuseExistingSession:如果打开,则将重新使用与 sessionNamePrefix 匹配的现有跟踪会话。如果 cleanupOldSessions 也打开了,那么它将保留一个会话以供重复使用。

根据您的设置,您同时使用两者,我会尝试调整这些值以查看是否可以解决问题。

于 2018-07-17T09:45:57.197 回答
2

只是添加到这个答案,因为我得到了同样的错误。

  1. 使用列出所有活动会话

logman -ets

  1. 对于所有活动会话执行停止命令,如

logman 停止“MyListenerService-A402EE30-53B7-48E4-B602-76B101C0AB97”-ets

它帮助我继续我的代码。

于 2020-11-10T20:14:38.030 回答