Skip to content

Commit

Permalink
Adding TLC stats to cimetrics (#5807)
Browse files Browse the repository at this point in the history
  • Loading branch information
heidihoward authored Nov 7, 2023
1 parent 1d52533 commit 6e0f675
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 3 deletions.
12 changes: 12 additions & 0 deletions .azure-pipelines-templates/model_checking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ jobs:
workingDirectory: tla
displayName: MCccfraftWithReconfig.cfg

- script: |
set -ex
python3.8 -m venv env
source env/bin/activate
python -m pip install -r requirements.txt
ls ../tla/*.json
python3 upload_tlc_stats.py 3node_fixed ../tla/MCccfraft_stats.json
env:
METRICS_MONGO_CONNECTION: $(METRICS_MONGO_CONNECTION)
workingDirectory: tests
displayName: Uploading TLC stats to cimetrics
- task: PublishPipelineArtifact@1
inputs:
artifactName: "Model Checking Traces"
Expand Down
1 change: 1 addition & 0 deletions metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ monitoring_span: 150
groups:
"SGX": ".*_sgx_.*"
"Virtual": ".*_virtual_.*"
"TLC": "tlc_.*"
"Others": ".*"
46 changes: 46 additions & 0 deletions tests/upload_tlc_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache 2.0 License.

import json
import os
import argparse
import cimetrics.upload

from loguru import logger as LOG


def run(test_label, filename):
if os.path.exists(filename):
with open(filename) as f:
data = json.load(f)
duration_sec = data["duration"]
dstates = data["distinct"]
LOG.info(
"Uploading metrics for {} - duration: {}, distinct states: {}",
test_label,
duration_sec,
dstates,
)
with cimetrics.upload.metrics(complete=False) as metrics:
metrics.put(f"tlc_{test_label}_duration_s", duration_sec)
metrics.put(f"tlc_{test_label}_states", dstates)

else:
LOG.warning(f"Could not find file {filename}: skipping metrics upload")


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Upload TLC stats to cimetrics.")

parser.add_argument(
"test_label",
help="test name to upload metrics under",
)

parser.add_argument(
"filename",
help="TLC stats JSON file to upload",
)

args = parser.parse_args()
run(args.test_label, args.filename)
3 changes: 2 additions & 1 deletion tla/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ tools/
*.dot
*TTrace*.tla
*TTrace*.bin
**/states.dump*
*_stats.json
**/states.dump*
14 changes: 14 additions & 0 deletions tla/StatsFile.tla
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---- MODULE StatsFile----
EXTENDS TLC, Json, Sequences

\* Filename to write TLC stats to
CONSTANT StatsFilename
ASSUME StatsFilename \in STRING

\* Writes TLC stats (such as number of states and duration) to StatsFilename in ndJson format
\* Specify WriteStatsFile as a postcondition to write the stats file at the end of model checking
WriteStatsFile ==
/\ PrintT("Writing stats to file: " \o StatsFilename)
/\ ndJsonSerialize(StatsFilename, <<TLCGet("stats")>>)

====
5 changes: 5 additions & 0 deletions tla/consensus/MCccfraft.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ CONSTANTS
MaxTermLimit = 1
MaxCommitsNotified = 0
RequestLimit = 3

StatsFilename = "MCccfraft_stats.json"

Timeout <- MCTimeout
Send <- MCSend
Expand Down Expand Up @@ -50,6 +52,9 @@ VIEW View
CHECK_DEADLOCK
FALSE

POSTCONDITION
WriteStatsFile

PROPERTIES
CommittedLogAppendOnlyProp
MonotonicTermProp
Expand Down
5 changes: 4 additions & 1 deletion tla/consensus/MCccfraft.tla
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---------- MODULE MCccfraft ----------
EXTENDS ccfraft, TLC
EXTENDS ccfraft, StatsFile

CONSTANTS
NodeOne, NodeTwo, NodeThree
Expand All @@ -21,6 +21,7 @@ ASSUME MaxCommitsNotified \in Nat
CONSTANT RequestLimit
ASSUME RequestLimit \in Nat


ToServers ==
UNION Range(Configurations)

Expand Down Expand Up @@ -137,4 +138,6 @@ AllReconfigurationsCommitted ==
DebugAllReconfigurationsReachableInv ==
~AllReconfigurationsCommitted



===================================
5 changes: 5 additions & 0 deletions tla/consensus/MCccfraftAtomicReconfig.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ CONSTANTS
MaxTermLimit = 4
MaxCommitsNotified = 2
RequestLimit = 3

StatsFilename = "MCccfraftAtomicReconfig_stats.json"

Timeout <- MCTimeout
Send <- MCSend
Expand Down Expand Up @@ -50,6 +52,9 @@ VIEW View
CHECK_DEADLOCK
FALSE

POSTCONDITION
WriteStatsFile

PROPERTIES
CommittedLogAppendOnlyProp
MonotonicTermProp
Expand Down
7 changes: 6 additions & 1 deletion tla/consensus/MCccfraftWithReconfig.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ CONSTANTS

MaxTermLimit = 3
MaxCommitsNotified = 2
RequestLimit = 3
RequestLimit = 2

StatsFilename = "MCccfraftWithReconfig_stats.json"

Timeout <- MCTimeout
Send <- MCSend
Expand Down Expand Up @@ -50,6 +52,9 @@ VIEW View
CHECK_DEADLOCK
FALSE

POSTCONDITION
WriteStatsFile

PROPERTIES
CommittedLogAppendOnlyProp
MonotonicTermProp
Expand Down

0 comments on commit 6e0f675

Please sign in to comment.