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



372
373
374
# File 'lib/hwloc/Obj.rb', line 372

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

#attrObject



590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/hwloc/Obj.rb', line 590

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
    return at[:cache] if self.is_a_cache?
  end
  return nil
end

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



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

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



438
439
440
441
442
443
444
445
446
447
448
449
# File 'lib/hwloc/Obj.rb', line 438

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



553
554
555
# File 'lib/hwloc/Obj.rb', line 553

def descendants
  return each_descendant.to_a
end

#distancesObject



558
559
560
561
562
563
564
565
566
567
568
569
# File 'lib/hwloc/Obj.rb', line 558

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



451
452
453
# File 'lib/hwloc/Obj.rb', line 451

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

#each_descendant(&block) ⇒ Object



468
469
470
471
472
473
474
475
476
# File 'lib/hwloc/Obj.rb', line 468

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



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

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

#each_io_child(*args, &block) ⇒ Object



490
491
492
# File 'lib/hwloc/Obj.rb', line 490

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

#each_misc_child(*args, &block) ⇒ Object



504
505
506
# File 'lib/hwloc/Obj.rb', line 504

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

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



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

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



532
533
534
535
536
537
538
539
540
541
542
# File 'lib/hwloc/Obj.rb', line 532

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



572
573
574
575
576
577
578
579
580
581
582
583
584
# File 'lib/hwloc/Obj.rb', line 572

def infos
  infos_count = self[:infos_count]
  if infos_count == 0 then
    return []
  else
    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] }
	return inf_h
  end
end

#inspectObject



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

def inspect
  return to_s(1)
end

#io_childrenObject



480
481
482
483
484
485
486
487
488
# File 'lib/hwloc/Obj.rb', line 480

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)


618
619
620
# File 'lib/hwloc/Obj.rb', line 618

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

#misc_childrenObject



494
495
496
497
498
499
500
501
502
# File 'lib/hwloc/Obj.rb', line 494

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



544
545
546
# File 'lib/hwloc/Obj.rb', line 544

def parents
  return each_parent.to_a
end

#to_s(verbose = 0) ⇒ Object



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

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



376
377
378
379
380
381
# File 'lib/hwloc/Obj.rb', line 376

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



384
385
386
# File 'lib/hwloc/Obj.rb', line 384

def type_string
  return Hwloc.hwloc_obj_type_string(type)
end