LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

LabWindows 8.5 - High CPU Consumption - Performance controls

I am using LabWindows CVI 8.5, under Microsoft Windows XP SP2.

I have an application that the users can dynamically create so many controls (gauges, graphs, tanks...) as they want. The controls refresh rate is 10Hz.

I can identify in windows task manager that each control that the user creates, improves from 2% to 4% of the application CPU consumption.

It is a lot of CPU consumption for a simple control. How can I solve this problem? Is there any application performance tip that I can try?

Thank you in advance.
Gustavo


Message Edited by Oliveira on 03-24-2008 08:31 AM
0 Kudos
Message 1 of 9
(4,993 Views)
I would like to add that if I use some CWGraph object throught ActiveX, it improves from 6 to 10% in CPU consumption

I am using an P4 2.93 GHz, 512MB RAM.
0 Kudos
Message 2 of 9
(4,977 Views)
I note that only the Measurement Studio ActiveX controls do the CPU consumption goes high. Using the labwindows defaults controls is works well.

Is there any solution for this problem? Could someone from NI help?

Thank you.
0 Kudos
Message 3 of 9
(4,949 Views)
Hi Oliveira,

I'm a little confused as to what your actual issue is. From what I can gather from you posts, if you programmatically create CVI-native UI controls, the CPU jumps up by 2-4%? And when you programmatically create the Measurment Studio ActiveX controls on the CVI UI, the CPU jumps up by 6-10%? Are those correct statements? 

If those statements are correct, these are the questions I have
1) Why does this small jump in CPU really affect your application? Those jumps are not that big. I would be concerned if as soon as you created a UI control, that the CPU was being hogged and around 100% usage. 
2) Does the CPU stay at this new CPU usage or after you create the controls and move onto another statement does it go away?
3) Are you thinking there is some memory leak and that's why you are monitoring the CPU in task manager?

I'm really not clear on what your issue is and why its causing a problem. Maybe I'm just not understanding your problem. I mean, there is a difference between the sets of controls in that the Measurement Studio controls are ActiveX controls while the CVI controls are not. I mean it seems as if you are comparing 2-4% to 6-10% which isn't that large. Especially since CVI UI controls are native to CVI and when adding an ActiveX control to a CVI UI, we have to create a ActiveX container that hosts the ActiveX controls.

Anyway, perhaps you can clarify more on the problem.

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 4 of 9
(4,927 Views)
Hi Jonathan!

I will answers your questions in order to elucidate you, so I think it will be easy to help me.

1) Why does this small jump in CPU really affect your application? Those jumps are not that big. I would be concerned if as soon as you created a UI control, that the CPU was being hogged and around 100% usage. 
This small jump does not affect my application if I monitor only one of the sensors that my system has. Today, if I try to monitor 8 sensors at the same time, my application CPU consumption goes to 99%. The historic of the Measurement Studio Activex Graphs contains 800 points each one. (remember that the problem is not the memory usage but the cpu consumption). If I monitor the same parameters using CVI UI controls, the CPU consumption stays under 10%.

2) Does the CPU stay at this new CPU usage or after you create the controls and move onto another statement does it go away?
The CPU usage moves high when I create the activex controls, and stays high, it only raises when I delete the activex control.

3) Are you thinking there is some memory leak and that's why you are monitoring the CPU in task manager?
I found some memory leak problems in my application. I solve the problem discarding activex handles.

I hope to help you to help me 🙂

Any idea in what is it occurring?
Thank you in advance.


Message Edited by Oliveira on 03-26-2008 12:14 PM
0 Kudos
Message 5 of 9
(4,908 Views)
Hi Oliveira,

I wouldn't expect creating those ActiveX controls to force the CPU usage up to 100%. However, I am still unclear if the CPU usage stays at 100% after you create those controls and move on in your application. If you can post some small example that demonstrates the behavior, I could look at it and see what the problem might be.

Also, does it matter which ActiveX controls you create?
What version of those ActiveX controls do you have installed? (check the version property on the cwui.ocx file found in the system32 directory)

Best Regarsds,
Jonathan N.
National Instruments
0 Kudos
Message 6 of 9
(4,895 Views)
Hi Jonathan!

The version of the control that I am using in the application is 8.1.11 Release (377) (602).

The CPU consumption stays high after I create them and move them to my application. The creation of the controls is dynamic. I will post here part of the code that prints the data.

The code:

void Util_DrawData ( TControl *p_ptCtlControlList, ds_param_value *p_dpvSampleContents,
    double p_dblTimeToPlot, ListType p_lstParameterListCode, double p_dblTimeStamp )  {
......
        if (plot) {
                 // Pointer to the right function
                (*p_ptCtlControlList->pShowData)(p_ptCtlControlList, p_dblTimeToPlot, p_dblTimeStamp,
                    &g_ptDPVParameterValue[0], g_ptDPTParameterType[0]);
       }
       ....
    return;
}

// The function which I use in this case (in order to print data into an activex control)
void Util_StripChart(TControl * p_ptControlList, double p_dblTimeToPlot, double p_dblTimeStamp, 
    ds_param_value *p_dpvParameterValue, ds_param_type p_dptParameterType) {

        CAObjHandle m_objActiveXHandle;
        CWUIControlsLibObj_CWAxes AxesHandle;
        CWUIControlsLibObj_CWAxis AxisHandle;
        double time = 0;
       
        GetObjHandleFromActiveXCtrl ( p_ptControlList->panelID, p_ptControlList->controlID,
                                        &m_objActiveXHandle);

        CWUIControlsLib_Get_DCWGraphProperty (m_objActiveXHandle, NULL, CWUIControlsLib__DCWGraphAxes,
                    CAVT_OBJHANDLE, &AxesHandle);
        CWUIControlsLib_CWAxesItem (AxesHandle, NULL, CA_VariantInt(1), &AxisHandle);
        CWUIControlsLib_GetCWAxisProperty (AxisHandle, NULL, CWUIControlsLib_CWAxisMaximum,
                    CAVT_DOUBLE, &time);
               
        if ( p_dblTimeToPlot >= time || time >= 1) {
       
            g_blnControlTime = 0;
            Util_TimeStampToPlotTime ((float) p_dblTimeStamp);  //Function that only adjusts time
            CWUIControlsLib_CWAxisSetMinMax (AxisHandle, NULL, CA_VariantDouble(g_dblGraphInitTime),
                 CA_VariantDouble(g_dblGraphEndTime)); 
        }   

        Util_getSimpleGraphValuetoPrint ( p_ptControlList, g_ptDPVParameterValue, g_ptDPTParameterType[0],p_dblTimeToPlot,
             p_ptControlList->numberOfTraces, m_objActiveXHandle );
   
        CA_DiscardObjHandle(AxisHandle);
        CA_DiscardObjHandle(AxesHandle);
        CA_DiscardObjHandle(m_objActiveXHandle);

        return;
}


void Util_getSimpleGraphValuetoPrint ( TControl *p_ptControlList, ds_param_value *p_dpvParameterValue,
    ds_param_type p_dptParameterType, double p_dblTimeToPlot, int p_intNumberOfTraces, CAObjHandle p_objActiveXHandle ) {

    // ActiveX variables controls
    VARIANT     m_varDataToPlotY;

    switch ( p_dptParameterType ) {
        case PT_FLOAT:            CA_VariantSet1DArray ( &m_varDataToPlotY, CAVT_FLOAT, p_intNumberOfTraces, &p_dpvParameterValue->pvflt );
            break;
        case PT_DOUBLE:            CA_VariantSet1DArray ( &m_varDataToPlotY, CAVT_DOUBLE, p_intNumberOfTraces, &p_dpvParameterValue->pvdbl );
            break;                               
    }

    CWUIControlsLib__DCWGraphChartXvsY( p_objActiveXHandle, NULL, CA_VariantDouble (p_dblTimeToPlot), m_varDataToPlotY, CA_VariantBool(0) );

    if ( p_dpvParameterValue->pvdbl >= p_ptControlList->list->max_range*0.95 || p_dpvParameterValue->pvdbl <= p_ptControlList->list->min_range*1.05 ) {
       
        int max, min;
        CWUIControlsLibObj_CWAxes AxesHandle;
        CWUIControlsLibObj_CWAxis AxisHandle;
   
        if (p_dpvParameterValue->pvdbl >= p_ptControlList->list->max_range ) {

            max = p_ptControlList->list->max_range *0.2;
            p_ptControlList->list->min_range = p_ptControlList->list->min_range + max;
            p_ptControlList->list->max_range = p_ptControlList->list->max_range + max;
                       
        }
            else {
                min = p_ptControlList->list->min_range *0.2;
                p_ptControlList->list->max_range = p_ptControlList->list->max_range -min;
                p_ptControlList->list->min_range = p_ptControlList->list->min_range - min;

            }
                 
        CWUIControlsLib_Get_DCWGraphProperty (p_objActiveXHandle, NULL, CWUIControlsLib__DCWGraphAxes,
            CAVT_OBJHANDLE, &AxesHandle);
        CWUIControlsLib_CWAxesItem (AxesHandle, NULL, CA_VariantInt(2), &AxisHandle);

        CWUIControlsLib_SetCWAxisProperty (AxisHandle,NULL,CWUIControlsLib_CWAxisMaximum,
            CAVT_VARIANT,CA_VariantInt(p_ptControlList->list->max_range));
        CWUIControlsLib_SetCWAxisProperty (AxisHandle,NULL,CWUIControlsLib_CWAxisMinimum,
            CAVT_VARIANT,CA_VariantInt(p_ptControlList->list->min_range));

        CA_DiscardObjHandle(AxisHandle);
        CA_DiscardObjHandle(AxesHandle);
    }
   
    CA_VariantClear (&m_varDataToPlotY);
    return;
}


0 Kudos
Message 7 of 9
(4,882 Views)
Hi Oliveira,

Just by looking at the code I don't see anything wrong but again, I would need an working example to be sure on that. Please create a watered down example that I can run that demonstrates the behavior. This would be the fastest way for me to let you know what's going on and if its an issue.

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 8 of 9
(4,861 Views)
Jonathan,

I solve the problem. I store all graph handles, which are necessary to my application, in memory.

So, now, it is not any more necessary to get them every time when I try to update the graph. I reduced the number of callings to cwgraphs function in +-60%. And, then, the cpu consumption is in normal standards.

Thank you for your help.
Gustavo
0 Kudos
Message 9 of 9
(4,701 Views)