Skip to main content
Inspiring
October 14, 2022
Answered

manage cpu % during script

  • October 14, 2022
  • 2 replies
  • 390 views

hi, it s possible to survey the % cpu during a script? if over xx%, put script in pause?

This topic has been closed for replies.
Correct answer Loic.Aigon

Actually you might check for CPU Usage. Here is a snippet from the IDS SDK but the same method can be found with InDesign Client : 

 

// Get the process cpu usage and vm statistics
	this.cpuTime = app.performanceMetric(PerformanceMetricOptions.CPU_TIME);
	this.sysCpuTime = app.performanceMetric(PerformanceMetricOptions.OVERALL_SYSTEM_CPU);
	this.userCpuTime = app.performanceMetric(PerformanceMetricOptions.OVERALL_USER_CPU);
	this.initVMSize = app.performanceMetric(PerformanceMetricOptions.VIRTUAL_MEMORY_SIZE);
	this.resMemSize = app.performanceMetric(PerformanceMetricOptions.RESIDENT_MEMORY_SIZE);

 

But Pausing a script might not be possible. You can exit your script though if you see the CPU go wild.

HTH

Loic

2 replies

Loic.Aigon
Loic.AigonCorrect answer
Legend
October 17, 2022

Actually you might check for CPU Usage. Here is a snippet from the IDS SDK but the same method can be found with InDesign Client : 

 

// Get the process cpu usage and vm statistics
	this.cpuTime = app.performanceMetric(PerformanceMetricOptions.CPU_TIME);
	this.sysCpuTime = app.performanceMetric(PerformanceMetricOptions.OVERALL_SYSTEM_CPU);
	this.userCpuTime = app.performanceMetric(PerformanceMetricOptions.OVERALL_USER_CPU);
	this.initVMSize = app.performanceMetric(PerformanceMetricOptions.VIRTUAL_MEMORY_SIZE);
	this.resMemSize = app.performanceMetric(PerformanceMetricOptions.RESIDENT_MEMORY_SIZE);

 

But Pausing a script might not be possible. You can exit your script though if you see the CPU go wild.

HTH

Loic

Inspiring
November 2, 2022

hi my idea is create an alert() is cpu is over 50%

 

i would like do same with memory?

into your code wich value is % of cpu?

 

because after 1hour of script, indesign continue to "crash" without reason

rob day
Community Expert
Community Expert
November 2, 2022

I missed the application PerformanceMetricOptions. The full list is here:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PerformanceMetricOptions.html

 

$.writeln(app.performanceMetric(PerformanceMetricOptions.CPU_TIME))
$.writeln(app.performanceMetric(PerformanceMetricOptions.OVERALL_SYSTEM_CPU))
$.writeln(app.performanceMetric(PerformanceMetricOptions.OVERALL_USER_CPU))

 

rob day
Community Expert
Community Expert
October 14, 2022

I don’t think so. You can look at the ExtendScript $ object API here:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#$.html