---
title: statistics | CodeWeaver Docs
description: API reference for codeweaver.core.statistics
url: "https://docs.knitli.com/api/core/statistics"
type: static
generatedAt: "2026-04-17T17:21:08.080Z"
---

# statistics
       [Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fstatistics%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fstatistics%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[View in Markdown](/codeweaver/api/core/statistics.md)       [Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fstatistics%2F)[Share on X](https://x.com/intent/tweet?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fstatistics%2F&text=statistics)[Share on Threads](https://threads.net/intent/post?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fstatistics%2F&text=statistics)[Share on Bluesky](https://bsky.app/intent/compose?text=statistics%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fstatistics%2F)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fstatistics%2F)[Share on Reddit](https://reddit.com/submit?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fstatistics%2F&title=statistics)[Share on Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fstatistics%2F&t=statistics)[Share on Email](mailto:?subject=statistics&body=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fstatistics%2F)[Share on WhatsApp](https://wa.me/?text=statistics%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fstatistics%2F)[Share on Telegram](https://t.me/share/url?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fstatistics%2F&text=statistics)
# `codeweaver.core.statistics`
[Section titled “codeweaver.core.statistics”](#codeweavercorestatistics)
Statistics tracking for CodeWeaver, including file indexing, retrieval, and session performance metrics.

## Class: `FailoverStats`
[Section titled “Class: FailoverStats”](#class-failoverstats)
Statistics tracking for vector store failover operations.

## Class: `FileStatistics`
[Section titled “Class: FileStatistics”](#class-filestatistics)
Comprehensive file statistics tracking categories, languages, and operations.

### Method: `add_chunk_from_codechunk`
[Section titled “Method: add_chunk_from_codechunk”](#method-add_chunk_from_codechunk)

**

```
add_chunk_from_codechunk()
```

Add chunk statistics using a CodeChunk object (efficient).

This method tracks chunk creation statistics including chunk type (semantic vs delimiter), size, and language. It uses pre-computed information from the CodeChunk to avoid redundant operations.

Args: chunk: CodeChunk with pre-computed ext_category and metadata operation: Type of operation performed (usually “processed” for chunks)

### Method: `add_file`
[Section titled “Method: add_file”](#method-add_file)

**

```
add_file()
```

Add a file operation, automatically categorizing by extension.

### Method: `add_file_from_discovered`
[Section titled “Method: add_file_from_discovered”](#method-add_file_from_discovered)

**

```
add_file_from_discovered()
```

Add a file operation using a DiscoveredFile (more efficient).

This method is more efficient than add_file() when you already have a DiscoveredFile object, as it avoids redundant ExtCategory.from_file() calls.

Args: discovered_file: DiscoveredFile with pre-computed ext_category operation: Type of operation performed (indexed, retrieved, etc.)

### Method: `add_other_files`
[Section titled “Method: add_other_files”](#method-add_other_files)

**

```
add_other_files()
```

Add files to the ‘other’ category.

### Method: `get_summary_by_category`
[Section titled “Method: get_summary_by_category”](#method-get_summary_by_category)

**

```
get_summary_by_category()
```

Get a summary of unique files and operations by category.

### Method: `get_summary_by_language`
[Section titled “Method: get_summary_by_language”](#method-get_summary_by_language)

**

```
get_summary_by_language()
```

Get a summary of statistics by language across all categories.

## Class: `Identifier`
[Section titled “Class: Identifier”](#class-identifier)
A named tuple for request identifiers.

## Class: `SessionStatistics`
[Section titled “Class: SessionStatistics”](#class-sessionstatistics)
Statistics for tracking session performance and usage.

### Method: `add_chunk_from_codechunk`
[Section titled “Method: add_chunk_from_codechunk”](#method-add_chunk_from_codechunk-1)

**

```
add_chunk_from_codechunk()
```

Add chunk statistics using a CodeChunk object (efficient).

This method tracks chunk creation statistics at the session level, including chunk type, size, and language distribution.

Args: chunk: CodeChunk with pre-computed ext_category and metadata operation: Type of operation performed (usually “processed” for chunks)

### Method: `add_failed_request`
[Section titled “Method: add_failed_request”](#method-add_failed_request)

**

```
add_failed_request()
```

Add a failed request count.

### Method: `add_file_from_discovered`
[Section titled “Method: add_file_from_discovered”](#method-add_file_from_discovered-1)

**

```
add_file_from_discovered()
```

Add a file operation using a DiscoveredFile (more efficient).

This method is more efficient than add_file() when you already have a DiscoveredFile object, as it avoids redundant ExtCategory.from_file() calls.

Args: discovered_file: DiscoveredFile with pre-computed ext_category operation: Type of operation performed (indexed, retrieved, etc.)

### Method: `add_file_operation`
[Section titled “Method: add_file_operation”](#method-add_file_operation)

**

```
add_file_operation()
```

Add a file operation to the index statistics.

### Method: `add_file_operations`
[Section titled “Method: add_file_operations”](#method-add_file_operations)

**

```
add_file_operations()
```

Add multiple file operations to the index statistics.

### Method: `add_file_operations_by_extcategory`
[Section titled “Method: add_file_operations_by_extcategory”](#method-add_file_operations_by_extcategory)

**

```
add_file_operations_by_extcategory()
```

Add file operations to the index statistics by extension category.

### Method: `add_other_files`
[Section titled “Method: add_other_files”](#method-add_other_files-1)

**

```
add_other_files()
```

Add files to the ‘other’ category in index statistics.

### Method: `add_successful_request`
[Section titled “Method: add_successful_request”](#method-add_successful_request)

**

```
add_successful_request()
```

Add a successful request count.

### Method: `add_token_usage`
[Section titled “Method: add_token_usage”](#method-add_token_usage)

**

```
add_token_usage()
```

Add token usage statistics.

### Method: `get_timing_statistics`
[Section titled “Method: get_timing_statistics”](#method-get_timing_statistics)

**

```
get_timing_statistics()
```

Get the current timing statistics.

### Method: `get_token_usage`
[Section titled “Method: get_token_usage”](#method-get_token_usage)

**

```
get_token_usage()
```

Get the current token usage statistics.

### Method: `log_request_from_context`
[Section titled “Method: log_request_from_context”](#method-log_request_from_context)

**

```
log_request_from_context()
```

Log a request from the given context.

Note: This is fastmcp.Context, *not* fastmcp.middleware.MiddlewareContext

### Method: `report`
[Section titled “Method: report”](#method-report)

**

```
report()
```

Generate a report of the current statistics.

### Method: `request_in_log`
[Section titled “Method: request_in_log”](#method-request_in_log)

**

```
request_in_log()
```

Check if a request ID is in the successful or failed request logs.

### Method: `reset`
[Section titled “Method: reset”](#method-reset)

**

```
reset()
```

Reset all statistics to their initial state.

### Method: `serialize_token_statistics`
[Section titled “Method: serialize_token_statistics”](#method-serialize_token_statistics)

**

```
serialize_token_statistics()
```

Serialize the token statistics to a dictionary.

### Method: `update_failover_stats`
[Section titled “Method: update_failover_stats”](#method-update_failover_stats)

**

```
update_failover_stats()
```

Update failover statistics.

Args: failover_active: Set failover active status increment_failover_count: Increment the failover count failover_time_seconds: Add to total failover time last_failover_time: Set last failover timestamp increment_backup_syncs: Increment backup sync counter increment_sync_back_ops: Increment sync-back operations counter chunks_synced_back: Add to chunks synced back count active_store_type: Set active store type (primary/backup) primary_circuit_breaker_state: Set circuit breaker state backup_file_exists: Set backup file existence flag backup_file_size_bytes: Set backup file size chunks_in_failover: Set number of chunks in failover

## Class: `TimingStatistics`
[Section titled “Class: TimingStatistics”](#class-timingstatistics)
By-operation timing statistics for CodeWeaver operations.

### Method: `update`
[Section titled “Method: update”](#method-update)

**

```
update()
```

Update the timing statistics for a specific request type.

### Method: `update_http_requests`
[Section titled “Method: update_http_requests”](#method-update_http_requests)

**

```
update_http_requests()
```

Update the timing statistics for a specific HTTP request type.

## Class: `TokenCategory`
[Section titled “Class: TokenCategory”](#class-tokencategory)
Categories of token usage for vector store operations.

## Class: `TokenCost`
[Section titled “Class: TokenCost”](#class-tokencost)
Cost categories for token usage.

### Method: `expense`
[Section titled “Method: expense”](#method-expense)

**

```
expense()
```

Calculate the expense for a given number of tokens.

## Class: `TokenCounter`
[Section titled “Class: TokenCounter”](#class-tokencounter)
A counter for tracking token usage by operation.

## Function: `add_failed_request`
[Section titled “Function: add_failed_request”](#function-add_failed_request)

**

```
add_failed_request()
```

Add a failed request to the log.

## Function: `add_successful_request`
[Section titled “Function: add_successful_request”](#function-add_successful_request)

**

```
add_successful_request()
```

Add a successful request to the log.

## Function: `get_session_statistics`
[Section titled “Function: get_session_statistics”](#function-get_session_statistics)

**

```
get_session_statistics()
```

Get the current session statistics.

## Function: `normalize_language`
[Section titled “Function: normalize_language”](#function-normalize_language)

**

```
normalize_language()
```

Normalize a language string to a SemanticSearchLanguage or ConfigLanguage.

## Function: `record_timed_http_request`
[Section titled “Function: record_timed_http_request”](#function-record_timed_http_request)

**

```
record_timed_http_request()
```

Record the time taken for an HTTP request of a given type.

## Function: `timed_http`
[Section titled “Function: timed_http”](#function-timed_http)

**

```
timed_http()
```

Decorator to time HTTP endpoints and record success/failure counts.

Measures end-to-end handler execution time, records duration in milliseconds, and increments HTTP success/failed counters based on response status.