-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tobias Hafner
committed
Apr 8, 2024
1 parent
3918305
commit 8292e5b
Showing
6 changed files
with
236 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
plugins/proto-interface/src/main/java/org/polypheny/db/protointerface/MonitoringPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright 2019-2024 The Polypheny Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.polypheny.db.protointerface; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Map.Entry; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import lombok.Setter; | ||
import org.polypheny.db.information.InformationGroup; | ||
import org.polypheny.db.information.InformationManager; | ||
import org.polypheny.db.information.InformationPage; | ||
import org.polypheny.db.information.InformationTable; | ||
import org.polypheny.db.protointerface.statements.StatementManager; | ||
|
||
public class MonitoringPage { | ||
|
||
@Setter | ||
private ClientManager clientManager; | ||
|
||
private Set<StatementManager> statementManagers; | ||
private final InformationPage informationPage; | ||
private final InformationGroup interfaceGroup; | ||
private final InformationTable statementsTable; | ||
private final InformationTable connectionsTable; | ||
|
||
private final InformationGroup connectionsGroup; | ||
private final InformationTable connectionListTable; | ||
|
||
|
||
public MonitoringPage( String uniqueName, String description ) { | ||
statementManagers = new HashSet<>(); | ||
|
||
InformationManager informationManager = InformationManager.getInstance(); | ||
|
||
informationPage = new InformationPage( uniqueName, description ) | ||
.fullWidth() | ||
.setLabel( "Interfaces" ); | ||
interfaceGroup = new InformationGroup( informationPage, "Interface Statistics" ); | ||
|
||
informationManager.addPage( informationPage ); | ||
informationManager.addGroup( interfaceGroup ); | ||
|
||
statementsTable = new InformationTable( interfaceGroup, Arrays.asList( "Attribute", "Value" ) ); | ||
statementsTable.setOrder( 1 ); | ||
informationManager.registerInformation( statementsTable ); | ||
|
||
connectionsTable = new InformationTable( interfaceGroup, Arrays.asList( "Attribute", "Value" ) ); | ||
connectionsTable.setOrder( 2 ); | ||
informationManager.registerInformation( connectionsTable ); | ||
|
||
connectionsGroup = new InformationGroup( informationPage, "Connections" ); | ||
informationManager.addGroup( connectionsGroup ); | ||
connectionListTable = new InformationTable( connectionsGroup, | ||
Arrays.asList( "UUID", "TX", "Auto Commit", "Default Namespace" ) ); | ||
connectionListTable.setOrder( 3 ); | ||
informationManager.registerInformation( connectionListTable ); | ||
|
||
informationPage.setRefreshFunction( this::update ); | ||
} | ||
|
||
|
||
public void update() { | ||
connectionsTable.reset(); | ||
connectionsTable.addRow( "Open Connections", clientManager.getClientCount() ); | ||
|
||
statementsTable.reset(); | ||
AtomicInteger statementCount = new AtomicInteger(); | ||
statementManagers.forEach(m -> statementCount.addAndGet( m.openStatementCount() ) ); | ||
statementsTable.addRow( "Open Statements", statementCount.get() ); | ||
|
||
connectionListTable.reset(); | ||
clientManager.getClients().forEach( this::addClientEntry ); | ||
} | ||
|
||
|
||
private void addClientEntry( Entry<String, PIClient> clientEntry ) { | ||
String uuid = clientEntry.getKey(); | ||
PIClient client = clientEntry.getValue(); | ||
String txId = "-"; | ||
if ( !client.hasNoTransaction() ) { | ||
txId = String.valueOf( client.getCurrentOrCreateNewTransaction().getId() ); | ||
} | ||
connectionListTable.addRow( | ||
uuid, | ||
txId, | ||
client.isAutoCommit(), | ||
client.getNamespace() | ||
); | ||
} | ||
|
||
|
||
public void addStatementManager( StatementManager statementManager ) { | ||
statementManagers.add( statementManager ); | ||
} | ||
|
||
|
||
public void removeStatementManager( StatementManager statementManager ) { | ||
statementManagers.remove( statementManager ); | ||
} | ||
|
||
|
||
public void remove() { | ||
InformationManager im = InformationManager.getInstance(); | ||
im.removeInformation( connectionsTable ); | ||
im.removeInformation( statementsTable ); | ||
im.removeInformation( connectionListTable ); | ||
im.removeGroup( interfaceGroup ); | ||
im.removePage( informationPage ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ns/proto-interface/src/main/java/org/polypheny/db/protointerface/PIPerformanceLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2019-2024 The Polypheny Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.polypheny.db.protointerface; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
|
||
public class PIPerformanceLogger { | ||
private BufferedWriter writer; | ||
private static final String PATH = System.getProperty( "user.home" ) + "/uni_basel/master_project/benchmarking/"; | ||
|
||
// Method to open a file. If the file exists, it will be overwritten. | ||
public void openFile(String fileName) { | ||
try { | ||
// FileWriter is set to false to overwrite the file if it exists | ||
writer = new BufferedWriter(new FileWriter(PATH + fileName, true)); | ||
} catch ( IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
// Method to write a line to the file | ||
public void write(String line) { | ||
try { | ||
if (writer != null) { | ||
writer.write(line + ","); | ||
} else { | ||
System.out.println("Error: File is not opened yet."); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void writeNewLine() { | ||
try { | ||
if (writer != null) { | ||
writer.newLine(); | ||
} else { | ||
System.out.println("Error: File is not opened yet."); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
// Method to close the file | ||
public void closeFile() { | ||
try { | ||
if (writer != null) { | ||
writer.close(); | ||
} else { | ||
System.out.println("Error: File is not opened or already closed."); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters