MacOS Lion Number of CPUs always 0

Bug #869269 reported by Andreas Xenos
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OCS Inventory: Unified Unix Agent
Fix Released
High
mortheres

Bug Description

In the Ocsinventory::Agent::Backend::OS::MacOS::CPU.pm module the number of processors is extracted with this line:
my $processorn = $h->{'Number Of Processors'} || $h->{'Number Of CPUs'};

whereas in MacOS X 10.7 Lion the system_profiler returns the number as: "Number of Processors: 1" (case sensitive).
I added another option in this line of code in case the agent runs on 10.7 .

my $processorn = $h->{'Number Of Processors'} || $h->{'Number Of CPUs'} || $h->{'Number of Processors'}; # 10.7

affects: ocsinventory-deploy-tool → ocsinventory-unix-agent
Revision history for this message
mortheres (mortheres) wrote :

Hi Andreas,

Thanks a lot to your report. It is a know problem and we are currently working on it. The problem is due to Mac::Sysprofile perl module with has bugs about getting CPU and memories informations under MacOSX Snow Leopard and MacOSX Lion.

You can follow the thread here: https://rt.cpan.org/Public/Bug/Display.html?id=52983#txn-709767

We will solve this issue as soon as possible.

Regards,

Guillaume

Changed in ocsinventory-unix-agent:
assignee: nobody → mortheres (mortheres)
importance: Undecided → High
status: New → In Progress
Revision history for this message
Andreas Xenos (andreas-xenos) wrote :

Hello Guillaume,

thank you for your answer.
Are you currently working on trying to fix the incompatibility issues for MacOSX 10.6 and 10.7?

Do you think that I should begin to edit the code for getting the memory info or should I wait for an update?

There are some other incompatibilities too, such as : Storage, Controllers, Slots, Ports .....

Can you inform please me about them as well?

Regards,
Andreas

Revision history for this message
mortheres (mortheres) wrote :

Hi Andreas,

Yes I am currently working on it. It is a major refund because instead of using the standard output of the "system_profiler" command, Mac::Sysprofile will use the xml output of this command and so the treatments are really not the same. If you try to change the code for memories detection, you will see that you should not find a solution because of the new output of "system_profiler" command since MacOSX 10.6 :( :(.

Of course, I will let you know when this refund will OK and I really hope that it will be solved quickly.

Regards,

Guillaume

Revision history for this message
Andreas Xenos (andreas-xenos) wrote :

Hey Guillaume,

thanks for your reply.
I was trying all day yesterday to find a solution, similar to the one that you implemented until MacOSX 10.5, but I couldn't!

Using the xml format of the system profiler is the next step I guess and if you want, I would really like to help you and do this together. Either way, I will keep you informed if I manage to proceed with this.

Also...
I have thought of something else (no one agrees with me so far :P).
If we use
system_profiler SPMemoryDataType | grep -i "size" , for example, we are always getting the values of "Size" of each slot, no matter the MacOS release.

In the existing code, there are already 3 different ways to get the results, in order to fight the incompatibility issues.
I know that by using the grep command, we are "destroying" the structure of the tree, but the tags are and will be the same in every release (at least 10.4 - 10.7).

In that way we can easily get Size, Type, Speed, Status, Manufacturer, Part Number, Serial Number
and with grep "DIMM" we take the number of slots.

Please let me of what you think.

Talk again. Regards,
Andreas

Revision history for this message
mortheres (mortheres) wrote :

Hi Andreas,

Of course, any help will be appreciated :) :).

However, I am not a big fan of your "grep "solution" too. I am currently rewriting the Mac::Sysprofile perl module to get the XML output of the system_profiler in a generic way. It will be easier to maintain later :) :). Your grep solution could be used if any other solution can be found :) :).

However, depending of the future Mac::Sysprofile version, there should be some code changes to do in OCS MacOS/ Backend modules. I will give news about it ASAP.

Kind regards,

Guillaume

Revision history for this message
Andreas Xenos (andreas-xenos) wrote :

Hello Guillaume,

today I edited the Mac/SysProfile.pm module> I kept the same hash structure as you did before and it works on MacOSX 10.6, 10.7.1 an 10.7.2 . You can try it if you want in previous releases of MacOS so that we can be sure that it is still backwards compatible.

In the SysProfile.pm, you can replace the gettype function with the one I am sending you in the attached file.

Also, in Backend/OS/MacOS/Mem.pm
the

#Workaround for MacOSX 10.5.7
if ($h->{'Memory Slots'}) {
    $h = $h->{'Memory Slots'};
}

works for 10.6 and 10.7 as well.
In the foreach repetition, you have memory in 10.5, which also works for 10.6.
You can add this code to make it compatible with 10.7

# 10.7
if ($slot =~ /^DIMM (\d)/) {
    $slot = $1;
}

