none
How to sync Perfmon writes to get smooth trace? RRS feed

  • Question

  • Hello 

    This is what I do (something like that)

    While(1) {

        for(i = 0; i < Count; i++)

            if(i%5) {

                Value = ReadRegister();

            }

            PerfSetULongLongCounterValue(Value);

            Sleep(100);

        }

    }

    So for every 5th iteration data is written out to the Perfmon. For all iterations we sleep 100 millisecond and I can vary it from the command line. In other words for some every 400 or so ms data is passed to Perfmon. What Perfmon does is show spikes it displays whenever it sees the data in the counter.
    I have seen when I write the data continuously without any lag then the trace is smooth and continuous. When one places the cursor on the trace we can see  Counter Name, Value and time stamp. In my case I see Counter Name and Value only. No Timestamp. And in the "Last" box I see many time 0 or ---------. I have three questions please
    1. I assume when it shows 0 it means the value was zero and -------- means no data found. Is that right?

    2. When it does not show Timestamp I guess it gets totally confused and inhibits the time display.

    3. How can I sync my input with Perfmon to make my race also contiguous? I am looking for a setting to tell Perfmon read the counter and sustain. In other words read and hold to that value till you get the next value withing some set time. In that way I get a smooth trace. How do I set that? Please advice. 

    Thanks in advance

    ananda

    Saturday, November 16, 2019 11:22 PM

