VS 负载测试和“发送的总字节数”性能计数器?

发布于 2024-12-06 07:18:48 字数 201 浏览 0 评论 0原文

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

谢谢

I have a load test for a WCF service, where we are trying out different compression libraries and configurations and we need to measure the total number of mb sent during a test. Is there a performance counter that measure the relative trafic pr. test. If so, how do I add it to my load test - it seems that only a fraction of the performance counters are visible - E.g. under the category "Web Service", i don't see the performance counter "Total Bytes Received" in VS Load test, but I can find it in PerfMon.

Thanks

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

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

发布评论

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

评论(1

流绪微梦 2024-12-13 07:18:48

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

您可以实现自己的自定义性能计数器,如下所示:

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);
        }
    }
}
}

In the load test expand Counter Sets > Expand applicable > Right Click on Counter Sets > Add Counters

You can implement your own custom performance counter like so:

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