Hope it helps. I am waiting for your opinion. If you can't see the attachment let me know.

Regards,
Andreas

Revision history for this message
Andreas Xenos (andreas-xenos) wrote :

If the gettype function is not compatible, we can keep the old one and create a new function that returns the type for 10.6 and 10.7.

We can check the release of MacOS with the Mac::SysProfile -> osx function.

Andreas

Revision history for this message
Andreas Xenos (andreas-xenos) wrote :

Hello Guillame,

this is a fix in the SysProfile.pm file to get the Memory and Storage info correctly.
Hope it's helpful :

sub gettype {
   my ($pro, $typ, $fre) = @_;
   $pro->types() unless exists $types{$typ};
   if(!exists $types{$typ}) {
      delete $pro->{$typ};
      return undef;
   }
   my $raw = $fre || !$pro->{$typ} ? `$conf{bin} $typ` : $pro->{$typ};
   my $hdr = '';
   my($k,$v,$k2);
   my $previousHdr = ''; # in case we have the same $hdr key
   my $counter = 0; # we will now get for example: Intel ICH10 AHCI 1, Intel ICH10 AHCI 2, ...
   for(split /\n/, $raw) {
      next if m/^\s*$/ || m/^\w/;
      if(m/^\s{4}\w/) {
        $hdr = $_;
        $hdr =~ s/^\s+//;
        $hdr =~ s/:.*$//;
        ++$counter;
        $hdr = $hdr . " " . $counter;
        $previousHdr = $hdr;
        print $hdr, "\n";
        $pro->{$typ}->{$hdr} = {};
      } elsif(m/^\s{6}\w/) {
         s/^\s+//;
         s/\s+$//;
         ($k,$v) = split /:\s+/;
         if($hdr) {
            $pro->{$typ}->{$hdr}->{$k} = $v;
         } else {
            $pro->{$typ}->{$k} = $v;
         }
      } elsif(m/^\s{8}\w/) {
        $k2 = $_;
        $k2 =~ s/^\s+//;
        $k2 =~ s/:.*$//;
        if($hdr) {
         $pro->{$typ}->{$hdr}->{$k2} = {};
        } else {
         $pro->{$typ}->{$k2} = {};
        }
      } elsif(m/^\s{10}\w/) {
         s/^\s+//;
         s/\s+$//;
         my($k3,$v3) = split /:\s+/;
         if($hdr) {
            $pro->{$typ}->{$hdr}->{$k2}->{$k3} = $v3;
         } else {
            $pro->{$typ}->{$k2}->{$k3} = $v3;
         }
      }
   }
   return $pro->{$typ};
}

Regards,
Andreas

Revision history for this message
Andreas Xenos (andreas-xenos) wrote :

Bug fix: no need to use $previousHdr. There was an error in reporting the Processors.
Replace in SysProfile.pm the part with the 4 whitespaces, with this:

if(m/^\s{4}\w/) {
        $hdr = $_;
        $hdr =~ s/^\s+//;
        $hdr =~ s/:.*$//;
        if ($counter > 0) {
         $hdr .= " " . $counter;
        }
        $pro->{$typ}->{$hdr} = {};
        ++$counter;
 }

Cheers,
Andreas

Revision history for this message
Andreas Xenos (andreas-xenos) wrote :

Also, I have 1TB hard drive memory and I have to convert from TB to MB.

In MacOS/Storages.pm :

my $size = $drive->{'Capacity'};
if ($size =~ /GB$/) {
     $size =~ s/ GB//;
     $size *= 1024;
 }
 if ($size =~ /TB$/) {
     $size =~ s/ TB//;
     $size *= 1048576;
 }

Andreas

Revision history for this message
Andreas Xenos (andreas-xenos) wrote :

Sorry, without the $ in =~ /GB$/ and /TB$/ :

my $size = $drive->{'Capacity'};
 if ($size =~ /GB/) {
      $size =~ s/ GB//;
      $size *= 1024;
 }
 if ($size =~ /TB/) {
      $size =~ s/ TB//;
      $size *= 1048576;
 }

Revision history for this message
mortheres (mortheres) wrote :

Hi Andreas,

Thanks a lot for your help. New OCS MacOSX agent 2.0 beta4 has been released and it should solves memories detection under MacOSX Snow Leopard and Lion: http://launchpad.net/ocsinventory-unix-agent/stable-2.0/2.0.3/+download/Ocsinventory_Agent_MacOSX_beta4.pkg.zip. Can you tell me if it solves the problem ?

Kind regards,

Guillaume

Revision history for this message
Frank (frank-bourdeau) wrote :

Hi,

Any updates on this bug Andreas?

Frank (frank-bourdeau)
Changed in ocsinventory-unix-agent:
status: In Progress → Fix Committed
Frank (frank-bourdeau)
Changed in ocsinventory-unix-agent:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.