none
Increase in CPU Utilization with referencing a dll RRS feed

  • Question

  • Hi,

    I am working on a legacy Winforms application that includes many user controls on
    .NET 2.0 Compact Framework embedded in WinCE 6.0 OS. As part of code
    refactoring, I added a dll named Utilities and reference the dll as needed by
    the main app and user controls. Within the Utilities.dll I added a static class
    containing a structure that holds 2 integers, one long and one boolean. The
    structure is used to hold the realtime data packet information. The realtime
    data is used extensively for drawing various graphs on the Graphics at an
    interval of every 50ms.

    With the addition of the Utilities dll I am seeing an increase in the CPU
    Utilization ~8%. Can anyone please let know why there is an increase in CPU
    Usage with just adding a structure in a .dll and referencing it. Within the
    Build project properties I have checked the Optimize code option. Are there any
    other relevant project settings that need to be done?

    Thanks,

    Chethana


    Monday, January 18, 2016 10:03 AM

All replies

  • The increase in CPU utilitisation is not going to be anything to do with just referencing the DLL, but with how the static class within it is being used!

    i.e. the code that updates this structure with packet information and/or the code that updates the graphs every 50ms (which sounds like a very short time interval for updating  a GUI) is going to be the cause of this.

    You may need to trace/profile that code through a bit more and possibly post some code samples if you can narrow it down.


    • Edited by RJP1973 Monday, January 18, 2016 11:20 AM grammar correction
    Monday, January 18, 2016 11:20 AM
  • Actually, off the top of my head, using a static class like this - where you have one system constantly trying to update static value and another system constantly trying to read them - sounds like a real cause of contention.

    It's difficult to give advice without knowing more details (and I'm not really an expert on this), but this is sounding like a classic example of where you would use a Queue of 'data packet' structures. Then you would have one thread adding timestamped data-packets to one end of the queue, and another thread reading off values and updating the graphs.

    Unfortunately .NET 2 Compact probably doesn't have a lot of juicy technologies that would make this kind of asynchronous work easier, but I'm sure it still has Threads e.t.c.

    Monday, January 18, 2016 12:11 PM
  • Thanks for the update. Drawing the 3 graphs as and when data is received from the serial communication(i.e every 50ms) was already existing. Previously the data was all cluttered, now I added into structure within a static class for better code readability and maintainability which is causing an increase in CPU Usage. Let me check if it is possible to post the code snippet on the forum.
    Tuesday, January 19, 2016 3:57 AM
  • Hi Chethana,

    If you've got shared data, Whether that's exposed through static classes, a singleton, whatever, isn't terribly important. If you don't need the shared data , I expect you wouldn't have a static class anyway. So if you don't use that static class? How about the result?

    Please use this  insert code button to provide code.

    In addition, I also suggest you run a some third-party performance profilers such as:

    1. JetBrains DotTrace
    2. ANTS Performance Profiler

    And see where you spend most of the time. If you want to profile specific bottlenecks you can try using Stopwatch to test which object cost much time.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, January 20, 2016 9:13 AM