Skip to content
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ $ gnutls-cli --x509cafile=doc/credentials/x509/ca.pem localhost -p 5556 --priori

In the above example, client stores logs as a sequence of
CBOR objects, which can be parsed and printed as a tree with the
`crau-log-parser` executable:
`crau-query` executable:
```console
$ crau-log-parser audit.cborseq
$ crau-query --log-file audit.cborseq
[
{
"context": "33acb8e6ccc65bb285bd2f84cac3bf80",
Expand Down Expand Up @@ -183,7 +183,7 @@ From the tree output, a flamegraph can be produced with the
`scripts/flamegraph.py`:

```console
$ crau-log-parser audit.cborseq | python scripts/flamegraph.py -
$ crau-query --log-file audit.cborseq | python scripts/flamegraph.py -
dumping data to flamegraph.html
```

Expand Down
17 changes: 8 additions & 9 deletions crypto-auditing/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::cell::RefCell;
use std::collections::BTreeMap;
use std::ffi::CStr;
use std::rc::Rc;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use sysinfo::System;

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
Expand Down Expand Up @@ -50,7 +50,7 @@ pub struct Context {
#[derive(Debug)]
pub struct ContextTracker {
all_contexts: BTreeMap<ContextId, Rc<RefCell<Context>>>,
root_contexts: Vec<(Instant, Rc<RefCell<Context>>)>,
root_contexts: Vec<Rc<RefCell<Context>>>,
boot_time: SystemTime,
}

Expand All @@ -67,11 +67,11 @@ impl ContextTracker {
}
}

pub fn flush(&mut self, since: Option<Instant>) -> impl IntoIterator<Item = Context> {
pub fn flush(&mut self, before: Option<SystemTime>) -> impl IntoIterator<Item = Context> {
let mut removed = Vec::new();
self.root_contexts.retain(|(timestamp, context)| {
if let Some(since) = since
&& *timestamp < since
self.root_contexts.retain(|context| {
if let Some(before) = before
&& context.borrow().start > before
{
true
} else {
Expand Down Expand Up @@ -115,7 +115,7 @@ impl ContextTracker {
.spans
.insert(*group.context(), context.clone());
} else {
self.root_contexts.push((Instant::now(), context.clone()));
self.root_contexts.push(context.clone());
count += 1;
}
self.all_contexts.insert(*group.context(), context);
Expand All @@ -134,8 +134,7 @@ impl ContextTracker {
events: Default::default(),
spans: Default::default(),
}));
self.root_contexts
.push((Instant::now(), context_obj.clone()));
self.root_contexts.push(context_obj.clone());
self.all_contexts.insert(*group.context(), context_obj);
count += 1;
}
Expand Down
4 changes: 2 additions & 2 deletions log-parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

[![crates.io badge](https://img.shields.io/crates/v/crypto-auditing-log-parser.svg)](https://crates.io/crates/crypto-auditing-log-parser)

This crate provides the `crau-log-parser` executable. To see the whole architecture, see the design [document](https://github.com/latchset/crypto-auditing/blob/main/docs/architecture.md).
This crate provides the `crau-query` executable. To see the whole architecture, see the design [document](https://github.com/latchset/crypto-auditing/blob/main/docs/architecture.md).

## Usage

```console
$ cargo install crypto-auditing-log-parser
$ crau-log-parser /path/to/audit.cborseq
$ crau-query --log-file /path/to/audit.cborseq
```
2 changes: 1 addition & 1 deletion log-parser/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod config;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = config::Config::new()?;
Pager::new().skip_on_notty().setup();
Pager::new().setup();

let log_file = std::fs::File::open(&config.log_file)
.with_context(|| format!("unable to read file `{}`", config.log_file.display()))?;
Expand Down
1 change: 1 addition & 0 deletions monitor/LICENSE
12 changes: 12 additions & 0 deletions monitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# crypto-auditing-event-monitor

[![crates.io badge](https://img.shields.io/crates/v/crypto-auditing-event-monitor.svg)](https://crates.io/crates/crypto-auditing-event-monitor)

This crate provides the `crau-query` executable. To see the whole architecture, see the design [document](https://github.com/latchset/crypto-auditing/blob/main/docs/architecture.md).

## Usage

```console
$ cargo install crypto-auditing-event-monitor
$ crau-monitor
```
7 changes: 4 additions & 3 deletions monitor/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde_cbor::de::Deserializer;
use std::fs;
use std::marker;
use std::path::{Path, PathBuf};
use std::time::{Duration, Instant};
use std::time::{Duration, SystemTime};
use tokio::signal;
use tokio::sync::{broadcast, mpsc};
use tokio::task::JoinSet;
Expand Down Expand Up @@ -93,7 +93,7 @@ struct Writer {
event_window: Duration,
scopes: Vec<String>,
timeouts: JoinSet<()>,
last_flush: Instant,
last_flush: SystemTime,
}

impl Writer {
Expand All @@ -103,7 +103,7 @@ impl Writer {
event_window,
scopes: scopes.to_owned(),
timeouts: JoinSet::new(),
last_flush: Instant::now(),
last_flush: SystemTime::now(),
}
}

Expand Down Expand Up @@ -134,6 +134,7 @@ impl Writer {
for context in self.tracker.flush(self.last_flush.checked_add(self.event_window)) {
println!("{}", serde_json::to_string_pretty(&context).unwrap());
}
self.last_flush = SystemTime::now();
},
_ = shutdown_receiver.recv() => break,
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/flamegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Usage:
#
# cargo run --bin crypto-auditing-log-parser audit.cborseq > audit.json
# crau-query --log-file audit.cborseq > audit.json
# python flamegraph.py audit.json
#
# Based on perf script flamegraph written by
Expand Down