1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/*******************************************************************************
* Copyright (c) 2010 Intel Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel - initial API and implementation
*******************************************************************************/
package org.yocto.sdk.remotetools.actions;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.yocto.sdk.remotetools.views.BaseFileView;
public class PowertopModel extends BaseModel {
private static final String REMOTE_EXEC = "/tmp/yocto_tool.sh";
private static final String LOCAL_SCRIPT = "resources/yocto_tool.sh";
private static final String REMOTE_FILE_PREFIX = "/tmp/yocto-powertop-";
private static final String LOCAL_FILE_SUFFIX = ".local";
private static final String TASK_NAME = "powertop command";
private Float time;
Display display;
public PowertopModel(IHost host, Float time, Display display) {
super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC);
this.time=time;
this.display=display;
}
@Override
public void postProcess(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
try {
new File(localFile).delete();
}catch (Exception e) {
}
}
private void generateData(IProgressMonitor monitor) throws Exception {
String currentDate = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime()).toString();
remoteFile = new String(REMOTE_FILE_PREFIX + currentDate);
localFile = new String(remoteFile + LOCAL_FILE_SUFFIX);
String args = "start -l " + remoteFile + " powertop --debug --time " + time.toString();
runRemoteShellExec(monitor, args, true);
}
@Override
public void process(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
monitor.beginTask("Running powertop", 100);
try {
//running powertop
monitor.subTask("Generating powertop data file remotely");
generateData(new SubProgressMonitor(monitor,30));
//download datafile
monitor.subTask("Downloading powertop data file");
getDataFile(new SubProgressMonitor(monitor,30));
//show it in the powertop view
display.syncExec(new Runnable() {
public void run() {
BaseFileView view;
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
view=(BaseFileView) page.showView("org.yocto.sdk.remotetools.views.PowerTopView");
}catch (PartInitException e) {
e.printStackTrace();
return;
}
view.setInput(localFile);
page.bringToTop(view);
}
});
}catch (InterruptedException e){
throw e;
}catch (InvocationTargetException e) {
throw e;
}catch (Exception e){
throw new InvocationTargetException(e, e.getMessage());
}finally {
monitor.done();
}
}
}
|