Create repo
This commit is contained in:
commit
8b32ec55b7
6 changed files with 1890 additions and 0 deletions
11
README.md
Normal file
11
README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Simgrid platform to dot file converter
|
||||
|
||||
**sgp2dot** is a [Simgrid](https://simgrid.org) platform to [Graphiz dot file](http://graphviz.org/) convert implemented in Lisp. It require:
|
||||
- Common Lisp (supporting asdf)
|
||||
- s-xml
|
||||
|
||||
How to use it ? Compile it using the following lisp code:
|
||||
|
||||
> (asdf:operate :build-op "sgp2dot")
|
||||
Finally invoke `./sgp2dot-cl.lisp <platform-file> <output-dot-file>`
|
||||
|
42
convert.lisp
Normal file
42
convert.lisp
Normal file
|
@ -0,0 +1,42 @@
|
|||
(in-package :sgp2dot)
|
||||
|
||||
|
||||
(defparameter *hosts* nil "Contains hosts found in the Simgrid XML platform file")
|
||||
(defparameter *links* nil "Contains links found in the Simgrid XML platform file")
|
||||
|
||||
|
||||
(defun handle-host (attributes)
|
||||
(push (cdr (assoc :|id| attributes)) *hosts*))
|
||||
|
||||
(defun handle-route (attributes)
|
||||
(push `(,(cdr (assoc :|src| attributes)) . ,(cdr (assoc :|dst| attributes))) *links* ))
|
||||
|
||||
(defun handle-element (name attributes seed)
|
||||
(declare (ignore seed)) ; Ignore "unused argument" warning
|
||||
(cond ((eq name :|host|) (handle-host attributes))
|
||||
((eq name :|route|) (handle-route attributes))))
|
||||
|
||||
|
||||
;;; Program entry point
|
||||
(defun convert (platform dot-file)
|
||||
"Parse Simgrid platform then write it into a dot file."
|
||||
(let ((xml-parser (make-instance 'xml-parser-state
|
||||
:seed (cons 0 0)
|
||||
:new-element-hook #'handle-element)))
|
||||
;; Parse Simgrid Platform
|
||||
(with-open-file (stream-file platform :direction :input)
|
||||
(start-parse-xml stream-file xml-parser))
|
||||
;; Write parsed host and list to a dot file
|
||||
(with-open-file (stream dot-file :direction :output :if-exists :overwrite :if-does-not-exist :create)
|
||||
;; Add header
|
||||
(format stream "graph Network {~%")
|
||||
(format stream "graph [outputorder=\"edgesfirst\"]")
|
||||
(format stream "node [shape=circle,style=filled]")
|
||||
;; Add links
|
||||
(dolist (link *links*)
|
||||
(format stream "~t~a -- ~a ~%" (car link) (cdr link)))
|
||||
;; Add hosts
|
||||
(dolist (host *hosts*)
|
||||
(format stream "~t~a~%" host))
|
||||
;; Add footer
|
||||
(format stream "}~%"))))
|
4
packages.lisp
Normal file
4
packages.lisp
Normal file
|
@ -0,0 +1,4 @@
|
|||
(defpackage :sgp2dot
|
||||
(:use :common-lisp :s-xml)
|
||||
(:export :convert :main))
|
||||
|
1815
platform.xml
Normal file
1815
platform.xml
Normal file
File diff suppressed because it is too large
Load diff
8
sgp2dot-cl.lisp
Executable file
8
sgp2dot-cl.lisp
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/sbcl --script
|
||||
|
||||
(load "./sgp2dot.lisp")
|
||||
|
||||
(if (eq (length sb-ext:*posix-argv*) 3)
|
||||
(sgp2dot:convert (second sb-ext:*posix-argv*) (third sb-ext:*posix-argv*))
|
||||
(format t "Usage: ./sgp2dot-cl.lisp <platform-file> <output-dot-file>~%"))
|
||||
|
10
sgp2dot.asd
Normal file
10
sgp2dot.asd
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
(defsystem "sgp2dot"
|
||||
:description "Generate a dot file (graphiz) to the corresponding Simgrid platform"
|
||||
:version "0.0.1"
|
||||
:depends-on ("s-xml")
|
||||
:build-operation "monolithic-concatenate-source-op"
|
||||
:build-pathname "sgp2dot"
|
||||
:components ((:file "packages")
|
||||
(:file "convert")))
|
||||
|
Loading…
Add table
Reference in a new issue