Skip to content

Move Selector into database crate #1958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.73.0
toolchain: 1.75.0
override: true
components: rustfmt, clippy

Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion site/src/interpolate.rs → database/src/interpolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! Given a series with some missing data `[1, 2, ?, 4]`,
//! this iterator yields `[1, 2, 2, 4]`.

use crate::db::Point;
use crate::selector::Point;

/// Whether a point has been interpolated or not
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Expand Down
39 changes: 33 additions & 6 deletions database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ use serde::{Deserialize, Serialize};
use std::fmt;
use std::hash;
use std::ops::{Add, Sub};
use std::sync::Arc;
use std::time::Duration;

pub mod interpolate;
pub mod metric;
pub mod pool;
pub mod selector;

pub use pool::{Connection, Pool};

Expand Down Expand Up @@ -245,20 +249,15 @@ impl fmt::Display for Profile {
///
/// These are usually reported to users in a "flipped" way. For example,
/// `Cache::Empty` means we're doing a "full" build. We present this to users as "full".
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[serde(tag = "variant", content = "name")]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Scenario {
/// Empty cache (i.e., full build)
#[serde(rename = "full")]
Empty,
/// Empty cache but still incremental (i.e., a full incremental build)
#[serde(rename = "incr-full")]
IncrementalEmpty,
/// Cache is fully up-to-date (i.e., no code has changed)
#[serde(rename = "incr-unchanged")]
IncrementalFresh,
/// Cache is mostly up-to-date but some code has been changed
#[serde(rename = "incr-patched")]
IncrementalPatch(PatchName),
}

Expand Down Expand Up @@ -431,6 +430,34 @@ intern!(pub struct QueryLabel);
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct ArtifactIdNumber(pub u32);

#[derive(Debug)]
pub struct ArtifactIdIter {
ids: Arc<Vec<ArtifactId>>,
idx: usize,
}

impl ArtifactIdIter {
pub fn new(artifact_ids: Arc<Vec<ArtifactId>>) -> ArtifactIdIter {
ArtifactIdIter {
ids: artifact_ids,
idx: 0,
}
}
}

impl Iterator for ArtifactIdIter {
type Item = ArtifactId;
fn next(&mut self) -> Option<Self::Item> {
let r = self.ids.get(self.idx)?;
self.idx += 1;
Some(r.clone())
}

fn size_hint(&self) -> (usize, Option<usize>) {
(self.ids.len(), Some(self.ids.len()))
}
}

/// Cached Id lookups for many database tables.
///
/// This is a quick way to find what the database id for something.
Expand Down
113 changes: 113 additions & 0 deletions database/src/metric.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
use std::str::FromStr;

use serde::{de::IntoDeserializer, Deserialize, Serialize};

/// This enum contains all "known" metrics coming from rustc or profiling tools that we know
/// (and care) about.
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Metric {
#[serde(rename = "context-switches")]
ContextSwitches,
#[serde(rename = "cpu-clock")]
CpuClock,
#[serde(rename = "cpu-clock:u")]
CpuClockUser,
#[serde(rename = "cycles")]
Cycles,
#[serde(rename = "cycles:u")]
CyclesUser,
#[serde(rename = "faults")]
Faults,
#[serde(rename = "faults:u")]
FaultsUser,
#[serde(rename = "instructions:u")]
InstructionsUser,
#[serde(rename = "max-rss")]
MaxRSS,
#[serde(rename = "task-clock")]
TaskClock,
#[serde(rename = "task-clock:u")]
TaskClockUser,
#[serde(rename = "wall-time")]
WallTime,
#[serde(rename = "branch-misses")]
BranchMisses,
#[serde(rename = "cache-misses")]
CacheMisses,
/// Rustc guesses the codegen unit size by MIR count.
#[serde(rename = "size:codegen_unit_size_estimate")]
CodegenUnitSize,
/// The codegen unit size by llvm ir count, the real size of a cgu.
#[serde(rename = "size:cgu_instructions")]
CodegenUnitLlvmIrCount,
#[serde(rename = "size:dep_graph")]
DepGraphSize,
#[serde(rename = "size:linked_artifact")]
LinkedArtifactSize,
#[serde(rename = "size:object_file")]
ObjectFileSize,
#[serde(rename = "size:query_cache")]
QueryCacheSize,
#[serde(rename = "size:work_product_index")]
WorkProductIndexSize,
#[serde(rename = "size:crate_metadata")]
CrateMetadataSize,
#[serde(rename = "size:dwo_file")]
DwoFileSize,
#[serde(rename = "size:assembly_file")]
AssemblyFileSize,
#[serde(rename = "size:llvm_bitcode")]
LlvmBitcodeSize,
#[serde(rename = "size:llvm_ir")]
LlvmIrSize,
/// Total bytes of a generated documentation directory
#[serde(rename = "size:doc_bytes")]
DocByteSize,
/// Number of files inside a generated documentation directory.
#[serde(rename = "size:doc_files_count")]
DocFilesCount,
}

impl FromStr for Metric {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Metric::deserialize(s.into_deserializer())
.map_err(|e: serde::de::value::Error| format!("Unknown metric `{s}`: {e:?}"))
}
}

impl Metric {
pub fn as_str(&self) -> &str {
match self {
Metric::ContextSwitches => "context-switches",
Metric::CpuClock => "cpu-clock",
Metric::CpuClockUser => "cpu-clock:u",
Metric::Cycles => "cycles",
Metric::CyclesUser => "cycles:u",
Metric::Faults => "faults",
Metric::FaultsUser => "faults:u",
Metric::InstructionsUser => "instructions:u",
Metric::MaxRSS => "max-rss",
Metric::TaskClock => "task-clock",
Metric::TaskClockUser => "task-clock:u",
Metric::WallTime => "wall-time",
Metric::BranchMisses => "branch-misses",
Metric::CacheMisses => "cache-misses",
Metric::CodegenUnitSize => "size:codegen_unit_size_estimate",
Metric::CodegenUnitLlvmIrCount => "size:cgu_instructions",
Metric::DepGraphSize => "size:dep_graph",
Metric::LinkedArtifactSize => "size:linked_artifact",
Metric::ObjectFileSize => "size:object_file",
Metric::QueryCacheSize => "size:query_cache",
Metric::WorkProductIndexSize => "size:work_product_index",
Metric::CrateMetadataSize => "size:crate_metadata",
Metric::DwoFileSize => "size:dwo_file",
Metric::AssemblyFileSize => "size:assembly_file",
Metric::LlvmBitcodeSize => "size:llvm_bitcode",
Metric::LlvmIrSize => "size:llvm_ir",
Metric::DocByteSize => "size:doc_bytes",
Metric::DocFilesCount => "size:doc_files_count",
}
}
}
Loading
Loading