Class: Hwloc::Obj

Inherits:
Struct
  • Object
show all
Defined in:
lib/hwloc/Obj.rb,
lib/hwloc/Obj.rb,
lib/hwloc/Edition.rb

Instance Attribute Summary

Attributes inherited from Struct

#topology

Instance Method Summary collapse

Methods inherited from Struct

#[], #method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hwloc::Struct

Instance Method Details

#==(other) ⇒ Object



397
398
399
# File 'lib/hwloc/Obj.rb', line 397

def ==(other)
  return other.kind_of?(Obj) && to_ptr == other.to_ptr
end

#add_infos(**dict) ⇒ Object



620
621
622
623
624
625
626
# File 'lib/hwloc/Obj.rb', line 620

def add_infos(**dict)
  dict.each { |k, v|
    err = Hwloc.hwloc_obj_add_info(self, k.to_s, v.to_s)
    raise EditionError if err == -1
  }
  self
end

#attrObject



628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'lib/hwloc/Obj.rb', line 628

def attr
  at = self[:attr]
  return nil if at.to_ptr.null?
  t = self[:type]
  case t
  when :OBJ_GROUP
    return at[:group]
  when :OBJ_PCI_DEVICE
    return at[:pcidev]
  when :OBJ_BRIDGE
    return at[:bridge]
  when :OBJ_OS_DEVICE
    return at[:osdev]
  else
    if API_VERSION >= API_VERSION_2_0 then
      return at[:numanode] if t == :OBJ_NUMANODE
    end
    return at[:cache] if self.is_a_cache?
  end
  return nil
end

#attr_snprintf(verbose = 0, separator = ",") ⇒ Object



413
414
415
416
417
418
# File 'lib/hwloc/Obj.rb', line 413

def attr_snprintf(verbose=0, separator=",")
  sz = Hwloc.hwloc_obj_attr_snprintf(nil, 0, self, separator, verbose) + 1
  str_ptr = FFI::MemoryPointer::new(:char, sz)
  Hwloc.hwloc_obj_attr_snprintf(str_ptr, sz, self, separator, verbose)
  return str_ptr.read_string
end

#childrenObject



457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/hwloc/Obj.rb', line 457

def children
  arity = self[:arity]
  if arity == 0 then
    return []
  else
    return self[:children].read_array_of_pointer(arity).collect { |p|
      c = Obj::new(p)
      c.instance_variable_set(:@topology, @topology)
      c
    }
  end
end

#descendantsObject



586
587
588
# File 'lib/hwloc/Obj.rb', line 586

def descendants
  return each_descendant.to_a
end

#distancesObject



591
592
593
594
595
596
597
598
599
600
601
602
# File 'lib/hwloc/Obj.rb', line 591

def distances
  distances_count = self[:distances_count]
  if distances_count == 0 then
    return []
  else
    return self[:distances].read_array_of_pointer(distances_count).collect { |p|
      d = Distances::new(p)
      d.instance_variable_set(:@topology, @topology)
      d
    }
  end
end

#each_child(*args, &block) ⇒ Object



470
471
472
# File 'lib/hwloc/Obj.rb', line 470

def each_child(*args, &block)
  return children.each(*args, &block)
end

#each_descendant(&block) ⇒ Object



487
488
489
490
491
492
493
494
495
# File 'lib/hwloc/Obj.rb', line 487

def each_descendant(&block)
  if block then
    children.each { |c|
      c.each_obj(&block)
    }
  else
    to_enum(:each_descendant)
  end
end

#each_info(*args, &block) ⇒ Object



616
617
618
# File 'lib/hwloc/Obj.rb', line 616

def each_info(*args, &block)
  return infos.each(*args, &block)
end

#each_io_child(*args, &block) ⇒ Object



523
524
525
# File 'lib/hwloc/Obj.rb', line 523

def each_io_child(*args, &block)
  return io_children.each(*args, &block)
end

#each_memory_child(*args, &block) ⇒ Object



509
510
511
# File 'lib/hwloc/Obj.rb', line 509

def each_memory_child(*args, &block)
  return memory_children.each(*args, &block)
end

#each_misc_child(*args, &block) ⇒ Object



537
538
539
# File 'lib/hwloc/Obj.rb', line 537

def each_misc_child(*args, &block)
  return misc_children.each(*args, &block)
end

#each_obj(&block) ⇒ Object Also known as: traverse



475
476
477
478
479
480
481
482
483
484
485
# File 'lib/hwloc/Obj.rb', line 475

def each_obj(&block)
  if block then
    block.call self
    children.each { |c|
      c.each_obj(&block)
    }
    return self
  else
    to_enum(:each_obj)
  end
end

#each_parent(&block) ⇒ Object Also known as: each_ancestor



565
566
567
568
569
570
571
572
573
574
575
# File 'lib/hwloc/Obj.rb', line 565

def each_parent(&block)
  if block then
    if parent then
      block.call parent
      parent.each_parent(&block)
    end
    return self
  else
    to_enum(:each_parent)
  end
end

#infosObject



