Skip to content

Commit

Permalink
Add an option to show verbose debugging logs.
Browse files Browse the repository at this point in the history
Turns out the event handler (BlazeCommandEventHandler) prints almost all
event types, and I don't believe there's a way to tune it.

We certainly don't want these messages printed to the console unless
we're debugging the debugger, so turn them off by default.

PiperOrigin-RevId: 201211355
  • Loading branch information
brendandouglas authored and Copybara-Service committed Jun 19, 2018
1 parent 9f4d5fe commit b749229
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class SkylarkDebuggerOptions extends OptionsBase {
public boolean debugSkylark;

@Option(
name = "experimental_debug_server_port",
name = "experimental_skylark_debug_server_port",
defaultValue = "7300",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.EXECUTION},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Logger;
import javax.annotation.Nullable;

/**
Expand All @@ -46,6 +47,8 @@ static DebugServerTransport createAndWaitForClient(
clientSocket.getOutputStream());
}

private static final Logger logger = Logger.getLogger(DebugServerTransport.class.getName());

private final EventHandler eventHandler;
private final ServerSocket serverSocket;
private final Socket clientSocket;
Expand Down Expand Up @@ -74,7 +77,7 @@ DebugRequest readClientRequest() {
synchronized (requestStream) {
try {
DebugRequest request = DebugRequest.parseDelimitedFrom(requestStream);
eventHandler.handle(Event.debug("Received debug client request:\n" + request));
logger.fine("Received debug client request:\n" + request);
return request;
} catch (IOException e) {
handleParsingError(e);
Expand All @@ -95,7 +98,7 @@ private void handleParsingError(IOException e) {

/** Posts a debug event. */
void postEvent(DebugEvent event) {
eventHandler.handle(Event.debug("Sending debug event:\n" + event));
logger.fine("Sending debug event:\n" + event);
synchronized (eventStream) {
try {
event.writeDelimitedTo(eventStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.net.ServerSocket;
import java.util.List;
import java.util.function.Function;
import java.util.logging.Logger;
import javax.annotation.Nullable;

/** Manages the network socket and debugging state for threads running Skylark code. */
Expand Down Expand Up @@ -64,6 +65,8 @@ static SkylarkDebugServer createAndWaitForConnection(
return new SkylarkDebugServer(eventHandler, transport);
}

private static final Logger logger = Logger.getLogger(SkylarkDebugServer.class.getName());

private final EventHandler eventHandler;
/** Handles all thread-related state. */
private final ThreadHandler threadHandler;
Expand Down Expand Up @@ -119,7 +122,7 @@ private void listenForClientRequests() {
@Override
public void close() {
try {
eventHandler.handle(Event.debug("Closing debug server"));
logger.fine("Closing debug server");
transport.close();

} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,18 @@
import com.google.devtools.build.lib.skylarkdebugging.SkylarkDebuggingProtos.DebugEvent;
import com.google.devtools.build.lib.skylarkdebugging.SkylarkDebuggingProtos.DebugRequest;
import com.google.devtools.build.lib.skylarkdebugging.SkylarkDebuggingProtos.StartDebuggingRequest;
import com.google.devtools.build.lib.syntax.Environment.FailFastException;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.time.Duration;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -85,24 +82,6 @@ void sendRequest(DebugRequest request) throws IOException {
}
}

@Before
public void setupEventHandler() {
// fail-fast treats 'debug' messages as errors. Replace with something that doesn't
events.setFailFast(false);

EnumSet<EventKind> failOnEvents = EnumSet.copyOf(EventKind.ERRORS_AND_WARNINGS);
failOnEvents.remove(EventKind.DEBUG);

events
.reporter()
.addHandler(
event -> {
if (failOnEvents.contains(event.getKind())) {
throw new FailFastException(event.toString());
}
});
}

@Test
public void testConnectAndReceiveRequest() throws Exception {
ServerSocket serverSocket = new ServerSocket(0, 1, InetAddress.getByName(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import com.google.devtools.build.lib.syntax.BuildFileAST;
import com.google.devtools.build.lib.syntax.DebugServerUtils;
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.Environment.FailFastException;
import com.google.devtools.build.lib.syntax.Mutability;
import com.google.devtools.build.lib.syntax.ParserInputSource;
import com.google.devtools.build.lib.syntax.SkylarkList;
Expand All @@ -52,7 +51,6 @@
import java.net.InetAddress;
import java.net.ServerSocket;
import java.time.Duration;
import java.util.EnumSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -89,24 +87,6 @@ public void setUpServerAndClient() throws Exception {
DebugServerUtils.initializeDebugServer(server);
}

@Before
public void setupEventHandler() {
// fail-fast treats 'debug' messages as errors. Replace with something that doesn't
events.setFailFast(false);

EnumSet<EventKind> failOnEvents = EnumSet.copyOf(EventKind.ERRORS_AND_WARNINGS);
failOnEvents.remove(EventKind.DEBUG);

events
.reporter()
.addHandler(
event -> {
if (failOnEvents.contains(event.getKind())) {
throw new FailFastException(event.toString());
}
});
}

@After
public void shutDown() throws Exception {
if (client != null) {
Expand Down

0 comments on commit b749229

Please sign in to comment.