【问题标题】:VS Load Test and 'Total Bytes Sent' Performance Counter?VS 负载测试和“发送的总字节数”性能计数器?
【发布时间】:2011-09-22 07:57:17
【问题描述】:

我有一个 WCF 服务的负载测试,我们正在尝试不同的压缩库和配置,我们需要测量测试期间发送的 mb 总数。是否有衡量相对流量 pr 的性能计数器。测试。如果是这样,我如何将它添加到我的负载测试中 - 似乎只有一小部分性能计数器是可见的 - 例如在“Web 服务”类别下,我在 VS 负载测试中没有看到性能计数器“接收的总字节数”,但我可以在 PerfMon 中找到它。

谢谢

【问题讨论】:

  • 嗯,估计没有多少人需要这些信息......

标签: benchmarking load-testing perfmon performancecounter


【解决方案1】:

在负载测试中展开计数器集>展开适用>右键单击计数器集>添加计数器

您可以像这样实现自己的自定义性能计数器:

using System;
using System.Diagnostics;
using System.Net.NetworkInformation;

namespace PerfCounter
{
class PerfCounter
{
    private const String categoryName = "Custom category";
    private const String counterName = "Total bytes received";
    private const String categoryHelp = "A category for custom performance counters";
    private const String counterHelp = "Total bytes received on network interface";
    private const String lanName = "Local Area Connection"; // change this to match your network connection
    private  const int sampleRateInMillis = 1000;
    private const int numberofSamples = 200000;

    private static NetworkInterface lan = null;
    private static PerformanceCounter perfCounter;
    private static long initialReceivedBytes;

    static void Main(string[] args)
    {
        setupLAN();
        setupCategory();
        createCounters();
        updatePerfCounters();
    }

    private static void setupCategory()
    {
        if (!PerformanceCounterCategory.Exists(categoryName))
        {
            CounterCreationDataCollection counterCreationDataCollection = new CounterCreationDataCollection();
            CounterCreationData totalBytesReceived = new CounterCreationData();
            totalBytesReceived.CounterType = PerformanceCounterType.NumberOfItems64;
            totalBytesReceived.CounterName = counterName;
            counterCreationDataCollection.Add(totalBytesReceived);
            PerformanceCounterCategory.Create(categoryName, categoryHelp, PerformanceCounterCategoryType.MultiInstance, counterCreationDataCollection);
        }
        else
            Console.WriteLine("Category {0} exists", categoryName);
    }

    private static void createCounters()
    {
        perfCounter = new PerformanceCounter(categoryName, counterName, false);
        perfCounter.RawValue = getTotalBytesReceived();
    }

    private static long getTotalBytesReceived()
    {
        return lan.GetIPv4Statistics().BytesReceived;
    }

    private static void setupLAN()
    {
        NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
        foreach (NetworkInterface networkInterface in interfaces)
        {
            if (networkInterface.Name.Equals(lanName))
                lan = networkInterface;
        }
        initialReceivedBytes = lan.GetIPv4Statistics().BytesReceived;
    }

    private static void updatePerfCounters()
    {
        for (int i = 0; i < numberofSamples; i++)
        {
            perfCounter.RawValue = getTotalBytesReceived();
            Console.WriteLine("received: {0} bytes", perfCounter.RawValue - initialReceivedBytes);
            System.Threading.Thread.Sleep(sampleRateInMillis);
        }
    }
}
}

【讨论】:

    猜你喜欢
    • 2017-04-08
    • 1970-01-01
    • 2018-05-18
    • 2013-01-17
    • 2017-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    相关资源
    最近更新 更多