Skip to content

Commit

Permalink
finish refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Oct 17, 2023
1 parent 4705c1d commit 28c85a3
Show file tree
Hide file tree
Showing 46 changed files with 116 additions and 160 deletions.
15 changes: 4 additions & 11 deletions 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 crates/symbolicator-native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "symbolicator-native"
publish = false
version = "23.9.1"
version = "23.10.0"
authors = ["Sentry <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down
6 changes: 3 additions & 3 deletions crates/symbolicator-native/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use symbolicator_service::utils::hex::HexValue;
use symbolicator_sources::SourceConfig;
use thiserror::Error;

use crate::metrics::StacktraceOrigin;
pub use crate::metrics::StacktraceOrigin;

#[derive(Debug, Clone)]
/// A request for symbolication of multiple stack traces.
Expand Down Expand Up @@ -483,7 +483,7 @@ impl AdjustInstructionAddr {
/// [`adjust_instruction_addr`](RawFrame::adjust_instruction_addr)
/// field set, this will be [`Yes`](Self::Yes) or [`No`](Self::No) accordingly, otherwise
/// the given default is used.
fn for_frame(frame: &RawFrame, default: Self) -> Self {
pub fn for_frame(frame: &RawFrame, default: Self) -> Self {
match frame.adjust_instruction_addr {
Some(true) => Self::Yes,
Some(false) => Self::No,
Expand All @@ -496,7 +496,7 @@ impl AdjustInstructionAddr {
/// This will be [`Yes`](Self::Yes) if any frame in the thread has the
/// [`adjust_instruction_addr`](RawFrame::adjust_instruction_addr)
/// field set, otherwise it will be [`Auto`](Self::Auto).
fn default_for_thread(thread: &RawStacktrace) -> Self {
pub fn default_for_thread(thread: &RawStacktrace) -> Self {
if thread
.frames
.iter()
Expand Down
4 changes: 3 additions & 1 deletion crates/symbolicator-native/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod caches;
mod interface;
pub mod interface;
mod metrics;
mod symbolication;

pub use symbolication::symbolicate::SymbolicationActor;
2 changes: 1 addition & 1 deletion crates/symbolicator-native/src/symbolication/demangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use symbolic::demangle::{Demangle, DemangleOptions};
use symbolic::symcache::Function;

/// Options for demangling all symbols.
const DEMANGLE_OPTIONS: DemangleOptions = DemangleOptions::complete().return_type(false);
pub const DEMANGLE_OPTIONS: DemangleOptions = DemangleOptions::complete().return_type(false);

/// A cache for demangled symbols
pub type DemangleCache = moka::sync::Cache<(String, Language), String>;
Expand Down
2 changes: 1 addition & 1 deletion crates/symbolicator-native/src/symbolication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ mod module_lookup;
mod native;
mod process_minidump;
mod source_context;
mod symbolicate;
pub mod symbolicate;
105 changes: 55 additions & 50 deletions crates/symbolicator-native/src/symbolication/source_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,74 @@ use std::collections::HashMap;

use futures::future;
use symbolicator_service::types::{Scope, ScrapingConfig};
use symbolicator_service::utils::http::is_valid_origin;
use symbolicator_sources::HttpRemoteFile;

use crate::interface::{CompleteStacktrace, RawFrame};

use super::module_lookup::ModuleLookup;
use super::symbolicate::SymbolicationActor;

pub async fn apply_source_context(
&self,
module_lookup: &mut ModuleLookup,
stacktraces: &mut [CompleteStacktrace],
scraping: &ScrapingConfig,
) {
module_lookup
.fetch_sources(self.objects.clone(), stacktraces)
.await;
impl SymbolicationActor {
pub async fn apply_source_context(
&self,
module_lookup: &mut ModuleLookup,
stacktraces: &mut [CompleteStacktrace],
scraping: &ScrapingConfig,
) {
module_lookup
.fetch_sources(self.objects.clone(), stacktraces)
.await;

// Map collected source contexts to frames and collect URLs for remote source links.
let mut remote_sources: HashMap<(Scope, url::Url), Vec<&mut RawFrame>> = HashMap::new();
{
let debug_sessions = module_lookup.prepare_debug_sessions();
// Map collected source contexts to frames and collect URLs for remote source links.
let mut remote_sources: HashMap<(Scope, url::Url), Vec<&mut RawFrame>> = HashMap::new();
{
let debug_sessions = module_lookup.prepare_debug_sessions();

for trace in stacktraces {
for frame in &mut trace.frames {
let Some(url) =
module_lookup.try_set_source_context(&debug_sessions, &mut frame.raw)
else {
continue;
};
if let Some(vec) = remote_sources.get_mut(&url) {
vec.push(&mut frame.raw)
} else {
remote_sources.insert(url, vec![&mut frame.raw]);
for trace in stacktraces {
for frame in &mut trace.frames {
let Some(url) =
module_lookup.try_set_source_context(&debug_sessions, &mut frame.raw)
else {
continue;
};
if let Some(vec) = remote_sources.get_mut(&url) {
vec.push(&mut frame.raw)
} else {
remote_sources.insert(url, vec![&mut frame.raw]);
}
}
}
}
}

// Download remote sources and update contexts.
if !remote_sources.is_empty() {
let cache = self.sourcefiles_cache.as_ref();
let futures = remote_sources
.into_iter()
.map(|((source_scope, url), frames)| async move {
let mut remote_file = HttpRemoteFile::from_url(url.clone());
// Download remote sources and update contexts.
if !remote_sources.is_empty() {
let cache = self.sourcefiles_cache.as_ref();
let futures =
remote_sources
.into_iter()
.map(|((source_scope, url), frames)| async move {
let mut remote_file = HttpRemoteFile::from_url(url.clone());

if scraping.enabled && is_valid_origin(&url, &scraping.allowed_origins) {
remote_file.headers.extend(
scraping
.headers
.iter()
.map(|(key, value)| (key.clone(), value.clone())),
);
}
if scraping.enabled && is_valid_origin(&url, &scraping.allowed_origins) {
remote_file.headers.extend(
scraping
.headers
.iter()
.map(|(key, value)| (key.clone(), value.clone())),
);
}

if let Ok(source) = cache
.fetch_file(&source_scope, remote_file.into(), true)
.await
{
for frame in frames {
ModuleLookup::set_source_context(&source, frame);
}
}
});
future::join_all(futures).await;
if let Ok(source) = cache
.fetch_file(&source_scope, remote_file.into(), true)
.await
{
for frame in frames {
ModuleLookup::set_source_context(&source, frame);
}
}
});
future::join_all(futures).await;
}
}
}
10 changes: 5 additions & 5 deletions crates/symbolicator-native/src/symbolication/symbolicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::interface::{
};
use crate::metrics::{record_symbolication_metrics, StacktraceMetrics};

use super::demangle::DemangleCache;
use super::demangle::{DemangleCache, DEMANGLE_OPTIONS};
use super::dotnet::symbolicate_dotnet_frame;
use super::module_lookup::{CacheFileEntry, ModuleLookup};
use super::native::{get_relative_caller_addr, symbolicate_native_frame};
Expand All @@ -29,12 +29,12 @@ use super::native::{get_relative_caller_addr, symbolicate_native_frame};
#[derive(Clone, Debug)]
pub struct SymbolicationActor {
demangle_cache: DemangleCache,
objects: ObjectsActor,
pub(crate) objects: ObjectsActor,
symcaches: SymCacheActor,
cficaches: CfiCacheActor,
pub(crate) cficaches: CfiCacheActor,
ppdb_caches: PortablePdbCacheActor,
diagnostics_cache: Cache,
sourcefiles_cache: Arc<SourceFilesCache>,
pub(crate) diagnostics_cache: Cache,
pub(crate) sourcefiles_cache: Arc<SourceFilesCache>,
}

impl SymbolicationActor {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::path::Path;
use std::sync::Arc;

use symbolicator_service::services::symbolication::SymbolicateStacktraces;
use symbolicator_service::types::{FrameStatus, ObjectDownloadInfo, ObjectFileStatus, Scope};
use symbolicator_native::interface::{FrameStatus, SymbolicateStacktraces};
use symbolicator_service::objects::ObjectDownloadInfo;
use symbolicator_service::types::{ObjectFileStatus, Scope};
use symbolicator_sources::{
DirectoryLayoutType, FileType, FilesystemSourceConfig, HttpSourceConfig, RemoteFileUri,
SentrySourceConfig, SourceConfig, SourceId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::time::Duration;

use symbolicator_service::types::{
CompletedSymbolicationResponse, FrameStatus, ObjectDownloadInfo, ObjectFileStatus,
ObjectUseInfo,
};
use symbolicator_native::interface::{CompletedSymbolicationResponse, FrameStatus};
use symbolicator_service::objects::{ObjectDownloadInfo, ObjectUseInfo};
use symbolicator_service::types::ObjectFileStatus;

use crate::{example_request, setup_service, Server};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::sync::Arc;

use symbolicator_native::interface::{StacktraceOrigin, SymbolicateStacktraces};
use symbolicator_native::SymbolicationActor;
use symbolicator_service::config::Config;
use symbolicator_service::services::symbolication::{
StacktraceOrigin, SymbolicateStacktraces, SymbolicationActor,
};
use symbolicator_service::services::SharedServices;
use symbolicator_service::types::RawObjectInfo;
use symbolicator_sources::SourceConfig;
Expand Down
13 changes: 1 addition & 12 deletions crates/symbolicator-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ https = []

[dependencies]
anyhow = "1.0.57"
apple-crash-report-parser = "0.5.1"
async-trait = "0.1.53"
aws-config = "0.56.0"
aws-sdk-s3 = "0.31.1"
aws-types = "0.56.0"
aws-credential-types = { version = "0.56.0", features = ["hardcoded-credentials"] }
backtrace = "0.3.65"
cadence = "0.29.0"
chrono = { version = "0.4.19", features = ["serde"] }
data-url = "0.3.0"
filetime = "0.2.16"
flate2 = "1.0.23"
futures = "0.3.12"
Expand All @@ -30,21 +26,17 @@ idna = "0.4.0"
ipnetwork = "0.20.0"
jsonwebtoken = "8.1.0"
lazy_static = "1.4.0"
minidump = "0.18.0"
minidump-processor = "0.18.0"
minidump-unwind = "0.18.0"
moka = { version = "0.12.1", features = ["future", "sync"] }
once_cell = "1.17.1"
parking_lot = "0.12.0"
rand = "0.8.5"
regex = "1.5.5"
reqwest = { version = "0.11.0", features = ["gzip", "brotli", "deflate", "json", "stream", "trust-dns"] }
sentry = { version = "0.31.7", features = ["tracing"] }
serde = { version = "1.0.137", features = ["derive", "rc"] }
serde_json = "1.0.81"
serde_yaml = "0.9.14"
sha2 = "0.10.6"
symbolic = { version = "12.4.0", features = ["cfi", "common-serde", "debuginfo", "demangle", "sourcemapcache", "symcache", "il2cpp", "ppdb"] }
symbolic = { version = "12.4.0", features = ["cfi", "common-serde", "debuginfo", "symcache"] }
symbolicator-sources = { path = "../symbolicator-sources" }
tempfile = "3.2.0"
thiserror = "1.0.31"
Expand All @@ -57,8 +49,5 @@ zip = { version = "0.6.4", default-features = false, features = ["deflate"] }
zstd = "0.12.1"

[dev-dependencies]
insta = { version = "1.18.0", features = ["redactions", "yaml"] }
reqwest = { version = "0.11.0", features = ["multipart"] }
sha-1 = "0.10.0"
symbolicator-test = { path = "../symbolicator-test" }
test-assembler = "0.1.5"
File renamed without changes.
Loading

0 comments on commit 28c85a3

Please sign in to comment.