Global Metrics

path: .metrics.nom.functions
old: 3.0
new: 2.0

path: .metrics.nom.total
old: 3.0
new: 2.0

path: .metrics.nargs.average
old: 0.3333333333333333
new: 0.5

path: .metrics.cognitive.sum
old: 0.0
new: 5.0

path: .metrics.cognitive.average
old: 0.0
new: 2.5

path: .metrics.cyclomatic.average
old: 1.2
new: 2.6666666666666665

path: .metrics.cyclomatic.sum
old: 12.0
new: 8.0

path: .metrics.loc.cloc
old: 58.0
new: 5.0

path: .metrics.loc.lloc
old: 0.0
new: 23.0

path: .metrics.loc.ploc
old: 59.0
new: 39.0

path: .metrics.loc.blank
old: 26.0
new: 16.0

path: .metrics.loc.sloc
old: 143.0
new: 60.0

path: .metrics.halstead.bugs
old: 0.23847373031413824
new: 0.2856813732212078

path: .metrics.halstead.volume
old: 1643.7013046707143
new: 1345.043650314424

path: .metrics.halstead.n2
old: 67.0
new: 52.0

path: .metrics.halstead.length
old: 260.0
new: 218.0

path: .metrics.halstead.N1
old: 140.0
new: 121.0

path: .metrics.halstead.N2
old: 120.0
new: 97.0

path: .metrics.halstead.vocabulary
old: 80.0
new: 72.0

path: .metrics.halstead.difficulty
old: 11.64179104477612
new: 18.653846153846153

path: .metrics.halstead.level
old: 0.0858974358974359
new: 0.053608247422680416

path: .metrics.halstead.time
old: 1063.090396055686
new: 1393.902073509606

path: .metrics.halstead.n1
old: 13.0
new: 20.0

path: .metrics.halstead.estimated_program_length
old: 454.5336920965049
new: 382.861427241084

path: .metrics.halstead.effort
old: 19135.627129002347
new: 25090.237323172907

path: .metrics.halstead.purity_ratio
old: 1.7482065080634803
new: 1.7562450790875417

path: .metrics.mi.mi_visual_studio
old: 28.852307871834725
new: 38.227995916124875

path: .metrics.mi.mi_sei
old: 38.40831289860112
new: 41.045240455468345

path: .metrics.mi.mi_original
old: 49.337446460837384
new: 65.36987301657354

path: .metrics.nexits.sum
old: 0.0
new: 6.0

path: .metrics.nexits.average
old: 0.0
new: 3.0

Spaces Data

Minimal test - lines (9, 58)

path: .spaces[0].metrics.cyclomatic.sum
old: 11.0
new: 6.0

path: .spaces[0].metrics.cyclomatic.average
old: 1.2222222222222223
new: 6.0

path: .spaces[0].metrics.halstead.level
old: 0.08488063660477453
new: 0.05268817204301075

path: .spaces[0].metrics.halstead.bugs
old: 0.2365172957271224
new: 0.2782294468184387

path: .spaces[0].metrics.halstead.difficulty
old: 11.78125
new: 18.979591836734695

path: .spaces[0].metrics.halstead.length
old: 256.0
new: 208.0

path: .spaces[0].metrics.halstead.vocabulary
old: 77.0
new: 69.0

path: .spaces[0].metrics.halstead.N1
old: 140.0
new: 115.0

path: .spaces[0].metrics.halstead.n2
old: 64.0
new: 49.0

path: .spaces[0].metrics.halstead.volume
old: 1604.297354417895
new: 1270.5730870098591

path: .spaces[0].metrics.halstead.estimated_program_length
old: 432.1057163358342
new: 361.5593442593925

path: .spaces[0].metrics.halstead.effort
old: 18900.628206735822
new: 24114.958590187125

path: .spaces[0].metrics.halstead.n1
old: 13.0
new: 20.0

path: .spaces[0].metrics.halstead.purity_ratio
old: 1.6879129544368523
new: 1.738266078170156

path: .spaces[0].metrics.halstead.time
old: 1050.0349003742124
new: 1339.7199216770623

path: .spaces[0].metrics.halstead.N2
old: 116.0
new: 93.0

path: .spaces[0].metrics.nargs.average
old: 0.3333333333333333
new: 1.0

path: .spaces[0].metrics.mi.mi_visual_studio
old: 30.96168903738195
new: 40.39746550303284

path: .spaces[0].metrics.mi.mi_sei
old: 40.794449627022075
new: 39.816208258856406

path: .spaces[0].metrics.mi.mi_original
old: 52.94448825392314
new: 69.07966601018616

path: .spaces[0].metrics.nexits.sum
old: 0.0
new: 5.0

path: .spaces[0].metrics.nexits.average
old: 0.0
new: 5.0

path: .spaces[0].metrics.nom.total
old: 3.0
new: 1.0

path: .spaces[0].metrics.nom.functions
old: 3.0
new: 1.0

path: .spaces[0].metrics.loc.ploc
old: 54.0
new: 35.0

path: .spaces[0].metrics.loc.sloc
old: 117.0
new: 50.0

path: .spaces[0].metrics.loc.cloc
old: 39.0
new: 2.0

path: .spaces[0].metrics.loc.lloc
old: 0.0
new: 22.0

path: .spaces[0].metrics.loc.blank
old: 24.0
new: 13.0

path: .spaces[0].metrics.cognitive.average
old: 0.0
new: 5.0

path: .spaces[0].metrics.cognitive.sum
old: 0.0
new: 5.0

Code

bool nsUserIdleServiceX::PollIdleTime(uint32_t* aIdleTime) {
  NS_OBJC_BEGIN_TRY_BLOCK_RETURN;

  kern_return_t rval;
  mach_port_t masterPort;

  rval = IOMasterPort(kIOMasterPortDefault, &masterPort);
  if (rval != KERN_SUCCESS) return false;

  io_iterator_t hidItr;
  rval = IOServiceGetMatchingServices(masterPort, IOServiceMatching("IOHIDSystem"), &hidItr);

  if (rval != KERN_SUCCESS) return false;
  NS_ASSERTION(hidItr, "Our iterator is null, but it ought not to be!");

  io_registry_entry_t entry = IOIteratorNext(hidItr);
  NS_ASSERTION(entry, "Our IO Registry Entry is null, but it shouldn't be!");

  IOObjectRelease(hidItr);

  NSMutableDictionary* hidProps;
  rval = IORegistryEntryCreateCFProperties(entry, (CFMutableDictionaryRef*)&hidProps,
                                           kCFAllocatorDefault, 0);
  if (rval != KERN_SUCCESS) return false;
  NS_ASSERTION(hidProps, "HIDProperties is null, but no error was returned.");
  [hidProps autorelease];

  id idleObj = [hidProps objectForKey:@"HIDIdleTime"];
  NS_ASSERTION([idleObj isKindOfClass:[NSData class]] || [idleObj isKindOfClass:[NSNumber class]],
               "What we got for the idle object is not what we expect!");

  uint64_t time;
  if ([idleObj isKindOfClass:[NSData class]])
    [idleObj getBytes:&time length:sizeof(time)];
  else
    time = [idleObj unsignedLongLongValue];

  IOObjectRelease(entry);

  // convert to ms from ns
  time /= 1000000;
  if (time > UINT32_MAX)  // Overflow will occur
    return false;

  *aIdleTime = static_cast(time);

  return true;

  NS_OBJC_END_TRY_BLOCK_RETURN(false);
}