性能计数器可以跟踪字符串标识符所花费的时间吗?

发布于 2024-09-16 11:04:53 字数 473 浏览 2 评论 0 原文

我需要记录任务所花费的时间,建议我使用 Windows 性能计数器。

我需要记录解决给定数学问题所需的时间。 Solve 方法的第一行将启动秒表,最后一行将停止它。

当我记录解决问题所需的时间时,我需要记录时间以及 ProblemId(字符串)。

性能计数器可以这样使用记录数据吗?性能图会绘制时间和标识符吗?那么当我单击或将鼠标悬停在图表点上时,它会显示 ProblemID 吗?

提前致谢

public class MathProblem
{
    public string ProblemID;

    public void Solve()
    {
        StopWatch sw = StopWatch.StartNew();

        sw.Stop();
        //Log to performance counter with ProblemID
    }
}

I need to record the time taken by a task and it's been sugguested I use windows performance counters.

I need to record the time taken to solve a given MathProblem. The Solve methods first line will start the StopWatch and the last line will Stop it.

When I record the time taken to solve the problem I need to record the time along with the ProblemId (a string).

Can performance counters be use the record data like this? Will the perfmon graph plot the times along with a idenitifer? so when I click or hover over the graph point it will show the ProblemID?

Thanks in advance

public class MathProblem
{
    public string ProblemID;

    public void Solve()
    {
        StopWatch sw = StopWatch.StartNew();

        sw.Stop();
        //Log to performance counter with ProblemID
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩心态 2024-09-23 11:04:53

不可以,如果您想按问题 ID 分离计数器,则系统性能计数器不适用于这种情况。虽然实例化类别可以跟踪每个实例的单独计数器,并且显示屏可以显示每个类别和 _Total 的计数器(这是您在代码中创建的聚合类别,并确保将所有单独实例也添加到 _Total),但这是事实,该基础设施是为相当稳定的实例而设计的,最不稳定的例子是进程。如果您的 ProblemID 频繁出现和消失(即 ID 非常不稳定,每小时更改次数超过几次),那么在 perfmon 基础设施下跟踪这种波动性是行不通的。客户端拍摄实例名称的快照,然后查找该实例名称空间中的更改,因此如果名称不稳定,则所有客户端基本上不会跟踪任何内容:将跟踪捕获快照时恰好存在的一些 ProblemId,那么就没有什么了,因为快照实例将消失并且不会捕获新实例。

No, the system performance counters do not work for such a case if you want to separate counters per problem ID. While is true that an instanced category can track separate counters for each instance and the display can show the counters for each category and for _Total (which is an aggregated category you create in code and make sure you add all individual instances to _Total as well), this infrastructure is designed for fairly stable instances, the most volatile example being a process. If your ProblemIDs show up and vanish frequently (ie. the ID is very volatile, changing more often than a few times per hour) tracking this kind of volatility under the perfmon infrastructure is just not going to work. The clients take a snapshot of the instance names and then look for changes in that instance names space, so if the names are volatile, all clients will track basically nothing: will track some ProblemId that happen to exists at the moment the snapshot was captured, then nothing more since the snapshot instances will be gone and no new instance is captured.

说谎友 2024-09-23 11:04:53

如果这看起来像一个简单的方法,请原谅我,但对于它的价值(并且基于 Remus 的信息,perfmon 不会做你想要的事情),我总是通过将结果写入 CSV 文件。然后可以将其直接导入 Excel,Excel 将以最合适的方式分析数据并绘制图表。当然,任何其他电子表格程序都可以工作。

通过这种方式,您无需编写任何代码即可获得复杂的分析功能,而只需创建文本文件即可;除非你想在Excel中编写一些VBA来帮助处理数据。

我可能误解了您的要求,但您可以将结果附加到有效的日志文件(CSV 格式)中,并在每次运行程序时简单地添加到该文件中,这或多或少与创建性能计数器具有相同的效果数据点。

如果您想变得更复杂,您当然可以使用更复杂的解决方案将结果直接注入到 Excel 工作表中。

Forgive me if this seems like a simplistic approach, but for what it's worth (and based on Remus' information that perfmon will not do what you want), I've always approached this type of problem by writing results to a CSV file. This can then be imported directly into Excel and Excel will analyse and graph the data in whatever manner is most appropriate. Any other spreadsheet program will work, of course.

This way you get sophisticated analysis capabilities without having to write code for anything more than creating a text file; unless you want to write some VBA in Excel to help process the data.

I may have misunderstood your requirements but you could append your results to what is effectively a log file (in a CSV format) and simply add to that each time your program is run, which would have more or less the same effect as creating performance counter datapoints.

If you want to get more sophisticated, you can of course inject results directly into Excel sheets with a more complicated solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文