有一个很好的 ASP.NET 性能计数器类别和一组计数器,可用于在性能测试运行期间跟踪请求队列。但是,我无法为未通过 IIS 托管的 WCF 服务找到类似的设置。我们的 WCF 服务使用 net-tcp 协议作为 Windows 服务运行。我了解到有几个绑定参数可以控制排队(Binding.MaxConnections和Binding.ListenBacklog)。这不是一个很容易的发现。所以我想知道,为什么要在 PerfMon 中跟踪这两个值?
我有一个具有一个Web角色的Azure云项目。部署后,Web角色端点几乎立即返回HTTP 400-错误请求。当我检查跟踪消息日志时,看到以下异常-
Type : System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Custom counters file view is out of memory.
Source : System
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Int32 CalculateMemory(Int32, Int32, Int32 ByRef)
HResult : -2146233079
Stack Trace : at System.Diagnostics.SharedPerformanceCounter.CalculateMemory(Int32 oldOffset, Int32 totalSize, Int32& alignmentAdjustment)
at System.Diagnostics.SharedPerformanceCounter.CreateCategory(CategoryEntry* lastCategoryPointer, Int32 instanceNameHashCode, String instanceName, PerformanceCounterInstanceLifetime lifetime)
at System.Diagnostics.SharedPerformanceCounter.GetCounter(String counterName, String instanceName, Boolean enableReuse, PerformanceCounterInstanceLifetime lifetime)
at System.Diagnostics.SharedPerformanceCounter..ctor(String catName, String counterName, String instanceName, PerformanceCounterInstanceLifetime lifetime)
at System.Diagnostics.PerformanceCounter.InitializeImpl()
at System.Diagnostics.PerformanceCounter..ctor(String categoryName, …Run Code Online (Sandbox Code Playgroud) perf stat -e <events> <command> 许多不同的事件通常会返回这样的输出
127.352.815.472 r53003c [23,76%]
65.712.112.871 r53019c [23,81%]
178.027.463.861 r53010e [23,88%]
162.854.142.303 r5302c2 [24,05%]
...
Run Code Online (Sandbox Code Playgroud)
百分比记录是什么意思?
我试图实现一个性能监视工具,我想监视内存和CPU等基本内容.
我试图通过使用性能计数器这样做,因为我相信这是在C#中查询进程性能的"正确"方法,这是一些示例代码:
class Program
{
static void Main(string[] args)
{
while (true)
{
var pcs = Process.GetProcesses()
.Select(p => new PerformanceCounter("Process", "Working Set - Private", p.ProcessName));
var sw = Stopwatch.StartNew();
foreach (var pc in pcs)
pc.NextValue();
Console.WriteLine($"Time taken to read {pcs.Count()} performance counters: {sw.ElapsedMilliseconds}ms");
Thread.Sleep(1000);
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以很明显〜在我的系统上查询进程大约12.5毫秒是不可接受的慢.它应该如何完成?
我已经在这篇文章中提到了一个相关问题:性能计数器读取访问速度非常慢 - 任务管理器如何做到这一点?
但我意识到我在那篇文章中并不够具体,并且问了错误的问题.我真的想知道我怎么能用性能计数器做我想做的事情,或者根本不可能做到这一点?
编辑1:
我正在运行Windows 10 Pro 1607 - Build 14393.479
我尝试通过简短的 C 代码片段来计算单个进程的 CPU 周期。MWE 是cpucycles.c。
\n\ncpucycles.c(主要基于手册页示例)
\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <unistd.h>\n#include <string.h>\n#include <sys/ioctl.h>\n#include <linux/perf_event.h>\n#include <asm/unistd.h>\n\nstatic long\nperf_event_open(struct perf_event_attr *hw_event, pid_t pid,\n int cpu, int group_fd, unsigned long flags)\n{\n int ret;\n ret = syscall(__NR_perf_event_open, hw_event, pid, cpu,\n group_fd, flags);\n return ret;\n}\n\nlong long\ncpu_cycles(pid_t pid, unsigned int microseconds)\n{\n struct perf_event_attr pe;\n long long count;\n int fd;\n\n memset(&pe, 0, sizeof(struct perf_event_attr));\n pe.type = PERF_TYPE_HARDWARE;\n pe.size = sizeof(struct perf_event_attr);\n pe.config = PERF_COUNT_HW_CPU_CYCLES;\n pe.disabled = 1;\n pe.exclude_kernel = 1;\n pe.exclude_hv …Run Code Online (Sandbox Code Playgroud) 在尝试查找字符串中一堆字符的频率时,为什么对 4 个不同的字符运行 string.count(character) 4 次会比使用 collections.Counter(string) 产生更快的执行时间(使用 time.time()) )?
背景:给定由字符串表示的一系列动作。有效移动为 R(右)、L(左)、U(上)和 D(下)。如果移动顺序带我回到原点,则返回 True。否则,返回 false。
# approach - 1 : iterate 4 times (3.9*10^-6 seconds)
def foo1(moves):
return moves.count('U') == moves.count('D') and moves.count('L') == moves.count('R')
# approach - 2 iterate once (3.9*10^-5 seconds)
def foo2(moves):
from collections import Counter
d = Counter(moves)
return d['R'] == d['L'] and d['U'] == d['D']
import time
start = time.time()
moves = "LDRRLRUULRLRLRLRLRLRLRLRLRLRL"
foo1(moves)
# foo2(moves)
end = time.time()
print("--- %s seconds ---" % (end …Run Code Online (Sandbox Code Playgroud) counter performancecounter count performance-testing python-3.x
我想使用 C# 检索系统的 cpu 使用情况。我读到我必须调用该方法NextValue(),然后等待大约一秒钟,然后NextValue()再次调用该方法。我想异步执行此操作,以免延迟我的 UI 线程,因此我编写了以下代码
public Task<float> GetCpuPerformanceAsync()
{
return Task.Run(() =>
{
CpuPerformance.NextValue();
Task.Delay(1000);
return CpuPerformance.NextValue();
});
}
Run Code Online (Sandbox Code Playgroud)
这是声明CpuPerformance
CpuPerformance = new PerformanceCounter("Processor Information", "% Processor Time", "_Total");
Run Code Online (Sandbox Code Playgroud)
第一次调用异步方法(如上所示)时,它会返回实际的 cpu 使用情况,但几秒钟后再次调用它,它只显示 0 或 100,这与我的任务管理器中显示的使用情况不一致
有人可以帮我解决这个问题吗?
我有一个Intel(R) Core(TM) i7-4720HQ CPU @ 2.60GHz( Haswell) 处理器。AFAIK计算DRAM (即)数据读取访问mem_load_uops_retired.l3_miss的数量。顾名思义,计算针对 DRAM 的数据读取次数。因此,这两个事件看起来是等价的(或者至少几乎相同)。但根据以下基准,前一个事件比后者发生的频率要低得多:demandnon-prefetchoffcore_response.demand_data_rd.l3_miss.local_dramdemand
1) 在循环中初始化 1000 个元素的全局数组C:
Performance counter stats for '/home/ahmad/Simple Progs/loop':
1,363 mem_load_uops_retired.l3_miss
1,543 offcore_response.demand_data_rd.l3_miss.local_dram
0.000749574 seconds time elapsed
0.000778000 seconds user
0.000000000 seconds sys
Run Code Online (Sandbox Code Playgroud)
2)在Evince中打开PDF文档:
Performance counter stats for '/opt/evince-3.28.4/bin/evince':
936,152 mem_load_uops_retired.l3_miss
1,853,998 offcore_response.demand_data_rd.l3_miss.local_dram
4.346408203 seconds time elapsed
1.644826000 seconds user
0.103411000 seconds sys
Run Code Online (Sandbox Code Playgroud)
3)运行Wireshark 5秒:
Performance counter stats …Run Code Online (Sandbox Code Playgroud) 我使用 windows-sys crate 编写了一个 Rust 程序,并收集所提供的查询的性能计数器值。我使用微软团队提供的示例程序(此处)。
该程序能够检索性能计数器值。然而,当我检查进程资源管理器以监视占用空间时,我注意到下面的私有字节图表。由于私有字节呈线性增加,因此表明存在内存泄漏。
我无法使用 Windbg,因为 Windbg 无法连接到 Microsoft 符号服务器。因此,我决定通过注释代码并检查私有字节来手动识别问题的根源。相关代码如下——
fn execute_perf_query(input_query: &String,perf_query: &mut Vec<PerfEntryForMongo>)->f64{
log::info!("Performing counter for {:?}", input_query);
let hostname = gethostname().into_string();
unsafe {
let mut query = 0;
let p: *const u16 = std::ptr::null();
PdhOpenQueryW(p, 0 as usize, &mut query);
}
return -1.0;
//println!("Returning Now");
}
Run Code Online (Sandbox Code Playgroud)
请注意,目前我已注释掉与PdhAddCounterW、 、相关的代码PdhCollectQueryData,PdhGetFormattedCounterValue以了解每个 Windows 调用对私有字节的影响。
Vec<PerfEntryForMongo>每次迭代后都会被清除,因此不会导致内存泄漏。hostname是一个字符串,将在堆上分配,但是一旦范围结束,内存将被释放。
我正在使用原始指针,但它是一个 NULL 指针,不应在堆中分配任何内存。我需要了解什么导致内存泄漏。我已经介绍了与引用、借用和不安全 Rust 相关的章节,但我无法确定内存泄漏的原因。
c# ×4
perf ×3
wcf ×2
windows ×2
.net ×1
asynchronous ×1
azure ×1
c ×1
count ×1
counter ×1
cpu-cycles ×1
cpu-usage ×1
intel ×1
intel-pmu ×1
linux ×1
perfmon ×1
performance ×1
python-3.x ×1
rust ×1