惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
罗磊的独立博客
H
Help Net Security
I
Intezer
G
Google Developers Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
Troy Hunt's Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
U
Unit 42
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
J
Java Code Geeks
S
Security Affairs
T
The Blog of Author Tim Ferriss
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
D
Docker
The GitHub Blog
The GitHub Blog
F
Full Disclosure
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
S
Security @ Cisco Blogs
腾讯CDC
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
Blog — PlanetScale
Blog — PlanetScale
T
Threatpost
D
DataBreaches.Net
Recent Announcements
Recent Announcements
博客园 - 三生石上(FineUI控件)
MongoDB | Blog
MongoDB | Blog
博客园 - 【当耐特】
L
LINUX DO - 最新话题
Google Online Security Blog
Google Online Security Blog
S
Schneier on Security
S
Securelist
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Help Net Security
Help Net Security
P
Proofpoint News Feed
Project Zero
Project Zero
S
SegmentFault 最新的问题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
宝玉的分享
宝玉的分享
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 叶小钗

博客园 - 江大渔

SuperSocket 2.0 发布第一个预览版, 另寻找Yang Fan哥哥 .NET Core 1.0 RC2 历险之旅 - 江大渔 使用LogMaster4Net实现应用程序日志的集中管理 SuperSocket 1.5 stable发布 SuperSocket 1.5 文档列表 SuperWebSocket 0.5发布 WebSocket4Net 0.5发布 SuperWebSocket发布0.1版本 用ILMerge合并Silverlight, WindowsPhone或Mono for Android的程序集 SuperSocket 1.4 SP2 发布了! 无需等待,SuperSocket 1.4 SP1 发布了! SuperSocket 1.4 stable正式发布 SuperSocket 1.4系列文档(18) 在Unix/Linux操作系统中通过Mono运行SuperSocket SuperSocket 1.4系列文档(17) 在Windows Azure中运行SuperSocket SuperSocket 1.4系列文档(16) 在SuperSocket中启用传输层加密(TLS/SSL) SuperSocket 1.4系列文档(15) 在SuperSocket中启用内置Flash/Silverlight策略服务器 SuperSocket 1.4系列文档(14) 多服务器实例和服务器实例之间的交互 SuperSocket 1.4系列文档(13) 连接过滤器(Connection Filter) SuperSocket 1.4系列文档(12) 命令过滤器(Command Filter)
在Mono/Linux上使用PerformanceCounter
江大渔 · 2012-07-30 · via 博客园 - 江大渔

前几天有一SuperSocket用户报在Linux上面性能日志的各个参数都是0, 由于SuperSocket的性能日志是通过PerformanceCounter实现的,于是我暂时怀疑Mono中的PerformanceCounter在Linux上不被支持。我自己也上Linux上跑了一下,确实有这个问题,performance counter的value都是0. 当时的获取PerformanceCounter的代码如下:

Process process = Process.GetCurrentProcess();

m_CpuUsagePC = new PerformanceCounter("Process", "% Processor Time", process.ProcessName);
m_ThreadCountPC = new PerformanceCounter("Process", "Thread Count", process.ProcessName);
m_WorkingSetPC = new PerformanceCounter("Process", "Working Set", process.ProcessName);

上面这段代码在Windows上是可以取到正确的值的。

Linux上真的不支持PerformanceCounter吗?遍寻网络,唯独只发现Mono网站上有一篇关于PerformanceCounter的权威文章:

http://www.mono-project.com/Mono_Performance_Counters, 上面并没有说PerformanceCounter在Linux上不被支持,网上其它地方也没有找到类似的陈述。

后来又有兄弟说Mono/Linux有个工具可以监控进程的性能,而且他已经在Linux上正常运行了。于是乎我看稍微看了下这个工具的源代码,发现他确实是用PerformanceCounter来获取性能参数的。然后我就尝试在Linux上使用PerformanceCounterCategory来获取intanceName。测试代码如下:

var category = new PerformanceCounterCategory("Process");

foreach(var instance in category.GetInstanceNames())
{
       Console.WriteLine(instance);    
}

运行结果令我大惊:

linuxpc

Linux上PerformanceCounter的instanceName是"ID/NAME"格式的,难怪取出来都是0。

于是我修改SuperSocket获取性能参数的代码为:

var isUnix = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX;
var instanceName = isUnix ? string.Format("{0}/{1}", process.Id, process.ProcessName) : process.ProcessName;

m_CpuUsagePC = new PerformanceCounter("Process", "% Processor Time", instanceName);
m_ThreadCountPC = new PerformanceCounter("Process", "Thread Count", instanceName);
m_WorkingSetPC = new PerformanceCounter("Process", "Working Set", instanceName);

在Linux上验证一下:

perflog

果然全都拿到了, 大功告成!