Commit 4c4f651f authored by Mario Hock's avatar Mario Hock

more logging options (environment and nics)

parent 20f7647b
......@@ -7,6 +7,7 @@ import time
import sys
import traceback
import math
import json
from collections import namedtuple
......@@ -184,22 +185,47 @@ if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
## Logging
parser.add_argument("-l", "--logging", action="store_true",
help="Enables logging.")
parser.add_argument("-c", "--comment",
help="A comment that is stored in the logfile. (See --logging.)")
parser.add_argument("--path", default="/tmp/cpunetlog",
help="Path where the log files are stored in. (See --logging.)")
parser.add_argument("-e", "--environment",
help="JSON file that holds arbitrary environment context. (This can be seen as a structured comment field.)")
# NICs
parser.add_argument("--nics", nargs='+',
help="The network interfaces that should be displayed (and logged, see --logging).")
args = parser.parse_args()
## NICs
monitored_nics = nics
if ( args.nics ):
assert( set(nics).issuperset(args.nics) )
monitored_nics = args.nics
## Read environment file (if given).
if ( args.environment ):
with open(args.environment) as f:
environment = json.load(f)
else:
environment = None
## Get hostname (for display and logging).
osdetails = tuple(os.uname())
ostype = osdetails[0]
hostname = osdetails[1]
## Logging
logging_manager = LoggingManager( psutil.NUM_CPUS, nics, hostname, args.comment, args.path )
logging_manager = LoggingManager( psutil.NUM_CPUS, monitored_nics, hostname, environment, args.comment, args.path )
if args.logging:
logging_manager.enable_measurement_logger()
......
......@@ -22,7 +22,7 @@ class MeasurementLogger:
## Initialization ##
def __init__(self, num_cpus, nics, begin, hostname, comment, filename):
def __init__(self, num_cpus, nics, begin, hostname, environment, comment, filename):
## Attributes
self.num_cpus = num_cpus
self.nics = nics
......@@ -40,6 +40,7 @@ class MeasurementLogger:
self.type_string,
begin,
hostname,
environment,
comment)
self.csv_header = self._create_csv_header(self.json_header)
......@@ -89,7 +90,7 @@ class MeasurementLogger:
## TODO Move this outside the class?
def _create_json_header(self, class_names, class_defs, type, begin, hostname, comment):
def _create_json_header(self, class_names, class_defs, type, begin, hostname, environment, comment):
top_level = dict()
general = dict()
class_definitions = dict()
......@@ -100,6 +101,7 @@ class MeasurementLogger:
general["Comment"] = comment
general["Date"] = begin
general["Hostname"] = hostname
general["Environment"] = environment
#general["End"] = 0 ## TODO ... can't be written at the beginning of the file!!
#general["Duration"] = 0 ## TODO
top_level["General"] = general
......@@ -246,12 +248,13 @@ class CNLFileWriter:
class LoggingManager:
def __init__(self, num_cpus, nics, hostname, comment, path):
def __init__(self, num_cpus, nics, hostname, environment, comment, path):
self.num_cpus = num_cpus
self.nics = nics
self.comment = comment
self.path = path
self.hostname = hostname
self.environment = environment
if ( path and not os.path.exists(path) ):
os.makedirs(path)
......@@ -275,7 +278,7 @@ class LoggingManager:
# Create Logger.
self.measurement_logger = MeasurementLogger(self.num_cpus, self.nics, [date,t],
self.hostname, self.comment, filename)
self.hostname, self.environment, self.comment, filename)
self.measurement_logger_enabled = True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment