.Net Core 2.2.0

.Net Core 2.2.0已经发布有一段时间了,很多新鲜功能已经有博主介绍了,今天给大家介绍一下运行时事件并附上demo。

运行时事件

通常需要监视运行时服务(如当前进程的GC,JIT和ThreadPool),以了解这些服务在运行应用程序时的行为方式。在Windows系统上,这通常使用ETW并监视当前进程的ETW事件来完成。虽然这种方法仍然有效,但使用ETW并不总是容易或可能。无论您是在低权限环境中运行还是在Linux或macOS上运行,都可能无法使用ETW。

从.NET Core 2.2开始,现在可以使用EventListener类来使用CoreCLR事件。这些事件描述了GC,JIT,ThreadPool和interop的行为。它们是在Windows上作为CoreCLR ETW提供程序的一部分公开的相同事件。这允许应用程序使用这些事件或使用传输机制将它们发送到遥测聚合服务。

Runtime Events

It is often desirable to monitor runtime services such as the GC, JIT, and ThreadPool of the current process to understand how these services are behaving while running your application. On Windows systems, this is commonly done using ETW and monitoring the ETW events of the current process. While this continues to work well, it is not always easy or possible to use ETW. Whether you’re running in a low-privilege environment or running on Linux or macOS, it may not be possible to use ETW.

Starting with .NET Core 2.2, CoreCLR events can now be consumed using the EventListener class. These events describe the behavior of GC, JIT, ThreadPool, and interop. They are the same events that are exposed as part of the CoreCLR ETW provider on Windows. This allows for applications to consume these events or use a transport mechanism to send them to a telemetry aggregation service.

Demo:

using System;
using System.Diagnostics.Tracing; namespace ConsoleApp
{
internal class Program
{
private static void Main(string[] args)
{
SimpleEventListener l = new SimpleEventListener(); add();
Console.ReadLine();
} public static string add()
{
return "123";
}
} internal sealed class SimpleEventListener : EventListener
{
// Called whenever an EventSource is created.
protected override void OnEventSourceCreated(EventSource eventSource)
{
// Watch for the .NET runtime EventSource and enable all of its events.
if (eventSource.Name.Equals("Microsoft-Windows-DotNETRuntime"))
{
EnableEvents(eventSource, EventLevel.Verbose, (EventKeywords)(-1));
}
} // Called whenever an event is written.
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
// Write the contents of the event to the console.
Console.WriteLine($"ThreadID = {eventData.OSThreadId} ID = {eventData.EventId} Name = {eventData.EventName}");
for (int i = 0; i < eventData.Payload.Count; i++)
{
string payloadString = eventData.Payload[i]?.ToString() ?? string.Empty;
Console.WriteLine($"\tName = \"{eventData.PayloadNames[i]}\" Value = \"{payloadString}\"");
}
Console.WriteLine("\n");
}
}
}

2020.04.03补充:

https://www.cnblogs.com/artech/p/performance-counter-in-net-core.html

参考

https://www.cnblogs.com/justmine/p/10069160.html

https://www.cnblogs.com/viter/p/10140697.html

https://www.tenforums.com/windows-10-news/122856-announcing-net-core-2-2-a.html

