Skip to content

Commit

Permalink
Renamed file varaibles
Browse files Browse the repository at this point in the history
  • Loading branch information
skrakau committed Jan 11, 2024
1 parent dd4a59a commit b8653a9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions docs/usage/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You can adjust the nf-co2footprint plugin parameters in your config file as foll
def co2_timestamp = new java.util.Date().format( 'yyyy-MM-dd_HH-mm-ss')
co2footprint {
file = "${params.outdir}/co2footprint_trace_${co2_timestamp}.txt"
traceFile = "${params.outdir}/co2footprint_trace_${co2_timestamp}.txt"
reportFile = "${params.outdir}/co2footprint_report_${co2_timestamp}.html"
ci = 300
pue = 1.4
Expand All @@ -26,7 +26,7 @@ nextflow run nextflow-io/hello -c nextflow.config

The following parameters are currently available:

- `file`: Name of the TXT carbon footprint report containing the energy consumption, the estimated CO<sub>2</sub> emission and other relevant metrics for each task.
- `traceFile`: Name of the TXT carbon footprint report containing the energy consumption, the estimated CO<sub>2</sub> emission and other relevant metrics for each task.
Default: `co2footprint_trace_<timestamp>.txt`.
- `summaryFile`: Name of the TXT carbon footprint summary file containing the total energy consumption and the total estimated CO<sub>2</sub> emission of the pipeline run.
Default: `co2footprint_summary_<timestamp>.txt`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import groovy.util.logging.Slf4j
* In this plugin, the user can configure the output file names of the CO2 footprint calculations
*
* co2footprint {
* file = "co2footprint_trace.txt"
* traceFile = "co2footprint_trace.txt"
* summaryFile = "co2footprint_summary.txt"
* ci = 300
* pue = 1.4
Expand All @@ -27,7 +27,7 @@ import groovy.util.logging.Slf4j
@PackageScope
class CO2FootprintConfig {

final private String file
final private String traceFile
final private String summaryFile
final private String reportFile
final private String location
Expand Down Expand Up @@ -74,7 +74,7 @@ class CO2FootprintConfig {

CO2FootprintConfig(Map map, Map<String, Double> cpuData){
def config = map ?: Collections.emptyMap()
file = config.file ?: CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_FILE_NAME
traceFile = config.traceFile ?: CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_TRACE_FILE_NAME
summaryFile = config.summaryFile ?: CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_SUMMARY_FILE_NAME
reportFile = config.reportFile ?: CO2FootprintFactory.CO2FootprintReportObserver.DEF_REPORT_FILE_NAME
ignoreCpuModel = config.ignoreCpuModel ?: false
Expand All @@ -98,7 +98,7 @@ class CO2FootprintConfig {
loadCustomCpuTdpData(cpuData, config.customCpuTdpFile)
}

String getFile() { file }
String getTraceFile() { traceFile }
String getSummaryFile() { summaryFile }
String getReportFile() { reportFile }
Boolean getIgnoreCpuModel() { ignoreCpuModel }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class CO2FootprintFactory implements TraceObserverFactory {

final result = new ArrayList(2)
// Generate CO2 footprint text output files
def co2eFile = (this.config.getFile() as Path).complete()
def co2eTraceFile = (this.config.getTraceFile() as Path).complete()
def co2eSummaryFile = (this.config.getSummaryFile() as Path).complete()

result.add( new CO2FootprintTextFileObserver(co2eFile, co2eSummaryFile) )
result.add( new CO2FootprintTextFileObserver(co2eTraceFile, co2eSummaryFile) )

// Generate CO2 footprint report with box-plot
def co2eReport = (this.config.getReportFile() as Path).complete()
Expand Down Expand Up @@ -243,7 +243,7 @@ class CO2FootprintFactory implements TraceObserverFactory {
class CO2FootprintTextFileObserver implements TraceObserver {

// TODO which files should we generate here?
public static final String DEF_FILE_NAME = "co2footprint_trace_${TraceHelper.launchTimestampFmt()}.txt"
public static final String DEF_TRACE_FILE_NAME = "co2footprint_trace_${TraceHelper.launchTimestampFmt()}.txt"
public static final String DEF_SUMMARY_FILE_NAME = "co2footprint_summary_${TraceHelper.launchTimestampFmt()}.txt"

/**
Expand All @@ -252,15 +252,15 @@ class CO2FootprintFactory implements TraceObserverFactory {
boolean overwrite = true

/**
* The path where the file is created. It is set by the object constructor
* The path where the files are created. It is set by the object constructor
*/
private Path co2ePath
private Path co2eTracePath
private Path co2eSummaryPath

/**
* The actual file object
*/
private PrintWriter co2eFile
private PrintWriter co2eTraceFile
private PrintWriter co2eSummaryFile


Expand All @@ -271,17 +271,17 @@ class CO2FootprintFactory implements TraceObserverFactory {
Map<TaskId, TraceRecord> current = new ConcurrentHashMap<>()


private Agent<PrintWriter> writer
private Agent<PrintWriter> traceWriter
private Agent<PrintWriter> summaryWriter


/**
* Create the trace observer
*
* @param co2eFile A path to the file where save the CO2 emission data
* @param co2eTraceFile A path to the file where save the CO2 emission data
*/
CO2FootprintTextFileObserver(Path co2eFile, Path co2eSummaryFile) {
this.co2ePath = co2eFile
CO2FootprintTextFileObserver(Path co2eTraceFile, Path co2eSummaryFile) {
this.co2eTracePath = co2eTraceFile
this.co2eSummaryPath = co2eSummaryFile
}

Expand All @@ -295,10 +295,10 @@ class CO2FootprintFactory implements TraceObserverFactory {
*/
@Override
void onFlowCreate(Session session) {
log.debug "Workflow started -- co2e file: ${co2ePath.toUriString()}"
log.debug "Workflow started -- co2e traceFile: ${co2eTracePath.toUriString()}"

// make sure parent path exists
def parent = co2ePath.getParent()
def parent = co2eTracePath.getParent()
if (parent)
Files.createDirectories(parent)

Expand All @@ -307,15 +307,15 @@ class CO2FootprintFactory implements TraceObserverFactory {
Files.createDirectories(summaryParent)

// create a new trace file
co2eFile = new PrintWriter(TraceHelper.newFileWriter(co2ePath, overwrite, 'co2footprint'))
co2eTraceFile = new PrintWriter(TraceHelper.newFileWriter(co2eTracePath, overwrite, 'co2footprint'))
co2eSummaryFile = new PrintWriter(TraceHelper.newFileWriter(co2eSummaryPath, overwrite, 'co2footprintsummary'))

// launch the agent
writer = new Agent<PrintWriter>(co2eFile)
traceWriter = new Agent<PrintWriter>(co2eTraceFile)
summaryWriter = new Agent<PrintWriter>(co2eSummaryFile)

String cpu_model_string = config.getIgnoreCpuModel()? "" : "cpu_model\t"
writer.send { co2eFile.println(
traceWriter.send { co2eTraceFile.println(
"task_id\t"
+ "name\t"
+ "status\t"
Expand All @@ -327,7 +327,7 @@ class CO2FootprintFactory implements TraceObserverFactory {
+ cpu_model_string
+ "cpu_usage\t"
+ "requested_memory"
); co2eFile.flush()
); co2eTraceFile.flush()
}
}

Expand All @@ -336,10 +336,10 @@ class CO2FootprintFactory implements TraceObserverFactory {
*/
@Override
void onFlowComplete() {
log.debug "Workflow completed -- saving trace file"
log.debug "Workflow completed -- saving trace and summary file"

// wait for termination and flush the agent content
writer.await()
traceWriter.await()

co2eSummaryFile.println("Total CO2e footprint measures of this workflow run")
co2eSummaryFile.println("CO2e emissions: ${HelperFunctions.convertToReadableUnits(total_co2,3)}g")
Expand All @@ -350,9 +350,9 @@ class CO2FootprintFactory implements TraceObserverFactory {
co2eSummaryFile.close()

// write the remaining records
current.values().each { taskId, record -> co2eFile.println("${taskId}\t-") }
co2eFile.flush()
co2eFile.close()
current.values().each { taskId, record -> co2eTraceFile.println("${taskId}\t-") }
co2eTraceFile.flush()
co2eTraceFile.close()

// Log warnings
if( hasWarnings() ) {
Expand Down Expand Up @@ -427,7 +427,7 @@ class CO2FootprintFactory implements TraceObserverFactory {

// save to the file
String cpu_model_string = config.getIgnoreCpuModel()? "" : "${trace.get('cpu_model').toString()}\t"
writer.send {
traceWriter.send {
PrintWriter it -> it.println(
"${taskId}\t"
+ "${trace.get('name').toString()}\t"
Expand Down Expand Up @@ -480,7 +480,7 @@ class CO2FootprintFactory implements TraceObserverFactory {

// save to the file
String cpu_model_string = config.getIgnoreCpuModel()? "" : "${trace.get('cpu_model').toString()}\t"
writer.send {
traceWriter.send {
PrintWriter it -> it.println(
"${taskId}\t"
+ "${trace.get('name').toString()}\t"
Expand Down

0 comments on commit b8653a9

Please sign in to comment.