diff options
author | aybuke <aybuke.147@gmail.com> | 2016-01-19 17:28:30 +0200 |
---|---|---|
committer | jan iversen <jani@documentfoundation.org> | 2016-01-27 15:58:28 +0000 |
commit | 3563d8dde1068094a7b79aad4aa864301583006d (patch) | |
tree | 4d6ac56e7ef4f8ed2b659ac01e045315de65d56d | |
parent | ff37ea6f96ead38e49ebe4c8356515e4061810c8 (diff) |
tdf#95505 Dump usage stats to text file in user profile.
Change-Id: I12c44db6f03c789682688d39aafb650d074c63f5
Reviewed-on: https://gerrit.libreoffice.org/21609
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: jan iversen <jani@documentfoundation.org>
-rw-r--r-- | sfx2/source/control/unoctitm.cxx | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index 6e63bc7c7bbd..78bd16085d8c 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -68,6 +68,7 @@ #include <osl/file.hxx> #include <rtl/ustring.hxx> #include <unotools/pathoptions.hxx> +#include <osl/time.h> #include <iostream> #include <map> @@ -77,8 +78,6 @@ #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <comphelper/lok.hxx> -#define USAGE "file:///~/.config/libreofficedev/4/user/usage.txt" - using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::util; @@ -645,28 +644,38 @@ void UsageInfo::save() if (!mbIsCollecting) return; - const OUString path(USAGE); + OUString path(SvtPathOptions().GetConfigPath()); + path += "usage/"; + osl::Directory::createPath(path); + + //get system time information. + TimeValue systemTime; + TimeValue localTime; + oslDateTime localDateTime; + osl_getSystemTime( &systemTime ); + osl_getLocalTimeFromSystemTime( &systemTime, &localTime ); + osl_getDateTimeFromTimeValue( &localTime, &localDateTime ); + + sal_Char time[1024]; + sprintf(time,"%4i-%02i-%02iT%02i_%02i_%02i", localDateTime.Year, localDateTime.Month, localDateTime.Day, localDateTime.Hours, localDateTime.Minutes, localDateTime.Seconds); + + //filename type: usage-YYYY-MM-DDTHH_MM_SS.csv + OUString filename = "usage-" + OUString::createFromAscii(time) + ".csv"; + path += filename; + osl::File file(path); if( file.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create) == osl::File::E_None ) { - OString aUsageInfoMsg = "Usage information:\n"; + OString aUsageInfoMsg = "Document Type,Command,Count"; for (UsageMap::const_iterator it = maUsage.begin(); it != maUsage.end(); ++it) aUsageInfoMsg += "\n" + it->first.toUtf8() + ";" + OString::number(it->second); - aUsageInfoMsg += "\nUsage information end\n"; sal_uInt64 written = 0; file.write(aUsageInfoMsg.pData->buffer, aUsageInfoMsg.getLength(), written); file.close(); } - - else{ - std::cerr << "Usage information:" << std::endl; - for (UsageMap::const_iterator it = maUsage.begin(); it != maUsage.end(); ++it) - std::cerr << it->first << ';' << it->second << std::endl; - std::cerr << "Usage information end" << std::endl; - } } class theUsageInfo : public rtl::Static<UsageInfo, theUsageInfo> {}; |