All replies

  • Hi,

     
    1.Regarding "Last" and timestamp, I am not sure, when I add a lot of counters, it still displays the Last and timestamp.
    2.Looks like there is no such method, you can start collecting data manually, when you want to start. Or set perfmon to start monitoring at the specified time. Refer to Data Collector Set Properties.

    And Perfmon instance – the one on the left (similar to the "Play" button on a CD or DVD player) switches the display to live data, while the second (the "Skip Forward" button) leaves the display paused but updates the data to the present moment.

    Best regards,

    Jeffrey


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 18, 2019 9:50 AM
  • Thank you very much Jeffrey. I shall try out your suggestions and read about it. I shall keep this open for couple more days when I try out and will close later with any new learning. 

    Best regards

    ananda

    Monday, November 18, 2019 2:08 PM
  • Performance counters are collected and used by services and applications. For display issue that may exist, If they are installed incorrectly or with improper permissions, performance counters cannot be loaded, and services or applications cannot collect or interpret the data. Please refer to this.

    Best regards,

    Jeffrey


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 19, 2019 5:43 AM
  • Hi Jeffery

    After much expt I am back. I still have the fundamental problem of a perfect handshake. Let me explain my woes

    1. I run my app and assume it generates data in MB like 1, 2, 1, 4, 5, 3, 2,1 and then spurts up 25, 26, 24, 25, 23, 25 and then it falls down to 1, 2, 1, 4, 5, 3, 2,1
    2. So what you should in the live chart is a horizontal line parallel x-axis and then go straight up and again flat for a while and then fall down to its original state. Like a Butte. 
    3. Unfortunately when i do live chart I do get the Vertical Line going up. I do get the vertical line coming down. What is missing is the top horizontal line connecting the two vertical line which would make the butte top.
    4. However I save away all the data written to the counter for live chard in a CSV file. Using Perfmon I do a static plot using the CSV file and I get a 100% perfect Butte both the Vertical and Horizontal intact. 

    The same data plots so well statically but gets disjointed when live. That suggests the the writes I make to the counter and the reads Perfmon makes are not in sync. So this is what I am doing in my code 

    1. I get the data ==> DataIN
    2. I set the counter using PerfSetULongLongCounterValue() and I do it only once at the very beginning.
    3. Next I do LastData = DataIn and remember it
    4. Go get a fresh data = DataIN
    5. If DataIN == LastData: I dont do any write to the counter leave it ASIS
    6. If DataIN > LastData then I call PerfIncrementULongLongCounterValue( llabs(DataIN - LastData))
    7. Else I call PerfDecrementULongLongCounterValue(llabs(DataIN - LastData))
    8. In both the above cases only the diff between the old and new data its absolute value is passed along for the Decrements/Increment function. 
      The questions are
    1. Why does the same data fail live but comes so picture perfect in static plot? 
    2. The Vertical lines do come but for the horizontal lines the data goes missing. 
    3. When Perfmon reads a data from a counter what happens to the content of the counter. Is it erased to zero or the value is left there?
    4. I Googled and someone mentioned types of counters like cumulative counter, rate counter. I also saw many Manifest files where the value for aggregate is undefined or sum or avg etc ... for the kind of work I do what would be the best
    5. In my case Perfmon should read the counter plot it and in the next read if it does not data it should just keep going parallel with the X-axis it should not fall down to zero. To tell Perfmon to use the last known good data what should I do? 
    6. My Manifest entry looks like this. What have I done wrong? that might solve all my problems. 
    <!-- Total MBW -->
              <counter
                  id = "2"          
                  type = "perf_counter_large_delta"
                  uri = "xxxxxYYYYzzzz.TotalMBW"
                  name = "Total Memory Bandwidth MB/sec"
                  nameID = "2022"
                  description = "XXXXYYYY"
                  descriptionID = "2024"
                  aggregate = "undefined"
                  detailLevel = "standard"
                  defaultScale = "0">
              </counter>

    Very sorry wrote a long one but i am really frustrated please advice 

    regards

    ananda

    Tuesday, November 26, 2019 12:40 AM
  • Hi Jeffery,

    I solved the issue. However I have new issue this is simple to explain. Suppose you have a series of data like this

    1341234, 245356, 335356, 3563563 and 3563563 . You will notice the last data is a repeat. 

    Earlier when the data was a repeat I called PerfSetULongLongCounterValue("To the repeat value") and that was the cause of all breakage in the trace. Now When the data repeats I call PerfIncrementULongLongCounterValue(0) with 0 value. So I get a very smooth contiguous trace. The new problem is when the data is like this

    1341234, 245356, 335356, 3563563, 3563563,3563563 and same thing repeated ....

    So doing every time PerfIncrementULongLongCounterValue(0) with 0 value will work the first second time then on if we repeat that  it will put in zero in the counter :(. Question is what order of call do you make if you just keep getting the same value ...?? If some one can answer this it would make my life bit easy?

    thanks in advance

    Wednesday, November 27, 2019 1:33 AM
  • Hi Ananda,

    >Earlier when the data was a repeat I called PerfSetULongLongCounterValue("To the repeat value") and that was the cause of all breakage in the trace. Now When the data repeats I call PerfIncrementULongLongCounterValue(0) with 0 value. So I get a very smooth contiguous trace. The new problem is when the data is like this

    Would you mind sharing a screenshot to help us understand the 'breakage'? Based on my understanding, we should write the real value instead of the fake value. 

    And below is the code sample demonstrates the following performance counter concepts:

        1. Defining the metadata for simple performance counters
        2. Registration of performance counters.
        3. Providing performance counter data.

    PerfCounters Code Sample

    Regards & Fei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 27, 2019 9:05 AM
  • Hi Fei,

    Let me put the sample code that will be easy for you to see my issue.

    1. Assume I have done PerfCreateInstance()
    2. I get my first value say 56 I use PerfSetULongLongCounterValue(x, instance, ID, 56) and set it
    3. Then I feed it some random values and use either PerfIncrementULongLongCounterValue() or PerfDecrementULongLongCounterValue() depending upon whether the value is  > or < 
    4. Things are going fine I get a beautiful trace.
    5. Now assume I feed a a stream of fixed value say 89 so what I do is call PerfIncrementULongLongCounterValue(0) with a 0 increment. It works the very first time then on it does not seem to have the affect. 
    6. The trace falls to 0. I keep feeding 89 the and I keep doing PerfIncrementULongLongCounterValue(0) and the trace is at 0

    The question is what Perfmon API I should call when the data is constant? Could you kindly help me out please?

    My code looks like this somewhat 

    if(firstTime == true) {

        PerfSet();

    } else {

        if (CurrentData > LastData) PerfInc(Abs(CurrentData - LastData);

        if (CurrentData < LastData) PerfDec(Abs(CurrentData - LastData);

        if (CurrentData == LastData) PerfInc(0) OR PerfDec(0) OR PerfSet(CurrentData); I have tried all the three but all of them have no affect. The trace just falls to 0 and remains at 0. 

    }

    regards

    ananda

    PS: The example code you pointed out is in C and also appears to be using Obsoleted calls. It is 4 years old. I will give that a try anyway
    Wednesday, November 27, 2019 6:06 PM
  • Hi Ananda,

    >Now assume I feed a a stream of fixed value say 89 so what I do is call PerfIncrementULongLongCounterValue(0) with a 0 increment. It works the very first time then on it does not seem to have the affect. 

    Did you mean that the the line keep on the same value like figure below? If I understood correctly, this is expected behavior, we shouldn't change it by writing wrong values. 

    In-addition, the code sample provided in my previous post works well for me, I have tested it on Windows 10 Version 1909( OS Build 18363.476). Please feel free to let me know if you have any problems.

    Regards & Fei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 28, 2019 3:19 AM
  • Hi Fei,

    Yes the code sample you pointed out behaves perfectly and goes parallel to the X axis 
    when I give one constant value for every iterations of the While() loop. 
    However please note I am NOT using PerfSetCounterRefValue().

    So I did try using PerfSetCounterRefValue() gave me the ERROR_INVALID_PARAMETER 

    So could you give me code sample where they use PerfCreateInstance(), PerfSetULongLongCounterValue(), 
    PerfIncrementULongLongCounterValue() and PerfDevrementULongLongCounterValue()
    please? My values are all ULONGLONG

    Thanks & regards

    ananda



    Thursday, November 28, 2019 7:07 AM
  • MSFT provides a sample code here: https://github.com/microsoft/Windows-classic-samples/blob/master/Samples/Win7Samples/winbase/PerfCounters/Basic/CPP 
    This sample has one issue, I could not get PerfSetCounterRefValue() to work. It complained about ERROR_INVALID_PARAMETER (0x57). My code does not use it. 
    The other problem was using PerfSetULongLongCounterValue(), if I use that instead of PerfIncrementULongLongCounterValue() my trace breaks up do not get contiguous trace. 

    Ok finally I got it working. Is it the correct/official way? I don't know. In my case it works fine and faithfully traces the value fed to it. 

        ULONGLONG initValue = 0;
        ULONGLONG currentValue = 0;
        SYSTEMTIME sysTime;
        PerfSetULongLongCounterValue(HandleX, PerfInstance, 1, initValue);
        
        while (!_kbhit()) {
        currentValue = (rand() % 10)*100;
        GetSystemTime(&sysTime);
        PerfIncrementULongLongCounterValue(HandleX, PerfInstance, 1, currentValue);
        cout << sysTime.wMinute << ":" << sysTime.wSecond << " " << currentValue << "\n";
        Sleep(1000);
        }
        return 0;
    Tuesday, December 10, 2019 11:50 PM