Loading ...
Sorry, an error occurred while loading the content.

How to check memory usage in Windows with Perl?

Expand Messages
  • Wallace Lai
    Hi, All, Can I use Perl to check the amount of memory used by certain app, like NotePad and Internet Explorer? And can I use Perl to check the amount of free
    Message 1 of 6 , Oct 4, 2006
    • 0 Attachment
      Hi, All,

      Can I use Perl to check the amount of memory used by
      certain app, like NotePad and Internet Explorer? And
      can I use Perl to check the amount of free memory?

      I am using it on Microsoft Windows.

      Thanks
      Wallace Lai

      __________________________________________________
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail.yahoo.com
    • Martin McGrath
      Please post only Win32::GuiTest questions to this list, not general Perl questions. Wallace Lai wrote:
      Message 2 of 6 , Oct 5, 2006
      • 0 Attachment
        Please post only Win32::GuiTest questions to this list, not general Perl questions.

        Wallace Lai <wallace_g_lai@...> wrote: Hi, All,

        Can I use Perl to check the amount of memory used by
        certain app, like NotePad and Internet Explorer? And
        can I use Perl to check the amount of free memory?

        I am using it on Microsoft Windows.

        Thanks
        Wallace Lai

        __________________________________________________
        Do You Yahoo!?
        Tired of spam? Yahoo! Mail has the best spam protection around
        http://mail.yahoo.com






        ---------------------------------
        Now you can scan emails quickly with a reading pane. Get the new Yahoo! Mail.

        [Non-text portions of this message have been removed]
      • kapil sharma
        Hi, I hope this helps. Regards, Kapil #The following API checks the following #CPU Time which is equal to KETNEL MODE + USER MODE TIME #PEAK MEMORY For details
        Message 3 of 6 , Oct 5, 2006
        • 0 Attachment
          Hi,
          I hope this helps.

          Regards,
          Kapil

          #The following API checks the following
          #CPU Time which is equal to KETNEL MODE + USER MODE
          TIME
          #PEAK MEMORY

          For details check www.perlmonks.com

          sub DumpPerformanceData
          {
          $OsName = Win_OS_Type();

          $ExeNameInTaskManager = "Your Executable Name goes
          here"; #If you have Win2000

          if ( lc($OsName) eq lc("XP") )
          {
          $ExeNameInTaskManager = "Your Executable Name goes
          here"; #If you have WinXP
          }


          foreach my $Proc ( sort {lc $a->{Name} cmp lc
          $b->{Name}} in( $WMI->InstancesOf( "Win32_Process" ) )
          )
          {
          $numberofProcesses++;
          $|=1;
          $TempProcessID =0;
          $TempProcessID = $Proc->{ProcessID};
          $KernelModeTime = 0;
          $UserModeTime = 0;

          if (lc($Proc->{Name}) eq lc($ExeNameInTaskManager))
          #Checking if the PID of the Process = PID of the your
          exe
          {
          $PID = $Proc->{ProcessID};

          $KernelModeTime = $Proc->{KernelModeTime};
          $UserModeTime = $Proc->{UserModeTime};
          $PeakMemoryUsage = ($Proc->{PeakWorkingSetSize}) /
          1024;

          $TotalCPUTime = $UserModeTime + $KernelModeTime;
          $TotalCPUTime = $TotalCPUTime / 10000000;

          #Defining and opening the main log file
          if($ARGV[3] == 1)
          {
          $PerformanceLogFile =
          $ARGV[1]."\\"."Performancedata.log";
          }
          else
          {
          $PerformanceLogFile =
          $ARGV[1]."\\"."Performancedata_new.log";
          }

          open PerformanceLogFileHandle,
          ">>$PerformanceLogFile" or warn "Can't open the log
          file in automation: $PerformanceLogFile : $!\n";

          print PerformanceLogFileHandle "$ARGV[0]\n";
          print PerformanceLogFileHandle "Total CPU Time =
          $TotalCPUTime\n";
          print PerformanceLogFileHandle "PeakMemoryUsage =
          $PeakMemoryUsage\n";
          close(PerformanceLogFileHandle);
          return 1;
          }

          } #End of "foreach my $Proc ( sort {lc $a->{Name} cmp
          lc $b->{Name}} in( $WMI->InstancesOf( "Win32_Process"
          ) ) )"


          }


          ###################################

          --- Wallace Lai <wallace_g_lai@...> wrote:

          > Hi, All,
          >
          > Can I use Perl to check the amount of memory used by
          > certain app, like NotePad and Internet Explorer?
          > And
          > can I use Perl to check the amount of free memory?
          >
          > I am using it on Microsoft Windows.
          >
          > Thanks
          > Wallace Lai
          >
          > __________________________________________________
          > Do You Yahoo!?
          > Tired of spam? Yahoo! Mail has the best spam
          > protection around
          > http://mail.yahoo.com
          >
          >
          >
          >



          The information in this message is confidential and may be legally
          privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error.


          __________________________________________________
          Do You Yahoo!?
          Tired of spam? Yahoo! Mail has the best spam protection around
          http://mail.yahoo.com
        • evenprime
          # Don t think you can do that with gui-test, unless I missed somthing in spy--. Might be overkill to use the gui-test module. Might want to stick with wmi
          Message 4 of 6 , Oct 8, 2006
          • 0 Attachment
            # Don't think you can do that with gui-test, unless I missed somthing
            in spy--. Might be overkill to use the gui-test module. Might want
            to stick with wmi query via OLE:

            use Win32::OLE('in');
            use constant returnit => 0x10;
            use constant forwardit => 0x20;

            my $wmi = Win32::OLE->GetObject("winmgmts:\\\\.\\root\\CIMV2")
            or next;
            my $col =
            $wmi->ExecQuery( "SELECT * FROM Win32_Process", "WQL",
            returnit | forwardit );

            foreach my $item ( in $col) {
            $mem = $item->{WorkingSetSize} / 1024;
            $name = $item->{Caption};
            print "App: $name\n";
            print "Memory: $mem K\n\n";
            }
          • Wallace Lai
            Hi, evenprime, Thanks. This is great help. Thanks Wallace ... __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail
            Message 5 of 6 , Oct 11, 2006
            • 0 Attachment
              Hi, evenprime,

              Thanks. This is great help.

              Thanks
              Wallace


              --- evenprime <evenprime@...> wrote:

              > # Don't think you can do that with gui-test, unless
              > I missed somthing
              > in spy--. Might be overkill to use the gui-test
              > module. Might want
              > to stick with wmi query via OLE:
              >
              > use Win32::OLE('in');
              > use constant returnit => 0x10;
              > use constant forwardit => 0x20;
              >
              > my $wmi =
              > Win32::OLE->GetObject("winmgmts:\\\\.\\root\\CIMV2")
              >
              > or next;
              > my $col =
              > $wmi->ExecQuery( "SELECT * FROM Win32_Process",
              > "WQL",
              > returnit | forwardit );
              >
              > foreach my $item ( in $col) {
              > $mem = $item->{WorkingSetSize} / 1024;
              > $name = $item->{Caption};
              > print "App: $name\n";
              > print "Memory: $mem K\n\n";
              > }
              >
              >
              >
              >


              __________________________________________________
              Do You Yahoo!?
              Tired of spam? Yahoo! Mail has the best spam protection around
              http://mail.yahoo.com
            • stuart arnold
              check out ScriptomaticV2.hta from microsoft. its free and does a lot of object manipulation per object in perl, and other languages. modifiable as well.
              Message 6 of 6 , Oct 12, 2006
              • 0 Attachment
                check out "ScriptomaticV2.hta" from microsoft. its free and does a lot of
                object manipulation "per object" in perl, and other languages. modifiable as
                well.

                -----Original Message-----
                From: perlguitest@yahoogroups.com [mailto:perlguitest@yahoogroups.com] On
                Behalf Of kapil sharma
                Sent: Friday, October 06, 2006 1:13 AM
                To: perlguitest@yahoogroups.com
                Subject: Re: [perlguitest] How to check memory usage in Windows with Perl?



                Hi,
                I hope this helps.

                Regards,
                Kapil

                #The following API checks the following
                #CPU Time which is equal to KETNEL MODE + USER MODE
                TIME
                #PEAK MEMORY

                For details check www.perlmonks.com

                sub DumpPerformanceData
                {
                $OsName = Win_OS_Type();

                $ExeNameInTaskManager = "Your Executable Name goes
                here"; #If you have Win2000

                if ( lc($OsName) eq lc("XP") )
                {
                $ExeNameInTaskManager = "Your Executable Name goes
                here"; #If you have WinXP
                }

                foreach my $Proc ( sort {lc $a->{Name} cmp lc
                $b->{Name}} in( $WMI->InstancesOf( "Win32_Process" ) )
                )
                {
                $numberofProcesses++;
                $|=1;
                $TempProcessID =0;
                $TempProcessID = $Proc->{ProcessID};
                $KernelModeTime = 0;
                $UserModeTime = 0;

                if (lc($Proc->{Name}) eq lc($ExeNameInTaskManager))
                #Checking if the PID of the Process = PID of the your
                exe
                {
                $PID = $Proc->{ProcessID};

                $KernelModeTime = $Proc->{KernelModeTime};
                $UserModeTime = $Proc->{UserModeTime};
                $PeakMemoryUsage = ($Proc->{PeakWorkingSetSize}) /
                1024;

                $TotalCPUTime = $UserModeTime + $KernelModeTime;
                $TotalCPUTime = $TotalCPUTime / 10000000;

                #Defining and opening the main log file
                if($ARGV[3] == 1)
                {
                $PerformanceLogFile =
                $ARGV[1]."\\"."Performancedata.log";
                }
                else
                {
                $PerformanceLogFile =
                $ARGV[1]."\\"."Performancedata_new.log";
                }

                open PerformanceLogFileHandle,
                ">>$PerformanceLogFile" or warn "Can't open the log
                file in automation: $PerformanceLogFile : $!\n";

                print PerformanceLogFileHandle "$ARGV[0]\n";
                print PerformanceLogFileHandle "Total CPU Time =
                $TotalCPUTime\n";
                print PerformanceLogFileHandle "PeakMemoryUsage =
                $PeakMemoryUsage\n";
                close(PerformanceLogFileHandle);
                return 1;
                }

                } #End of "foreach my $Proc ( sort {lc $a->{Name} cmp
                lc $b->{Name}} in( $WMI->InstancesOf( "Win32_Process"
                ) ) )"

                }

                ###################################

                --- Wallace Lai <wallace_g_lai@ <mailto:wallace_g_lai%40yahoo.com>
                yahoo.com> wrote:

                > Hi, All,
                >
                > Can I use Perl to check the amount of memory used by
                > certain app, like NotePad and Internet Explorer?
                > And
                > can I use Perl to check the amount of free memory?
                >
                > I am using it on Microsoft Windows.
                >
                > Thanks
                > Wallace Lai
                >
                > __________________________________________________
                > Do You Yahoo!?
                > Tired of spam? Yahoo! Mail has the best spam
                > protection around
                > http://mail. <http://mail.yahoo.com> yahoo.com
                >
                >
                >
                >

                The information in this message is confidential and may be legally
                privileged. It is intended solely for the addressee. Access to this message
                by anyone else is unauthorized. If you are not the intended recipient, any
                disclosure, copying, or distribution of the message, or any action or
                omission taken by you in reliance on it, is prohibited and may be unlawful.
                Please immediately contact the sender if you have received this message in
                error.

                __________________________________________________
                Do You Yahoo!?
                Tired of spam? Yahoo! Mail has the best spam protection around
                http://mail. <http://mail.yahoo.com> yahoo.com







                [Non-text portions of this message have been removed]
              Your message has been successfully submitted and would be delivered to recipients shortly.