605
606
607
608
609
610
611
612
613
614
# File 'lib/hwloc/Obj.rb', line 605

def infos
  infos_count = self[:infos_count]
  return {} if infos_count == 0
  inf_array = infos_count.times.collect { |i|
    o = ObjInfo::new(self[:infos] + i*ObjInfo.size)
  }
  inf_h = {}
  inf_array.each { |e| inf_h[e[:name].to_sym] = e[:value] if e[:name] }
  return inf_h
end

#inspectObject



427
428
429
# File 'lib/hwloc/Obj.rb', line 427

def inspect
  return to_s(1)
end

#io_childrenObject



513
514
515
516
517
518
519
520
521
# File 'lib/hwloc/Obj.rb', line 513

def io_children
  return [] if io_arity == 0
  c = []
  c.push( io_first_child )
  (io_arity-1).times {
    c.push( c[-1].next_sibling )
  }
  return c
end

#is_a_cache?Boolean

Returns:

  • (Boolean)


659
660
661
# File 'lib/hwloc/Obj.rb', line 659

def is_a_cache?
  (Hwloc::OBJ_L1CACHE..Hwloc::OBJ_L3ICACHE).include?(ObjType[type])
end

#is_cache?Boolean

Returns:

  • (Boolean)


675
676
677
# File 'lib/hwloc/Obj.rb', line 675

def is_cache?
  Hwloc::hwloc_obj_type_is_cache(ObjType[type]) == 1
end

#is_dcache?Boolean

Returns:

  • (Boolean)


683
684
685
# File 'lib/hwloc/Obj.rb', line 683

def is_dcache?
  Hwloc::hwloc_obj_type_is_dcache(ObjType[type]) == 1
end

#is_icache?Boolean

Returns:

  • (Boolean)


679
680
681
# File 'lib/hwloc/Obj.rb', line 679

def is_icache?
  Hwloc::hwloc_obj_type_is_icache(ObjType[type]) == 1
end

#is_io?Boolean

Returns:

  • (Boolean)


667
668
669
# File 'lib/hwloc/Obj.rb', line 667

def is_io?
  Hwloc::hwloc_obj_type_is_io(ObjType[type]) == 1
end

#is_memory?Boolean

Returns:

  • (Boolean)


671
672
673
# File 'lib/hwloc/Obj.rb', line 671

def is_memory?
  Hwloc::hwloc_obj_type_is_memory(ObjType[type]) == 1
end

#is_misc?Boolean

Returns:

  • (Boolean)


687
688
689
# File 'lib/hwloc/Obj.rb', line 687

def is_misc?
  ObjType[type] == Hwloc::OBJ_MISC
end

#is_normal?Boolean

Returns:

  • (Boolean)


663
664
665
# File 'lib/hwloc/Obj.rb', line 663

def is_normal?
  Hwloc::hwloc_obj_type_is_normal(ObjType[type]) == 1
end

#memory_childrenObject



499
500
501
502
503
504
505
506
507
# File 'lib/hwloc/Obj.rb', line 499

def memory_children
  return [] if memory_arity == 0
  c = []
  c.push( memory_first_child )
  (memory_arity-1).times {
    c.push( c[-1].next_sibling )
  }
  return c
end

#misc_childrenObject



527
528
529
530
531
532
533
534
535
# File 'lib/hwloc/Obj.rb', line 527

def misc_children
  return [] if misc_arity == 0
  c = []
  c.push( misc_first_child )
  (misc_arity-1).times {
    c.push( c[-1].next_sibling )
  }
  return c
end

#parentsObject Also known as: ancestors



577
578
579
# File 'lib/hwloc/Obj.rb', line 577

def parents
  return each_parent.to_a
end

#to_s(verbose = 0) ⇒ Object



420
421
422
423
424
425
# File 'lib/hwloc/Obj.rb', line 420

def to_s(verbose=0)
  attr_str = attr_snprintf(verbose)
  str = "#{type_snprintf(verbose)} L##{logical_index}"
  str += " (#{attr_str})" if attr_str != ""
  return str
end

#to_topoObject



85
86
87
88
89
90
91
# File 'lib/hwloc/Edition.rb', line 85

def to_topo
  new_topo = Topology::new
  new_topo.set_custom
  new_topo.custom_insert_topology( new_topo.root_obj , @topology, self)
  new_topo.load
  return new_topo
end

#type_snprintf(verbose = 0) ⇒ Object



401
402
403
404
405
406
# File 'lib/hwloc/Obj.rb', line 401

def type_snprintf(verbose=0)
  sz = Hwloc.hwloc_obj_type_snprintf(nil, 0, self, verbose) + 1
  str_ptr = FFI::MemoryPointer::new(:char, sz)
  Hwloc.hwloc_obj_type_snprintf(str_ptr, sz, self, verbose)
  return str_ptr.read_string
end

#type_stringObject Also known as: type_name



408
409
410
# File 'lib/hwloc/Obj.rb', line 408

def type_string
  return Hwloc.hwloc_obj_type_string(type)
end