1

我一直在使用 EF 并使用 CsvHelper 将测试输出直接映射到数据库实体以进行快速存储。我现在遇到了一个跟踪 cpu 核心、端口 io 和核心/端口配对数据的性能监视器的问题。我可以有任意数量的核心和任意数量的端口,这些在核心/端口配对中相乘。输出是 csv 格式,我无法控制这种输出格式。

我需要在这个动态列大小的 csv 中有效地扫描到实体模型。我希望我可以用最少的操作将列映射到各种表。

EF 的 POCO 配对示例:

public class CpuTesting
{
    [Key]
    public int Id { get; set; }
    public int Socket { get; set; }
    public int Core { get; set; }
    public double ProcessorTime { get; set; }

    public virtual ICollection<PortCorePairing> PortCorePairings { get; set; } 
}

public class PortIo
{
    [Key]
    public int Id { get; set; }
    public Int64 BytesReceivedTotal { get; set; }
    public Int64 BytesSentTotal { get; set; }
}

public class PortCorePairing
{
    [Key]
    public int Id { get; set; }
    public int CpuTestingId { get; set; }
    public int InteruptPerSecond { get; set; }
    public int DiscardedSent { get; set; }
    public int DiscardedReceived { get; set; }

    [ForeignKey("CpuTestingId")]
    public virtual CpuTesting CpuTesting { get; set; }
}

这映射到的大规模简化的标题行(相信我,它被解释了......我通常为单个端口测试处理 200 多列的集合,这就是为什么我希望找到更好的映射方式) .

Cpu(0,0) ProcTime, Cpu(0,1) ProcTime, Cpu(1,0) ProcTime, Cpu(1,1) ProcTime, Port(0) BytesRecTotal, Port(0) BytesSentTotal, Port(1) BytesRecTotal, Port(1) BytesSentTotal, Cpu(0,0) Port(0) CoreIntPerSec, Cpu(0,0) Port(0) Discarded, Cpu(0,1) Port(0) CoreIntPerSec, Cpu(0,1) Port(0) Discarded, Cpu(1,0) Port(1) CoreIntPerSec, Cpu(1,0) Port(1) Discarded, Cpu(1,1) Port(1) CoreIntPerSec, Cpu(1,1) Port(1) Discarded

现在我看到的唯一方法是预处理标题行以将列解析成集合(按索引映射),通过 csv 文件进行迭代。这有很多开销,并且会涉及映射和自动映射。标题在多个位置更改文本,这使得映射需要关闭标题中的子字符串。

上面的 CSV 标头仅是模式示例: 包含的 csv 标头只是问题的精简模式。如果我更改端口的品牌/型号,我会得到端口的新名称而不是Port。正在测试的下一个系统可能每个 CPU 有 12 个内核和/或四个端口。从字面上看,现在我面前有一个数据集,有 4 个 CPU @ 12 个内核,4 个端口,并且配对最终接近 1200 列。

4

0 回答 0