.net core 运行时事件(Runtime Events)的更多相关文章

  1. 在Linux安装ASP.NET Core运行时环境

    我使用的是Centos7 ,其它的Linux请参考微软文档   微软官方介绍文档:                                https://www.microsoft.com/n ...

  2. java 常用类库:操作系统System类,运行时环境Runtime

    System类: System 类代表Java程序的运行平台,程序不能创建System类的对象, System类提供了一些类变量和类方法,允许直接通过 System 类来调用这些类变量和类方法. Sy ...

  3. iOS运行时编程(Runtime Programming)和Java的反射机制对比

    运行时进行编程,类似Java的反射.运行时编程和Java反射的对比如下:   1.相同点   都可以实现的功能:获取类信息.属性设置获取.类的动态加载(NSClassFromString(@“clas ...

  4. iOS-浅谈runtime运行时机制-runtime简单使用(转)

    转自http://www.cnblogs.com/guoxiao/p/3583432.html 由于OC是运行时语言,只有在程序运行时,才会去确定对象的类型,并调用类与对象相应的方法.利用runtim ...

  5. LoadRunner 学习笔记(2)VuGen运行时设置Run-Time Setting

    定义:在Vugen中Run-Time Setting是用来设置脚本运行时所需要的相关选项

  6. .NET Core 运行时标识符 (RID) 目录

    RID 是什么? RID 是运行时标识符的缩写. RID 用于标识其中将运行应用程序或资产(即程序集)的目标操作系统. 其外观类似如下:“ubuntu.14.04-x64”.“win7-x64”.“o ...

  7. ArcMap运行时出现Runtime Error错误的解决方案

    运行ArcMap时弹出错误提示:“Microsoft Visual C++ Runtime Library. Runtime 1.开始->运行->regsvr32 "C:\Pro ...

  8. 【ASP.NET Core快速入门】(四)在CentOS上安装.NET Core运行时、部署到CentOS

    下载.NET Core SDK 下载地址:https://www.microsoft.com/net/download/windows 第一步:Add the dotnet product feed( ...

  9. [转]Loadrunner11之VuGen运行时设置Run-Time Setting

    转自:http://www.51testing.com/html/92/450992-248065.html General 1.Run Logic运行逻辑 脚本如何运行的,每个action和acti ...

随机推荐

  1. GMT\UTC YYYY-MM-DDTHH:mm:ss.sssZ、YYYY-MM-DDTHH:mm:ss.sss+8:00意义及与北京时间转换

    UTC: Universal Time Coordinated 协调世界时,又称世界标准时间. GMT: Greenwich Mean Time 格林尼治平均时. 格林尼治标准时间的正午是指当太阳横穿 ...

  2. python 1-100的数相加的和

    count = 1 sum = 0 while count <= 100: sum = sum + count count = count + 1 print(sum) 解释: count表示计 ...

  3. git加速和只下载部分目录

    浅复制 工作要用到的.git有1.8G太大了.下载过程要好几个小时,太慢了.可以这样操作 git clone 默认会下载项目的完整历史版本,如果你只关心最新版的代码,而不关心之前的历史信息,可以使用 ...

  4. CarbonData-2:core

    package Core是carbondata的核心代码. 照例,先看Test类.CarbonPropertiesValidationTest

  5. Unity3D中的shader基础知识

    1.Unity中配备了强大的阴影和材料的语言工具称为ShaderLab,以程式语言来看,它类似于CgFX和Direct3D的效果框架语法,它描述了材质所必须要的一切咨询,而不仅仅局限于平面顶点/像素着 ...

  6. Django框架详细介绍---中间件(认证)

    一.绪论 在cookie和session的应用中,通过在视图函数内添加装饰器判断用户是否登录,把没有登录的用户请求跳转到登录页面,通过给几个特定视图函数加装饰器实现了这个需求.但是以后添加的视图函数可 ...

  7. C++ STL stack 用法

    Stack(栈)是一种后进先出的数据结构,也就是LIFO(last in first out) ,最后加入栈的元素将最先被取出来,在栈的同一端进行数据的插入与取出,这一段叫做“栈顶”. 使用STL的s ...

  8. IT题库6-同步和异步

    同步就是许多线程同时共用一个资源,一个线程在用别的线程就要等待.异步相反,可以不用等待. 同步:发送一个请求,等待返回,然后才能再发送下一个请求:异步:发送一个请求,不等待返回,随时可以再发送下一个请 ...

  9. UVA10723 电子人的基因 Cyborg Genes

    题意翻译 [题目描述] 输入两个A~Z组成的字符串(长度均不超过30),找一个最短的串,使得输入的两个串均是它的子序列(不一定连续出现).你的程序还应统计长度最短的串的个数. e.g.:ABAAXGF ...

  10. 关于 mysql2 -v '0.3.21'(CentOS7.3)

    个人由于没有安装mysql而是装的MariaDB,所以网上说安装mysql,故没有采用,经查阅资料后,详细情况如下: Gem时报错: [root@localhost ~]# gem install m ...