Skip to content

Commit e8cc09f

Browse files
committed
usage logging
1 parent bfac6b0 commit e8cc09f

File tree

7 files changed

+217
-13
lines changed

7 files changed

+217
-13
lines changed

bundles/org.codechecker.eclipse.plugin/build.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ bin.includes = plugin.xml,\
55
.,\
66
icons/,\
77
contexts.xml,\
8-
log4j.properties
8+
log4j.properties,\
9+
resources/
910

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.codechecker.eclipse</groupId>
8+
<artifactId>org.codechecker.eclipse.bundles</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>org.codechecker.eclipse.plugin</artifactId>
13+
<version>0.0.6-SNAPSHOT</version>
14+
<packaging>eclipse-plugin</packaging>
15+
16+
<properties>
17+
<host.log>empty</host.log>
18+
<port.log>0</port.log>
19+
<plugin.version>${project.version}</plugin.version>
20+
</properties>
21+
22+
<build>
23+
<resources>
24+
<resource>
25+
<directory>resources</directory>
26+
<targetPath>resources</targetPath>
27+
<filtering>true</filtering>
28+
<includes>
29+
<include>**/*.properties</include>
30+
</includes>
31+
</resource>
32+
</resources>
33+
</build>
34+
35+
</project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
host=${host.log}
2+
port=${port.log}
3+
version=${plugin.version}

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/init/StartupJob.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
import java.util.HashSet;
44
import java.util.Set;
55

6+
import org.codechecker.eclipse.plugin.CodeCheckerNature;
7+
import org.codechecker.eclipse.plugin.ExternalLogger;
8+
import org.codechecker.eclipse.plugin.Logger;
9+
import org.codechecker.eclipse.plugin.config.CodeCheckerContext;
10+
import org.codechecker.eclipse.plugin.config.global.CcGlobalConfiguration;
11+
import org.codechecker.eclipse.plugin.config.project.CodeCheckerProject;
12+
import org.codechecker.eclipse.plugin.report.job.AnalyzeJob;
13+
import org.codechecker.eclipse.plugin.report.job.JobDoneChangeListener;
14+
import org.codechecker.eclipse.plugin.report.job.PlistParseJob;
15+
import org.codechecker.eclipse.plugin.runtime.SLogger;
16+
import org.codechecker.eclipse.plugin.usage.StatisticUploader;
17+
import org.codechecker.eclipse.plugin.usage.UsageInfo;
18+
import org.codechecker.eclipse.plugin.usage.UsageInfo.CommandType;
619
import org.eclipse.cdt.core.model.CoreModel;
720
import org.eclipse.core.resources.IProject;
821
import org.eclipse.core.resources.IResource;
@@ -24,18 +37,6 @@
2437
import org.eclipse.ui.IWorkbenchWindow;
2538
import org.eclipse.ui.PlatformUI;
2639

27-
import org.codechecker.eclipse.plugin.CodeCheckerNature;
28-
import org.codechecker.eclipse.plugin.ExternalLogger;
29-
import org.codechecker.eclipse.plugin.Logger;
30-
import org.codechecker.eclipse.plugin.config.CcConfiguration;
31-
import org.codechecker.eclipse.plugin.config.CodeCheckerContext;
32-
import org.codechecker.eclipse.plugin.config.global.CcGlobalConfiguration;
33-
import org.codechecker.eclipse.plugin.config.project.CodeCheckerProject;
34-
import org.codechecker.eclipse.plugin.report.job.AnalyzeJob;
35-
import org.codechecker.eclipse.plugin.report.job.JobDoneChangeListener;
36-
import org.codechecker.eclipse.plugin.report.job.PlistParseJob;
37-
import org.codechecker.eclipse.plugin.runtime.SLogger;
38-
3940
/**
4041
* This eclipse job is responsible for registering the Build listener.
4142
*
@@ -83,6 +84,8 @@ public IStatus runInUIThread(IProgressMonitor monitor) {
8384
Logger.log(IStatus.INFO, Logger.getStackTrace(e));
8485
}
8586

87+
new Thread(new StatisticUploader(new UsageInfo(CommandType.started, null))).run();
88+
8689
Logger.log(IStatus.INFO, "adding addResourceChangeListener ");
8790
ResourcesPlugin.getWorkspace().addResourceChangeListener(new ResourceChangeListener(),
8891
IResourceChangeEvent.POST_BUILD | IResourceChangeEvent.POST_CHANGE |
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.codechecker.eclipse.plugin.usage;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.net.DatagramPacket;
6+
import java.net.DatagramSocket;
7+
import java.net.Inet4Address;
8+
import java.util.Properties;
9+
10+
import org.eclipse.core.runtime.FileLocator;
11+
import org.eclipse.core.runtime.Path;
12+
import org.osgi.framework.FrameworkUtil;
13+
14+
import com.google.gson.Gson;
15+
16+
public class StatisticUploader implements Runnable {
17+
18+
private Integer port;
19+
private String host = "none";
20+
private UsageInfo info;
21+
22+
public StatisticUploader(UsageInfo info) {
23+
this.info = info;
24+
}
25+
26+
private void uploadStatistics() {
27+
try (InputStream is = FileLocator.openStream(FrameworkUtil.getBundle(getClass()),
28+
new Path("resources/config.properties"), false)) {
29+
Properties prop = new Properties();
30+
prop.load(is);
31+
host = prop.getProperty("host");
32+
try {
33+
port = Integer.parseInt(prop.getProperty("port"));
34+
} catch (Exception e) {
35+
;
36+
}
37+
} catch (IOException e1) {
38+
;
39+
}
40+
41+
try (DatagramSocket socket = new DatagramSocket()) {
42+
if (port != null) {
43+
DatagramPacket packet = new DatagramPacket(new Gson().toJson(info).getBytes(),
44+
new Gson().toJson(info).getBytes().length,
45+
Inet4Address.getByName(host), port);
46+
socket.send(packet);
47+
}
48+
} catch (IOException e) {
49+
;
50+
}
51+
}
52+
53+
@Override
54+
public void run() {
55+
uploadStatistics();
56+
}
57+
58+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package org.codechecker.eclipse.plugin.usage;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.net.InetAddress;
6+
import java.net.UnknownHostException;
7+
import java.util.Properties;
8+
9+
import org.eclipse.core.runtime.FileLocator;
10+
import org.eclipse.core.runtime.IContributor;
11+
import org.eclipse.core.runtime.IExtension;
12+
import org.eclipse.core.runtime.IExtensionPoint;
13+
import org.eclipse.core.runtime.IExtensionRegistry;
14+
import org.eclipse.core.runtime.Path;
15+
import org.eclipse.core.runtime.Platform;
16+
import org.eclipse.jdt.annotation.Nullable;
17+
import org.osgi.framework.Bundle;
18+
import org.osgi.framework.FrameworkUtil;
19+
20+
public class UsageInfo {
21+
private static final String UNKNOWN = "unknown";
22+
private static final String UNKNOWN_VER = "unknown version";
23+
24+
@SuppressWarnings("unused")
25+
private String machine = UNKNOWN;
26+
@SuppressWarnings("unused")
27+
private String hostname = UNKNOWN;
28+
//@SuppressWarnings("unused")
29+
//private String clangsa = UNKNOWN;
30+
@SuppressWarnings("unused")
31+
private String version = UNKNOWN_VER;
32+
// TODO make this parameter dynamic, from build parameters.
33+
@SuppressWarnings("unused")
34+
private String pluginVersion = UNKNOWN_VER;
35+
@SuppressWarnings("unused")
36+
private String user = UNKNOWN;
37+
@SuppressWarnings("unused")
38+
private CommandType command_type;
39+
//@SuppressWarnings("unused")
40+
//private String clang_tidy = UNKNOWN;
41+
42+
43+
public UsageInfo(CommandType ct, @Nullable String ccVersion) {
44+
StringBuilder tempos = new StringBuilder(System.getProperty("os.name"));
45+
tempos.append(" ").append(System.getProperty("os.version"));
46+
tempos.append(" ").append("/ Eclipse ").append(getEclipseVersion());
47+
machine = tempos.toString();
48+
try {
49+
hostname = InetAddress.getLocalHost().getHostName();
50+
} catch (UnknownHostException ex) {
51+
;
52+
}
53+
if (ccVersion != null)
54+
version = ccVersion;
55+
setPluginVersion();
56+
user = System.getProperty("user.name");
57+
command_type = ct;
58+
}
59+
60+
/**
61+
* Used for returning the eclipse version number. From:
62+
* https://stackoverflow.com/a/28855362/8149485
63+
*
64+
* @return The eclipse version number in 1.2.3.v19700101-0000 format.
65+
*/
66+
private String getEclipseVersion() {
67+
String version = UNKNOWN_VER;
68+
String product = System.getProperty("eclipse.product");
69+
IExtensionRegistry registry = Platform.getExtensionRegistry();
70+
IExtensionPoint point = registry.getExtensionPoint("org.eclipse.core.runtime.products");
71+
if (point != null) {
72+
IExtension[] extensions = point.getExtensions();
73+
for (IExtension ext : extensions)
74+
if (product.equals(ext.getUniqueIdentifier())) {
75+
IContributor contributor = ext.getContributor();
76+
if (contributor != null) {
77+
Bundle bundle = Platform.getBundle(contributor.getName());
78+
if (bundle != null)
79+
version = bundle.getVersion().toString();
80+
}
81+
}
82+
}
83+
return version;
84+
}
85+
86+
private void setPluginVersion() {
87+
try (InputStream is = FileLocator.openStream(FrameworkUtil.getBundle(getClass()),
88+
new Path("resources/config.properties"), false)) {
89+
Properties prop = new Properties();
90+
prop.load(is);
91+
pluginVersion = prop.getProperty("version");
92+
} catch (IOException e1) {
93+
e1.printStackTrace();
94+
}
95+
}
96+
97+
public enum CommandType {
98+
started, analyze_started
99+
}
100+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Usage logging.
3+
*/
4+
package org.codechecker.eclipse.plugin.usage;

0 commit comments

Comments
 (0)