Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ThreadDumpAction.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2020-2021 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package org.sleuthkit.autopsy.actions;
20
21import org.sleuthkit.autopsy.coreutils.Desktop;
22import java.awt.event.ActionListener;
23import java.io.BufferedWriter;
24import java.io.File;
25import java.io.FileWriter;
26import java.io.IOException;
27import java.nio.file.Path;
28import java.nio.file.Paths;
29import java.util.concurrent.ExecutionException;
30import java.util.logging.Level;
31import javax.swing.SwingWorker;
32import org.openide.awt.ActionID;
33import org.openide.awt.ActionReference;
34import org.openide.awt.ActionRegistration;
35import org.openide.util.HelpCtx;
36import org.openide.util.NbBundle.Messages;
37import org.openide.util.actions.CallableSystemAction;
38import org.sleuthkit.autopsy.casemodule.Case;
39import org.sleuthkit.autopsy.coreutils.Logger;
40import org.sleuthkit.autopsy.coreutils.PlatformUtil;
41import org.sleuthkit.autopsy.coreutils.ThreadUtils;
42import org.sleuthkit.autopsy.coreutils.TimeStampUtils;
43
49@ActionID(category = "Help", id = "org.sleuthkit.autopsy.actions.ThreadDumpAction")
50@ActionRegistration(displayName = "#CTL_DumpThreadAction", lazy = false)
51@ActionReference(path = "Menu/Help", position = 1750)
52@Messages({
53 "CTL_DumpThreadAction=Thread Dump"
54})
55public final class ThreadDumpAction extends CallableSystemAction implements ActionListener {
56
57 private static final long serialVersionUID = 1L;
58 private static final Logger logger = Logger.getLogger(ThreadDumpAction.class.getName());
59
60 @Override
61 public void performAction() {
62 (new ThreadDumper()).run();
63 }
64
65 @Override
66 public String getName() {
67 return Bundle.CTL_DumpThreadAction();
68 }
69
70 @Override
71 public HelpCtx getHelpCtx() {
72 return HelpCtx.DEFAULT_HELP;
73 }
74
79 private final class ThreadDumper extends SwingWorker<File, Void> {
80
81 @Override
82 protected File doInBackground() throws Exception {
83 return createThreadDump();
84 }
85
86 @Override
87 protected void done() {
88 File dumpFile = null;
89 try {
90 dumpFile = get();
91 Desktop.getDesktop().open(dumpFile);
92 } catch (ExecutionException | InterruptedException ex) {
93 logger.log(Level.SEVERE, "Failure occurred while creating thread dump file", ex);
94 } catch (IOException ex) {
95 if (dumpFile != null) {
96 logger.log(Level.WARNING, "Failed to open thread dump file in external viewer: " + dumpFile.getAbsolutePath(), ex);
97 } else {
98 logger.log(Level.SEVERE, "Failed to create thread dump file.", ex);
99 }
100 }
101 }
102
108 private File createThreadDump() throws IOException {
109
110 // generate thread dump
111 String threadDump = ThreadUtils.generateThreadDump();
112
113 File dumpFile = createFilePath().toFile();
114 try (BufferedWriter writer = new BufferedWriter(new FileWriter(dumpFile, true))) {
115 writer.write(threadDump);
116 }
117
118 return dumpFile;
119 }
120
126 private Path createFilePath() {
127 String fileName = "ThreadDump_" + TimeStampUtils.createTimeStamp() + ".txt";
128 if (Case.isCaseOpen()) {
129 return Paths.get(Case.getCurrentCase().getLogDirectoryPath(), fileName);
130 }
131 return Paths.get(PlatformUtil.getLogDirectory(), fileName);
132 }
133 }
134
135}
synchronized static Logger getLogger(String name)
Definition Logger.java:124

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.