<commit_before>/***************************************************************
 *
 * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
 * University of Wisconsin-Madison, WI.
 * 
 * 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.
 *
 ***************************************************************/

#include "condor_common.h"
#include "condor_debug.h"
#include "read_user_log.h"
#include "write_user_log.h"
#include <time.h>
#include "MyString.h"
#include "condor_config.h"
#include "stat_wrapper.h"
#include "user_log_header.h"

//
// UserLogHeader (base class) methods
//

// Simple constructor for the user log header
UserLogHeader::UserLogHeader( void )
{
	m_sequence = 0;
	m_ctime = 0;
	m_size = 0;
	m_num_events = 0;
	m_file_offset = 0;
	m_event_offset = 0;
	m_valid = false;
}

// Copy constructor for the user log header
UserLogHeader::UserLogHeader( const UserLogHeader &other )
{
	setId(          other.getId() );
	setSequence(    other.getSequence() );
	setCtime(       other.getCtime() );
	setSize(        other.getSize() );
	setNumEvents(   other.getNumEvents() );
	setFileOffset(  other.getFileOffset() );
	setEventOffset( other.getEventOffset() );

	m_valid = other.IsValid( );
}

// Extract info from an event
int
UserLogHeader::ExtractEvent( const ULogEvent *event )
{
	// Not a generic event -- ignore it
	if ( ULOG_GENERIC != event->eventNumber ) {
		return ULOG_NO_EVENT;
	}

	const GenericEvent	*generic = dynamic_cast <const GenericEvent*>( event );
	if ( ! generic ) {
		dprintf( D_ALWAYS, "Can't pointer cast generic event!\n" );
		return ULOG_UNK_ERROR;
	} else {
		char		 id[256];
		int			 ctime;

		::dprintf( D_FULLDEBUG,
				   "UserLogHeader::ExtractEvent(): parsing header '%s'\n",
				   generic->info );
		int n = sscanf( generic->info,
						"Global JobLog: "
						"ctime=%d "
						"id=%255s "
						"sequence=%d "
						"size="FILESIZE_T_FORMAT" "
						"events=%"PRId64" "
						"offset="FILESIZE_T_FORMAT" "
						"event_off=%"PRId64" ",
						&ctime,
						id,
						&m_sequence,
						&m_size,
						&m_num_events,
						&m_file_offset,
						&m_event_offset );
		if ( n >= 3 ) {
			m_ctime = ctime;
			m_valid = true;
			::dprintf( D_FULLDEBUG,
					   "UserLogHeader::ExtractEvent(): parsed OK\n" );
			return ULOG_OK;
		}
		::dprintf( D_FULLDEBUG,
				   "UserLogHeader::ExtractEvent(): can't parse '%s': %d\n",
				   generic->info, n );
		return ULOG_NO_EVENT;
	}
}

// dprintf() metchod
void
UserLogHeader::dprintf( int level, const char *label ) const
{
	if ( NULL == label ) {
		label = "";
	}
	if ( m_valid ) {
		::dprintf( level,
				   "%s header:"
				   " id=%s"
				   " seq=%d"
				   " ctime=%lu"
				   " size="FILESIZE_T_FORMAT
				   " num=%"PRIi64
				   " file_offset="FILESIZE_T_FORMAT
				   " event_offset=%" PRIi64
				   "\n",
				   label,
				   m_id.GetCStr(),
				   m_sequence,
				   (unsigned long) m_ctime,<commit_msg>Should finally fix the eventlog rotation on solaris: forgot that MyString.GetCStr() can return a NULL.  Duh!<commit_after>/***************************************************************
 *
 * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
 * University of Wisconsin-Madison, WI.
 * 
 * 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.
 *
 ***************************************************************/

#include "condor_common.h"
#include "condor_debug.h"
#include "read_user_log.h"
#include "write_user_log.h"
#include <time.h>
#include "MyString.h"
#include "condor_config.h"
#include "stat_wrapper.h"
#include "user_log_header.h"

//
// UserLogHeader (base class) methods
//

// Simple constructor for the user log header
UserLogHeader::UserLogHeader( void )
{
	m_sequence = 0;
	m_ctime = 0;
	m_size = 0;
	m_num_events = 0;
	m_file_offset = 0;
	m_event_offset = 0;
	m_valid = false;
}

// Copy constructor for the user log header
UserLogHeader::UserLogHeader( const UserLogHeader &other )
{
	setId(          other.getId() );
	setSequence(    other.getSequence() );
	setCtime(       other.getCtime() );
	setSize(        other.getSize() );
	setNumEvents(   other.getNumEvents() );
	setFileOffset(  other.getFileOffset() );
	setEventOffset( other.getEventOffset() );

	m_valid = other.IsValid( );
}

// Extract info from an event
int
UserLogHeader::ExtractEvent( const ULogEvent *event )
{
	// Not a generic event -- ignore it
	if ( ULOG_GENERIC != event->eventNumber ) {
		return ULOG_NO_EVENT;
	}

	const GenericEvent	*generic = dynamic_cast <const GenericEvent*>( event );
	if ( ! generic ) {
		dprintf( D_ALWAYS, "Can't pointer cast generic event!\n" );
		return ULOG_UNK_ERROR;
	} else {
		char		 id[256];
		int			 ctime;

		::dprintf( D_FULLDEBUG,
				   "UserLogHeader::ExtractEvent(): parsing header '%s'\n",
				   generic->info );
		int n = sscanf( generic->info,
						"Global JobLog: "
						"ctime=%d "
						"id=%255s "
						"sequence=%d "
						"size="FILESIZE_T_FORMAT" "
						"events=%"PRId64" "
						"offset="FILESIZE_T_FORMAT" "
						"event_off=%"PRId64" ",
						&ctime,
						id,
						&m_sequence,
						&m_size,
						&m_num_events,
						&m_file_offset,
						&m_event_offset );
		if ( n >= 3 ) {
			m_ctime = ctime;
			m_id = id;
			m_valid = true;
			::dprintf( D_FULLDEBUG,
					   "UserLogHeader::ExtractEvent(): parsed OK\n" );
			return ULOG_OK;
		}
		::dprintf( D_FULLDEBUG,
				   "UserLogHeader::ExtractEvent(): can't parse '%s': %d\n",
				   generic->info, n );
		return ULOG_NO_EVENT;
	}
}

// dprintf() method
void
UserLogHeader::dprintf( int level, const char *label ) const
{
	if ( NULL == label ) {
		label = "";
	}
	if ( m_valid ) {
		const char *id = m_id.GetCStr();
		if ( NULL == id ) {
			id = "";
		}
		::dprintf( level,
				   "%s header:"
				   " id=%s"
				   " seq=%d"
				   " ctime=%lu"
				   " size="FILESIZE_T_FORMAT
				   " num=%"PRIi64
				   " file_offset="FILESIZE_T_FORMAT
				   " event_offset=%" PRIi64
				   "\n",
				   label,
				   id,
				   m_sequence,
				   (unsigned long) m_ctime,
{'fraction_non_alphanumeric': 0.160268303125446, 'fraction_numerical': 0.009419152276295133, 'mean_word_length': 3.216606498194946, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3733928', 'n_tokens_mistral': 2745, 'n_tokens_neox': 2338, 'n_words': 612}