<commit_before>//
//  ZetaPoolWatcher.mm
//  ZetaWatch
//
//  Created by <NAME> on 2015.12.31.
//  Copyright © 2015 the-color-black.net. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without modification, are permitted
//  provided that the conditions of the "3-Clause BSD" license described in the BSD.LICENSE file are met.
//  Additional licensing options are described in the README file.
//

#import "ZetaPoolWatcher.h"

#include <map>

@interface ZetaPoolWatcher ()
{
	// ZFS
	zfs::LibZFSHandle _zfsHandle;
	std::vector<zfs::ZPool> _pools;

	// Statistics
	std::map<std::string,zfs::VDevStat> _errorStats;
}

@end

bool containsMoreErrors(zfs::VDevStat const & a, zfs::VDevStat const & b)
{
	return b.errorRead > a.errorRead
		|| b.errorWrite > a.errorWrite
		|| b.errorChecksum > a.errorChecksum;
}

@implementation ZetaPoolWatcher

- (id)init
{
	if (self = [super init])
	{
		[self refreshPools];
	}
	return self;
}

- (void)refreshPools
{
	_pools = zfs::zpool_list(_zfsHandle);
}

- (void)checkForNewErrors
{
	for (auto && pool: _pools)
	{
		auto vdevs = pool.vdevs();
		for (auto && vdev: vdevs)
		{
			auto devices = zfs::vdevChildren(vdev);
			for (auto && device: devices)
			{
				auto stat = zfs::vdevStat(device);
				auto path = zfs::vdevPath(device);<commit_msg>ZetaPoolWatcher Timed Test<commit_after>//
//  ZetaPoolWatcher.mm
//  ZetaWatch
//
//  Created by <NAME> on 2015.12.31.
//  Copyright © 2015 the-color-black.net. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without modification, are permitted
//  provided that the conditions of the "3-Clause BSD" license described in the BSD.LICENSE file are met.
//  Additional licensing options are described in the README file.
//

#import "ZetaPoolWatcher.h"

#include <map>

@interface ZetaPoolWatcher ()
{
	// ZFS
	zfs::LibZFSHandle _zfsHandle;
	std::vector<zfs::ZPool> _pools;

	// Statistics
	std::map<std::string,zfs::VDevStat> _errorStats;

	// Timing
	NSTimer * _autoUpdateTimer;
}

@end

bool containsMoreErrors(zfs::VDevStat const & a, zfs::VDevStat const & b)
{
	return b.errorRead > a.errorRead
		|| b.errorWrite > a.errorWrite
		|| b.errorChecksum > a.errorChecksum;
}

@implementation ZetaPoolWatcher

- (id)init
{
	if (self = [super init])
	{
		_autoUpdateTimer = [NSTimer timerWithTimeInterval:60
			target:self selector:@selector(timedUpdate:) userInfo:nil repeats:YES];
		_autoUpdateTimer.tolerance = 8;
		[[NSRunLoop currentRunLoop] addTimer:_autoUpdateTimer forMode:NSDefaultRunLoopMode];
		[self refreshPools];
	}
	return self;
}

- (void)dealloc
{
	[_autoUpdateTimer invalidate];
	_autoUpdateTimer = nil;
}

- (void)timedUpdate:(NSTimer*)timer
{
	[self refreshPools];
	[self checkForNewErrors];
}

- (void)refreshPools
{
	_pools = zfs::zpool_list(_zfsHandle);
}

- (void)checkForNewErrors
{
	for (auto && pool: _pools)
	{
		auto vdevs = pool.vdevs();
		for (auto && vdev: vdevs)
		{
			auto devices = zfs::vdevChildren(vdev);
			for (auto && device: devices)
			{
				auto stat = zfs::vdevStat(device);
				auto path = zfs::vdevPath(device);
{'fraction_non_alphanumeric': 0.13234821715387085, 'fraction_numerical': 0.009315772566655958, 'mean_word_length': 4.0634146341463415, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4093614', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1147, 'n_words': 271}